From 6ef9b10a3a1a032b995d47b51eca99e0d9fc0581 Mon Sep 17 00:00:00 2001 From: OMOTO Tsukasa Date: Sun, 27 Aug 2023 14:49:07 +0900 Subject: [PATCH] Improve line breaking behavior for east asian characters This commit aims to produce more natural line breaks in the rendered output. --- extension/cjk_test.go | 4 ++-- renderer/html/html.go | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/extension/cjk_test.go b/extension/cjk_test.go index e97bb72..40a7a10 100644 --- a/extension/cjk_test.go +++ b/extension/cjk_test.go @@ -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: "

太郎は\\ 「こんにちわ」\\ と言ったa\nんです

", + Expected: "

太郎は\\ 「こんにちわ」\\ と言ったaんです

", }, 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: "

太郎は\\ 「こんにちわ」\\ と言った\nbんです

", + Expected: "

太郎は\\ 「こんにちわ」\\ と言ったbんです

", }, t, ) diff --git a/renderer/html/html.go b/renderer/html/html.go index 3503688..73f7835 100644 --- a/renderer/html/html.go +++ b/renderer/html/html.go @@ -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') } }