Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an extension to handle Chinese (or CJK) newlines. #334

Merged
merged 3 commits into from
Apr 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1713,3 +1713,28 @@ func TestIsFenceLine(t *testing.T) {
}
}
}

func TestJoinLines(t *testing.T) {
input := `# 标题

第一
行文字。

行文字。
`
result := `<h1>标题</h1>

<p>第一行文字。</p>

<p>第二行文字。</p>
`
opt := Options{Extensions: commonExtensions | EXTENSION_JOIN_LINES}
renderer := HtmlRenderer(commonHtmlFlags, "", "")
output := MarkdownOptions([]byte(input), renderer, opt)

if string(output) != result {
t.Error("output dose not match.")
}
}
4 changes: 4 additions & 0 deletions inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ func lineBreak(p *parser, out *bytes.Buffer, data []byte, offset int) int {
precededByBackslash := offset >= 1 && data[offset-1] == '\\' // see http://spec.commonmark.org/0.18/#example-527
precededByBackslash = precededByBackslash && p.flags&EXTENSION_BACKSLASH_LINE_BREAK != 0

if p.flags&EXTENSION_JOIN_LINES != 0 {
return 1
}

// should there be a hard line break here?
if p.flags&EXTENSION_HARD_LINE_BREAK == 0 && !precededByTwoSpaces && !precededByBackslash {
return 0
Expand Down
1 change: 1 addition & 0 deletions markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
EXTENSION_AUTO_HEADER_IDS // Create the header ID from the text
EXTENSION_BACKSLASH_LINE_BREAK // translate trailing backslashes into line breaks
EXTENSION_DEFINITION_LISTS // render definition lists
EXTENSION_JOIN_LINES // delete newline and join lines

commonHtmlFlags = 0 |
HTML_USE_XHTML |
Expand Down