1
0
mirror of https://github.com/danog/blackfriday.git synced 2024-11-26 20:14:43 +01:00

Add syntax highlighting

This commit is contained in:
Daniil Gentili 2022-01-06 17:42:05 +01:00
parent 4c9bf95126
commit ba29d94709
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7

View File

@ -420,6 +420,9 @@ var (
aTag = []byte("<a")
aCloseTag = []byte("</a>")
preTag = []byte("<pre>")
preHighlightTag = []byte(`<pre class="highlight">`)
divHighlightTag = []byte(`<div class="highlight">`)
divCloseTag = []byte("</div>")
preCloseTag = []byte("</pre>")
codeTag = []byte("<code>")
codeCloseTag = []byte("</code>")
@ -763,11 +766,13 @@ func (r *HTMLRenderer) RenderNode(w io.Writer, node *Node, entering bool) WalkSt
case CodeBlock:
attrs = appendLanguageAttr(attrs, node.Info)
r.cr(w)
r.out(w, preTag)
r.out(w, divHighlightTag)
r.out(w, preHighlightTag)
r.tag(w, codeTag[:len(codeTag)-1], attrs)
escapeAllHTML(w, node.Literal)
r.out(w, codeCloseTag)
r.out(w, preCloseTag)
r.out(w, divCloseTag)
if node.Parent.Type != Item {
r.cr(w)
}