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...)
|
||||
|
|
18
org/testdata/example.html
vendored
18
org/testdata/example.html
vendored
|
@ -63,9 +63,7 @@ and some lines of text
|
|||
<p>
|
||||
and another subitem
|
||||
</p>
|
||||
<code class="src src-sh">
|
||||
<pre>echo with a block</pre>
|
||||
</code>
|
||||
<div class="highlight"><pre>echo with a block</pre></div>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
|
@ -166,14 +164,10 @@ auto link, i.e. not inside <code class="verbatim">\[[square brackets]\]</code> <
|
|||
</li>
|
||||
</ul>
|
||||
<h2>blocks</h2>
|
||||
<code class="src src-bash">
|
||||
<pre>echo a bash source block</pre>
|
||||
</code>
|
||||
<code class="src src-text">
|
||||
<pre>a source block without a language
|
||||
<div class="highlight"><pre>echo a bash source block</pre></div>
|
||||
<div class="highlight"><pre>a source block without a language
|
||||
and a second line
|
||||
and a third one</pre>
|
||||
</code>
|
||||
and a third one</pre></div>
|
||||
<pre class="example">\nan example block
|
||||
with multiple lines
|
||||
</pre>
|
||||
|
@ -280,9 +274,7 @@ and other elements
|
|||
<p>
|
||||
like blocks
|
||||
</p>
|
||||
<code class="src src-text">
|
||||
<pre>other non-plain</pre>
|
||||
</code>
|
||||
<div class="highlight"><pre>other non-plain</pre></div>
|
||||
</li>
|
||||
<li>
|
||||
<p>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue