mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
Improve line breaking behavior for east asian characters
This commit aims to produce more natural line breaks in the rendered output.
This commit is contained in:
parent
d39ab8f93e
commit
6ef9b10a3a
2 changed files with 3 additions and 4 deletions
|
|
@ -140,7 +140,7 @@ func TestEastAsianLineBreaks(t *testing.T) {
|
|||
No: no,
|
||||
Description: "Soft line breaks between a western character and an east asian wide character are rendered as a newline",
|
||||
Markdown: "太郎は\\ **「こんにちわ」**\\ と言ったa\nんです",
|
||||
Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言ったa\nんです</p>",
|
||||
Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言ったaんです</p>",
|
||||
},
|
||||
t,
|
||||
)
|
||||
|
|
@ -152,7 +152,7 @@ func TestEastAsianLineBreaks(t *testing.T) {
|
|||
No: no,
|
||||
Description: "Soft line breaks between an east asian wide character and a western character are rendered as a newline",
|
||||
Markdown: "太郎は\\ **「こんにちわ」**\\ と言った\nbんです",
|
||||
Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言った\nbんです</p>",
|
||||
Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言ったbんです</p>",
|
||||
},
|
||||
t,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -669,8 +669,7 @@ func (r *Renderer) renderText(w util.BufWriter, source []byte, node ast.Node, en
|
|||
if siblingText := sibling.(*ast.Text).Text(source); len(siblingText) != 0 {
|
||||
thisLastRune := util.ToRune(value, len(value)-1)
|
||||
siblingFirstRune, _ := utf8.DecodeRune(siblingText)
|
||||
if !(util.IsEastAsianWideRune(thisLastRune) &&
|
||||
util.IsEastAsianWideRune(siblingFirstRune)) {
|
||||
if !util.IsEastAsianWideRune(thisLastRune) && !util.IsEastAsianWideRune(siblingFirstRune) {
|
||||
_ = w.WriteByte('\n')
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue