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:
OMOTO Tsukasa 2023-08-27 14:49:07 +09:00
parent d39ab8f93e
commit 6ef9b10a3a
2 changed files with 3 additions and 4 deletions

View file

@ -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,
)

View file

@ -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')
}
}