mirror of
https://github.com/danog/blackfriday.git
synced 2024-11-30 04:29:13 +01:00
Add syntax highlighting
This commit is contained in:
parent
4c9bf95126
commit
ba29d94709
7
html.go
7
html.go
@ -420,6 +420,9 @@ var (
|
|||||||
aTag = []byte("<a")
|
aTag = []byte("<a")
|
||||||
aCloseTag = []byte("</a>")
|
aCloseTag = []byte("</a>")
|
||||||
preTag = []byte("<pre>")
|
preTag = []byte("<pre>")
|
||||||
|
preHighlightTag = []byte(`<pre class="highlight">`)
|
||||||
|
divHighlightTag = []byte(`<div class="highlight">`)
|
||||||
|
divCloseTag = []byte("</div>")
|
||||||
preCloseTag = []byte("</pre>")
|
preCloseTag = []byte("</pre>")
|
||||||
codeTag = []byte("<code>")
|
codeTag = []byte("<code>")
|
||||||
codeCloseTag = []byte("</code>")
|
codeCloseTag = []byte("</code>")
|
||||||
@ -763,11 +766,13 @@ func (r *HTMLRenderer) RenderNode(w io.Writer, node *Node, entering bool) WalkSt
|
|||||||
case CodeBlock:
|
case CodeBlock:
|
||||||
attrs = appendLanguageAttr(attrs, node.Info)
|
attrs = appendLanguageAttr(attrs, node.Info)
|
||||||
r.cr(w)
|
r.cr(w)
|
||||||
r.out(w, preTag)
|
r.out(w, divHighlightTag)
|
||||||
|
r.out(w, preHighlightTag)
|
||||||
r.tag(w, codeTag[:len(codeTag)-1], attrs)
|
r.tag(w, codeTag[:len(codeTag)-1], attrs)
|
||||||
escapeAllHTML(w, node.Literal)
|
escapeAllHTML(w, node.Literal)
|
||||||
r.out(w, codeCloseTag)
|
r.out(w, codeCloseTag)
|
||||||
r.out(w, preCloseTag)
|
r.out(w, preCloseTag)
|
||||||
|
r.out(w, divCloseTag)
|
||||||
if node.Parent.Type != Item {
|
if node.Parent.Type != Item {
|
||||||
r.cr(w)
|
r.cr(w)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user