Merge pull request #102 from FikriRNurhidayat/master

trim leading newline char on blocks for html
This commit is contained in:
Niklas Fasching 2023-06-16 20:07:53 +02:00 committed by GitHub
commit 6eb20dbda9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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...) WriteNodes(w, children...)
out := w.String() out := w.String()
w.Builder, w.htmlEscape = builder, htmlEscape w.Builder, w.htmlEscape = builder, htmlEscape
return strings.TrimRightFunc(out, unicode.IsSpace)
return strings.TrimRightFunc(strings.TrimLeftFunc(out, IsNewLineChar), unicode.IsSpace)
} else { } else {
return w.WriteNodesAsString(children...) return w.WriteNodesAsString(children...)
} }

View file

@ -22,6 +22,16 @@ block caption
<div class="src src-text"> <div class="src src-text">
<div class="highlight"> <div class="highlight">
<pre> <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 a source block without a language
</pre> </pre>
</div> </div>

View file

@ -12,6 +12,15 @@ function hello {
hello hello
#+END_SRC #+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 #+BEGIN_SRC
a source block without a language a source block without a language
#+END_SRC #+END_SRC

View file

@ -12,6 +12,15 @@ function hello {
hello hello
#+END_SRC #+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 #+BEGIN_SRC
a source block without a language a source block without a language
#+END_SRC #+END_SRC

View file

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