mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
Fixes #35
This commit is contained in:
parent
fba5de7344
commit
4536e57938
2 changed files with 32 additions and 0 deletions
|
|
@ -32,3 +32,28 @@ func TestEndsWithNonSpaceCharacters(t *testing.T) {
|
||||||
t.Errorf("%s \n---------\n %s", source, b.String())
|
t.Errorf("%s \n---------\n %s", source, b.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWindowsNewLine(t *testing.T) {
|
||||||
|
markdown := New(WithRendererOptions(
|
||||||
|
html.WithXHTML(),
|
||||||
|
))
|
||||||
|
source := []byte("a \r\nb\n")
|
||||||
|
var b bytes.Buffer
|
||||||
|
err := markdown.Convert(source, &b)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err.Error())
|
||||||
|
}
|
||||||
|
if b.String() != "<p>a<br />\nb</p>\n" {
|
||||||
|
t.Errorf("%s\n---------\n%s", source, b.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
source = []byte("a\\\r\nb\r\n")
|
||||||
|
var b2 bytes.Buffer
|
||||||
|
err = markdown.Convert(source, &b2)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err.Error())
|
||||||
|
}
|
||||||
|
if b2.String() != "<p>a<br />\nb</p>\n" {
|
||||||
|
t.Errorf("\n%s\n---------\n%s", source, b2.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1154,7 +1154,14 @@ func (p *parser) parseBlock(block text.BlockReader, parent ast.Node, pc Context)
|
||||||
if lineLength > 2 && line[lineLength-2] == '\\' && softLinebreak { // ends with \\n
|
if lineLength > 2 && line[lineLength-2] == '\\' && softLinebreak { // ends with \\n
|
||||||
stop--
|
stop--
|
||||||
hardlineBreak = true
|
hardlineBreak = true
|
||||||
|
|
||||||
|
} else if lineLength > 3 && line[lineLength-3] == '\\' && line[lineLength-2] == '\r' && softLinebreak { // ends with \\r\n
|
||||||
|
stop -= 2
|
||||||
|
hardlineBreak = true
|
||||||
} else if lineLength > 3 && line[lineLength-3] == ' ' && line[lineLength-2] == ' ' && softLinebreak { // ends with [space][space]\n
|
} else if lineLength > 3 && line[lineLength-3] == ' ' && line[lineLength-2] == ' ' && softLinebreak { // ends with [space][space]\n
|
||||||
|
stop--
|
||||||
|
hardlineBreak = true
|
||||||
|
} else if lineLength > 4 && line[lineLength-4] == ' ' && line[lineLength-3] == ' ' && line[lineLength-2] == '\r' && softLinebreak { // ends with [space][space]\r\n
|
||||||
hardlineBreak = true
|
hardlineBreak = true
|
||||||
}
|
}
|
||||||
rest := diff.WithStop(stop)
|
rest := diff.WithStop(stop)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue