html: Fix code block export (superfluous newlines)

I didn't consider that all newlines in the pre block will be printed and we
thus shouldn't wrap html that has it's tags on separate lines (i.e. contains
superfluous newlines) - wrapping in a div less accurately represents
org-html-export but it provides the same information and gives us more freedom
in the return value of HighlightCodeBlock as well as allowing us to keep the
html tags on new lines (consistency).
This commit is contained in:
Niklas Fasching 2019-07-28 16:40:09 +02:00
parent 777899c803
commit 97fe8b7850
8 changed files with 31 additions and 30 deletions

View file

@ -59,7 +59,7 @@ func NewHTMLWriter() *HTMLWriter {
log: defaultConfig.Log,
htmlEscape: true,
HighlightCodeBlock: func(source, lang string) string {
return fmt.Sprintf("%s\n<pre>\n%s\n</pre>\n</div>", `<div class="highlight">`, html.EscapeString(source))
return fmt.Sprintf("<div class=\"highlight\">\n<pre>\n%s\n</pre>\n</div>", html.EscapeString(source))
},
footnotes: footnotes{
mapping: map[string]int{},
@ -109,7 +109,7 @@ func (w *HTMLWriter) WriteBlock(b Block) {
lang = strings.ToLower(b.Parameters[0])
}
content = w.HighlightCodeBlock(content, lang)
w.WriteString(fmt.Sprintf("<pre class=\"src src-%s\">\n%s\n</pre>\n", lang, content))
w.WriteString(fmt.Sprintf("<div class=\"src src-%s\">\n%s\n</div>\n", lang, content))
case name == "EXAMPLE":
w.WriteString(`<pre class="example">` + "\n" + content + "\n</pre>\n")
case name == "EXPORT" && len(b.Parameters) >= 1 && strings.ToLower(b.Parameters[0]) == "html":