trim leading newline char on blocks for html
This commit is contained in:
parent
2d45490186
commit
0de50d60af
5 changed files with 34 additions and 1 deletions
|
@ -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...)
|
||||||
}
|
}
|
||||||
|
|
10
org/testdata/blocks.html
vendored
10
org/testdata/blocks.html
vendored
|
@ -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>
|
||||||
|
|
9
org/testdata/blocks.org
vendored
9
org/testdata/blocks.org
vendored
|
@ -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
|
||||||
|
|
9
org/testdata/blocks.pretty_org
vendored
9
org/testdata/blocks.pretty_org
vendored
|
@ -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
|
||||||
|
|
|
@ -68,3 +68,7 @@ func ParseRanges(s string) [][2]int {
|
||||||
}
|
}
|
||||||
return ranges
|
return ranges
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsNewLineChar(r rune) bool {
|
||||||
|
return r == '\n' || r == '\r'
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue