Skip to content

Commit

Permalink
Fix #274, Fix #275
Browse files Browse the repository at this point in the history
  • Loading branch information
yuin committed Feb 8, 2022
1 parent d44b185 commit f6e93ff
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
19 changes: 19 additions & 0 deletions _test/extra.txt
Original file line number Diff line number Diff line change
Expand Up @@ -684,3 +684,22 @@ This line will be displayed.
<video autoplay muted loop>\r\n<source src=\"https://example.com/example.mp4\" type=\"video/mp4\">\r\nYour browser does not support the video tag.\r\n</video>
//= = = = = = = = = = = = = = = = = = = = = = = =//


53: HTML comment without trailing new lines
OPTIONS: {"trim": true}
//- - - - - - - - -//
<!--
-->
//- - - - - - - - -//
<!--
-->
//= = = = = = = = = = = = = = = = = = = = = = = =//


54: Escaped characters followed by a null character
OPTIONS: {"enableEscape": true}
//- - - - - - - - -//
\\\x00\"
//- - - - - - - - -//
<p>\\\ufffd&quot;</p>
//= = = = = = = = = = = = = = = = = = = = = = = =//
2 changes: 1 addition & 1 deletion parser/html_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (b *htmlBlockParser) Continue(node ast.Node, reader text.Reader, pc Context
}
if bytes.Contains(line, closurePattern) {
htmlBlock.ClosureLine = segment
reader.Advance(segment.Len() - 1)
reader.Advance(segment.Len())
return Close
}

Expand Down
1 change: 1 addition & 0 deletions renderer/html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ func (d *defaultWriter) Write(writer util.BufWriter, source []byte) {
d.RawWrite(writer, source[n:i])
d.RawWrite(writer, replacementCharacter)
n = i + 1
escaped = false
continue
}
if c == '&' {
Expand Down
17 changes: 13 additions & 4 deletions testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,31 @@ type MarkdownTestCase struct {
}

func source(t *MarkdownTestCase) string {
ret := t.Markdown
if t.Options.Trim {
ret = strings.TrimSpace(ret)
}
if t.Options.EnableEscape {
return string(applyEscapeSequence([]byte(t.Markdown)))
return string(applyEscapeSequence([]byte(ret)))
}
return t.Markdown
return ret
}

func expected(t *MarkdownTestCase) string {
ret := t.Expected
if t.Options.Trim {
ret = strings.TrimSpace(ret)
}
if t.Options.EnableEscape {
return string(applyEscapeSequence([]byte(t.Expected)))
return string(applyEscapeSequence([]byte(ret)))
}
return t.Expected
return ret
}

// MarkdownTestCaseOptions represents options for each test case.
type MarkdownTestCaseOptions struct {
EnableEscape bool
Trim bool
}

const attributeSeparator = "//- - - - - - - - -//"
Expand Down

0 comments on commit f6e93ff

Please sign in to comment.