trim leading newline char on blocks for html

This commit is contained in:
Fikri 2023-06-16 23:49:33 +07:00
parent 2d45490186
commit 0de50d60af
5 changed files with 34 additions and 1 deletions

View file

@ -622,7 +622,8 @@ func (w *HTMLWriter) blockContent(name string, children []Node) string {
WriteNodes(w, children...)
out := w.String()
w.Builder, w.htmlEscape = builder, htmlEscape
return strings.TrimRightFunc(out, unicode.IsSpace)
return strings.TrimRightFunc(strings.TrimLeftFunc(out, IsNewLineChar), unicode.IsSpace)
} else {
return w.WriteNodesAsString(children...)
}

View file

@ -22,6 +22,16 @@ block caption
<div class="src src-text">
<div class="highlight">
<pre>
a source block with leading newline, trailing newline characters
and a line started
with leading space
and line leading tab.
</pre>
</div>
</div>
<div class="src src-text">
<div class="highlight">
<pre>
a source block without a language
</pre>
</div>

View file

@ -12,6 +12,15 @@ function hello {
hello
#+END_SRC
#+BEGIN_SRC
a source block with leading newline, trailing newline characters
and a line started
with leading space
and line leading tab.
#+END_SRC
#+BEGIN_SRC
a source block without a language
#+END_SRC

View file

@ -12,6 +12,15 @@ function hello {
hello
#+END_SRC
#+BEGIN_SRC
a source block with leading newline, trailing newline characters
and a line started
with leading space
and line leading tab.
#+END_SRC
#+BEGIN_SRC
a source block without a language
#+END_SRC

View file

@ -68,3 +68,7 @@ func ParseRanges(s string) [][2]int {
}
return ranges
}
func IsNewLineChar(r rune) bool {
return r == '\n' || r == '\r'
}