mirror of
https://github.com/danog/blackfriday.git
synced 2024-11-30 04:29:13 +01:00
Final fixes
This commit is contained in:
parent
e99e04f09b
commit
7a9993e054
19
html.go
19
html.go
@ -329,7 +329,7 @@ func appendLanguageAttr(attrs []string, info []byte) ([]string, string) {
|
|||||||
if endOfLang < 0 {
|
if endOfLang < 0 {
|
||||||
endOfLang = len(info)
|
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) {
|
func (r *HTMLRenderer) tag(w io.Writer, name []byte, attrs []string) {
|
||||||
@ -422,8 +422,7 @@ var (
|
|||||||
aTag = []byte("<a")
|
aTag = []byte("<a")
|
||||||
aCloseTag = []byte("</a>")
|
aCloseTag = []byte("</a>")
|
||||||
preTag = []byte("<pre>")
|
preTag = []byte("<pre>")
|
||||||
preHighlightTag = []byte(`<pre class="highlight">`)
|
divTag = []byte(`<div>`)
|
||||||
divHighlightTag = []byte(`<div class="highlight">`)
|
|
||||||
divCloseTag = []byte("</div>")
|
divCloseTag = []byte("</div>")
|
||||||
preCloseTag = []byte("</pre>")
|
preCloseTag = []byte("</pre>")
|
||||||
codeTag = []byte("<code>")
|
codeTag = []byte("<code>")
|
||||||
@ -768,16 +767,17 @@ func (r *HTMLRenderer) RenderNode(w io.Writer, node *Node, entering bool) WalkSt
|
|||||||
case CodeBlock:
|
case CodeBlock:
|
||||||
attrs, lang := appendLanguageAttr(attrs, node.Info)
|
attrs, lang := appendLanguageAttr(attrs, node.Info)
|
||||||
r.cr(w)
|
r.cr(w)
|
||||||
r.out(w, divHighlightTag)
|
r.tag(w, divTag[:len(divTag)-1], attrs)
|
||||||
r.out(w, preHighlightTag)
|
r.tag(w, divTag[:len(divTag)-1], []string{`class="highlight"`})
|
||||||
r.tag(w, codeTag[:len(codeTag)-1], attrs)
|
r.tag(w, preTag[:len(preTag)-1], []string{`class="highlight"`})
|
||||||
|
r.out(w, codeTag)
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
args := []string{"-f", "html"}
|
args := []string{"highlight", "-f", "html"}
|
||||||
if lang != "" {
|
if lang != "" {
|
||||||
args = append(args, "-l", 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.Stdin = strings.NewReader(string(node.Literal))
|
||||||
cmd.Stdout = buf
|
cmd.Stdout = buf
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
@ -785,9 +785,12 @@ func (r *HTMLRenderer) RenderNode(w io.Writer, node *Node, entering bool) WalkSt
|
|||||||
panic(e)
|
panic(e)
|
||||||
}
|
}
|
||||||
r.out(w, buf.Bytes())
|
r.out(w, buf.Bytes())
|
||||||
|
|
||||||
r.out(w, codeCloseTag)
|
r.out(w, codeCloseTag)
|
||||||
r.out(w, preCloseTag)
|
r.out(w, preCloseTag)
|
||||||
r.out(w, divCloseTag)
|
r.out(w, divCloseTag)
|
||||||
|
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