From 7a9993e05455c97f33c461eae852389dde688314 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 6 Jan 2022 18:21:16 +0100 Subject: [PATCH] Final fixes --- html.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/html.go b/html.go index 7fc5728..b5ef299 100644 --- a/html.go +++ b/html.go @@ -329,7 +329,7 @@ func appendLanguageAttr(attrs []string, info []byte) ([]string, string) { if endOfLang < 0 { endOfLang = len(info) } - return append(attrs, fmt.Sprintf("class=\"language-%s\"", info[:endOfLang])), string(info[:endOfLang]) + return append(attrs, fmt.Sprintf("class=\"language-%s highlighter-rouge\"", info[:endOfLang])), string(info[:endOfLang]) } func (r *HTMLRenderer) tag(w io.Writer, name []byte, attrs []string) { @@ -422,8 +422,7 @@ var ( aTag = []byte("") preTag = []byte("
")
-	preHighlightTag    = []byte(`
`)
-	divHighlightTag    = []byte(`
`) + divTag = []byte(`
`) divCloseTag = []byte("
") preCloseTag = []byte("
") codeTag = []byte("") @@ -768,16 +767,17 @@ func (r *HTMLRenderer) RenderNode(w io.Writer, node *Node, entering bool) WalkSt case CodeBlock: attrs, lang := appendLanguageAttr(attrs, node.Info) r.cr(w) - r.out(w, divHighlightTag) - r.out(w, preHighlightTag) - r.tag(w, codeTag[:len(codeTag)-1], attrs) + r.tag(w, divTag[:len(divTag)-1], attrs) + r.tag(w, divTag[:len(divTag)-1], []string{`class="highlight"`}) + r.tag(w, preTag[:len(preTag)-1], []string{`class="highlight"`}) + r.out(w, codeTag) buf := new(bytes.Buffer) - args := []string{"-f", "html"} + args := []string{"highlight", "-f", "html"} if lang != "" { args = append(args, "-l", lang) } - cmd := exec.Command("pygmentize", args...) // nolint: gas + cmd := exec.Command("rougify", args...) // nolint: gas cmd.Stdin = strings.NewReader(string(node.Literal)) cmd.Stdout = buf cmd.Stderr = os.Stderr @@ -785,9 +785,12 @@ func (r *HTMLRenderer) RenderNode(w io.Writer, node *Node, entering bool) WalkSt panic(e) } r.out(w, buf.Bytes()) + r.out(w, codeCloseTag) r.out(w, preCloseTag) r.out(w, divCloseTag) + r.out(w, divCloseTag) + if node.Parent.Type != Item { r.cr(w) }