mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
Fix #245 - 5
This commit is contained in:
parent
351308fb72
commit
7efc483c26
3 changed files with 22 additions and 9 deletions
|
|
@ -395,3 +395,17 @@ hello\x00world
|
||||||
//- - - - - - - - -//
|
//- - - - - - - - -//
|
||||||
<p>hello\ufffdworld</p>
|
<p>hello\ufffdworld</p>
|
||||||
//= = = = = = = = = = = = = = = = = = = = = = = =//
|
//= = = = = = = = = = = = = = = = = = = = = = = =//
|
||||||
|
|
||||||
|
27: Newlines in code spans must be preserved as a space
|
||||||
|
OPTIONS: {"enableEscape": true}
|
||||||
|
//- - - - - - - - -//
|
||||||
|
`\n`
|
||||||
|
|
||||||
|
`x\n`
|
||||||
|
|
||||||
|
`\nx`
|
||||||
|
//- - - - - - - - -//
|
||||||
|
<p><code> </code></p>
|
||||||
|
<p><code>x </code></p>
|
||||||
|
<p><code> x</code></p>
|
||||||
|
//= = = = = = = = = = = = = = = = = = = = = = = =//
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package parser
|
||||||
import (
|
import (
|
||||||
"github.com/yuin/goldmark/ast"
|
"github.com/yuin/goldmark/ast"
|
||||||
"github.com/yuin/goldmark/text"
|
"github.com/yuin/goldmark/text"
|
||||||
"github.com/yuin/goldmark/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type codeSpanParser struct {
|
type codeSpanParser struct {
|
||||||
|
|
@ -52,9 +51,7 @@ func (s *codeSpanParser) Parse(parent ast.Node, block text.Reader, pc Context) a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !util.IsBlank(line) {
|
node.AppendChild(node, ast.NewRawTextSegment(segment))
|
||||||
node.AppendChild(node, ast.NewRawTextSegment(segment))
|
|
||||||
}
|
|
||||||
block.AdvanceLine()
|
block.AdvanceLine()
|
||||||
}
|
}
|
||||||
end:
|
end:
|
||||||
|
|
@ -62,11 +59,11 @@ end:
|
||||||
// trim first halfspace and last halfspace
|
// trim first halfspace and last halfspace
|
||||||
segment := node.FirstChild().(*ast.Text).Segment
|
segment := node.FirstChild().(*ast.Text).Segment
|
||||||
shouldTrimmed := true
|
shouldTrimmed := true
|
||||||
if !(!segment.IsEmpty() && block.Source()[segment.Start] == ' ') {
|
if !(!segment.IsEmpty() && isSpaceOrNewline(block.Source()[segment.Start])) {
|
||||||
shouldTrimmed = false
|
shouldTrimmed = false
|
||||||
}
|
}
|
||||||
segment = node.LastChild().(*ast.Text).Segment
|
segment = node.LastChild().(*ast.Text).Segment
|
||||||
if !(!segment.IsEmpty() && block.Source()[segment.Stop-1] == ' ') {
|
if !(!segment.IsEmpty() && isSpaceOrNewline(block.Source()[segment.Stop-1])) {
|
||||||
shouldTrimmed = false
|
shouldTrimmed = false
|
||||||
}
|
}
|
||||||
if shouldTrimmed {
|
if shouldTrimmed {
|
||||||
|
|
@ -81,3 +78,7 @@ end:
|
||||||
}
|
}
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isSpaceOrNewline(c byte) bool {
|
||||||
|
return c == ' ' || c == '\n'
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -477,9 +477,7 @@ func (r *Renderer) renderCodeSpan(w util.BufWriter, source []byte, n ast.Node, e
|
||||||
value := segment.Value(source)
|
value := segment.Value(source)
|
||||||
if bytes.HasSuffix(value, []byte("\n")) {
|
if bytes.HasSuffix(value, []byte("\n")) {
|
||||||
r.Writer.RawWrite(w, value[:len(value)-1])
|
r.Writer.RawWrite(w, value[:len(value)-1])
|
||||||
if c != n.LastChild() {
|
r.Writer.RawWrite(w, []byte(" "))
|
||||||
r.Writer.RawWrite(w, []byte(" "))
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
r.Writer.RawWrite(w, value)
|
r.Writer.RawWrite(w, value)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue