HTMLWriter: Change code block markup to resemble hugo chroma output
The highlight function from hugo already wraps the highlighted source code in div > pre > code e.g. <div class="highlight"> <pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"> <code class="language-sh" data-lang="sh">echo hello world</code> </pre> </div> So now we always delegate all that to the highlight function
This commit is contained in:
parent
d5665fb21c
commit
09a8437b59
2 changed files with 7 additions and 17 deletions
|
@ -34,7 +34,7 @@ var listTags = map[string][]string{
|
|||
func NewHTMLWriter() *HTMLWriter {
|
||||
return &HTMLWriter{
|
||||
HighlightCodeBlock: func(source, lang string) string {
|
||||
return fmt.Sprintf("<pre>%s</pre>", html.EscapeString(source))
|
||||
return fmt.Sprintf(`<div class="highlight"><pre>%s</pre></div>`, html.EscapeString(source))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -112,9 +112,7 @@ func (w *HTMLWriter) writeBlock(b Block) {
|
|||
for _, n := range b.Children {
|
||||
lines = append(lines, n.(Line).Children[0].(Text).Content)
|
||||
}
|
||||
w.WriteString(fmt.Sprintf(`<code class="src src-%s">`, lang) + "\n")
|
||||
w.WriteString(w.HighlightCodeBlock(strings.Join(lines, "\n"), lang))
|
||||
w.WriteString("\n</code>\n")
|
||||
w.WriteString(w.HighlightCodeBlock(strings.Join(lines, "\n"), lang) + "\n")
|
||||
case "EXAMPLE":
|
||||
w.WriteString(`<pre class="example">\n`)
|
||||
w.writeNodes(b.Children...)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue