From ba29d94709189b3fc935149dd678481cfc7971f2 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 6 Jan 2022 17:42:05 +0100 Subject: [PATCH] Add syntax highlighting --- html.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/html.go b/html.go index cb4f26e..4e65404 100644 --- a/html.go +++ b/html.go @@ -420,6 +420,9 @@ var ( aTag = []byte("") preTag = []byte("
")
+	preHighlightTag    = []byte(`
`)
+	divHighlightTag    = []byte(`
`) + divCloseTag = []byte("
") preCloseTag = []byte("
") codeTag = []byte("") codeCloseTag = []byte("") @@ -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) }