Skip to content

Commit

Permalink
Fixes #35
Browse files Browse the repository at this point in the history
  • Loading branch information
yuin committed Nov 25, 2019
1 parent fba5de7 commit 4536e57
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
25 changes: 25 additions & 0 deletions extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,28 @@ func TestEndsWithNonSpaceCharacters(t *testing.T) {
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())
}
}
7 changes: 7 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
stop--
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
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
}
rest := diff.WithStop(stop)
Expand Down

0 comments on commit 4536e57

Please sign in to comment.