Skip to content

Commit

Permalink
Fixed bug related newline code
Browse files Browse the repository at this point in the history
  • Loading branch information
yuin committed Sep 25, 2022
1 parent ae42b91 commit c71a97b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
21 changes: 21 additions & 0 deletions extension/cjk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,25 @@ func TestEastAsianLineBreaks(t *testing.T) {
},
t,
)

markdown = goldmark.New(goldmark.WithRendererOptions(
html.WithXHTML(),
html.WithUnsafe(),
),
goldmark.WithExtensions(
NewCJK(WithEastAsianLineBreaks()),
Linkify,
),
)
no = 7
testutil.DoTestCase(
markdown,
testutil.MarkdownTestCase{
No: no,
Description: "WithEastAsianLineBreaks and linkfy extension",
Markdown: "太郎は\\ **「こんにちわ」**\\ と言った\r\nんです",
Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言ったんです</p>",
},
t,
)
}
34 changes: 17 additions & 17 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,16 +567,16 @@ type ASTTransformer interface {
// DefaultBlockParsers returns a new list of default BlockParsers.
// Priorities of default BlockParsers are:
//
// SetextHeadingParser, 100
// ThematicBreakParser, 200
// ListParser, 300
// ListItemParser, 400
// CodeBlockParser, 500
// ATXHeadingParser, 600
// FencedCodeBlockParser, 700
// BlockquoteParser, 800
// HTMLBlockParser, 900
// ParagraphParser, 1000
// SetextHeadingParser, 100
// ThematicBreakParser, 200
// ListParser, 300
// ListItemParser, 400
// CodeBlockParser, 500
// ATXHeadingParser, 600
// FencedCodeBlockParser, 700
// BlockquoteParser, 800
// HTMLBlockParser, 900
// ParagraphParser, 1000
func DefaultBlockParsers() []util.PrioritizedValue {
return []util.PrioritizedValue{
util.Prioritized(NewSetextHeadingParser(), 100),
Expand All @@ -595,11 +595,11 @@ func DefaultBlockParsers() []util.PrioritizedValue {
// DefaultInlineParsers returns a new list of default InlineParsers.
// Priorities of default InlineParsers are:
//
// CodeSpanParser, 100
// LinkParser, 200
// AutoLinkParser, 300
// RawHTMLParser, 400
// EmphasisParser, 500
// CodeSpanParser, 100
// LinkParser, 200
// AutoLinkParser, 300
// RawHTMLParser, 400
// EmphasisParser, 500
func DefaultInlineParsers() []util.PrioritizedValue {
return []util.PrioritizedValue{
util.Prioritized(NewCodeSpanParser(), 100),
Expand All @@ -613,7 +613,7 @@ func DefaultInlineParsers() []util.PrioritizedValue {
// DefaultParagraphTransformers returns a new list of default ParagraphTransformers.
// Priorities of default ParagraphTransformers are:
//
// LinkReferenceParagraphTransformer, 100
// LinkReferenceParagraphTransformer, 100
func DefaultParagraphTransformers() []util.PrioritizedValue {
return []util.PrioritizedValue{
util.Prioritized(LinkReferenceParagraphTransformer, 100),
Expand Down Expand Up @@ -1178,7 +1178,7 @@ func (p *parser) parseBlock(block text.BlockReader, parent ast.Node, pc Context)
if c == '\n' {
break
}
isSpace := util.IsSpace(c)
isSpace := util.IsSpace(c) && c != '\r' && c != '\n'
isPunct := util.IsPunct(c)
if (isPunct && !escaped) || isSpace && !(escaped && p.escapedSpace) || i == 0 {
parserChar := c
Expand Down

0 comments on commit c71a97b

Please sign in to comment.