diff options
author | OMOTO Tsukasa <[email protected]> | 2023-10-29 18:13:56 +0900 |
---|---|---|
committer | GitHub <[email protected]> | 2023-10-29 10:13:56 +0100 |
commit | db14238ba323279b28e7ad4cfff5aa10909ccd18 (patch) | |
tree | 6b0059b2ccf27fe7d262fea95d7be3629bef8eff /markup | |
parent | 3f64b5a3de5f097c4ee1b70505398f75feb391c4 (diff) | |
download | hugo-db14238ba323279b28e7ad4cfff5aa10909ccd18.tar.gz hugo-db14238ba323279b28e7ad4cfff5aa10909ccd18.zip |
markup/goldmark: Update the CJK extension to allow specifying line break styles
This commit follows https://github.com/yuin/goldmark/pull/411
Diffstat (limited to 'markup')
-rw-r--r-- | markup/goldmark/convert.go | 6 | ||||
-rw-r--r-- | markup/goldmark/convert_test.go | 54 | ||||
-rw-r--r-- | markup/goldmark/goldmark_config/config.go | 10 |
3 files changed, 66 insertions, 4 deletions
diff --git a/markup/goldmark/convert.go b/markup/goldmark/convert.go index d66687783..6ebcd8a77 100644 --- a/markup/goldmark/convert.go +++ b/markup/goldmark/convert.go @@ -140,7 +140,11 @@ func newMarkdown(pcfg converter.ProviderConfig) goldmark.Markdown { if cfg.Extensions.CJK.Enable { opts := []extension.CJKOption{} if cfg.Extensions.CJK.EastAsianLineBreaks { - opts = append(opts, extension.WithEastAsianLineBreaks()) + if cfg.Extensions.CJK.EastAsianLineBreaksStyle == "css3draft" { + opts = append(opts, extension.WithEastAsianLineBreaks(extension.EastAsianLineBreaksCSS3Draft)) + } else { + opts = append(opts, extension.WithEastAsianLineBreaks()) + } } if cfg.Extensions.CJK.EscapedSpace { diff --git a/markup/goldmark/convert_test.go b/markup/goldmark/convert_test.go index 6d73b301f..c97156f7a 100644 --- a/markup/goldmark/convert_test.go +++ b/markup/goldmark/convert_test.go @@ -675,6 +675,60 @@ eastAsianLineBreaks=true c.Assert(got, qt.Contains, "<p>私は太郎です。プログラミングが好きで、運動が苦手です。</p>\n") } +func TestConvertCJKWithExtensionWithEastAsianLineBreaksOptionWithSimple(t *testing.T) { + c := qt.New(t) + + content := ` +私は太郎です。 +Programming が好きで、 +運動が苦手です。 +` + + confStr := ` +[markup] +[markup.goldmark] +[markup.goldmark.extensions.CJK] +enable=true +eastAsianLineBreaks=true +eastAsianLineBreaksStyle="simple" +` + + cfg := config.FromTOMLConfigString(confStr) + conf := testconfig.GetTestConfig(nil, cfg) + + b := convert(c, conf, content) + got := string(b.Bytes()) + + c.Assert(got, qt.Contains, "<p>私は太郎です。\nProgramming が好きで、運動が苦手です。</p>\n") +} + +func TestConvertCJKWithExtensionWithEastAsianLineBreaksOptionWithStyle(t *testing.T) { + c := qt.New(t) + + content := ` +私は太郎です。 +Programming が好きで、 +運動が苦手です。 +` + + confStr := ` +[markup] +[markup.goldmark] +[markup.goldmark.extensions.CJK] +enable=true +eastAsianLineBreaks=true +eastAsianLineBreaksStyle="css3draft" +` + + cfg := config.FromTOMLConfigString(confStr) + conf := testconfig.GetTestConfig(nil, cfg) + + b := convert(c, conf, content) + got := string(b.Bytes()) + + c.Assert(got, qt.Contains, "<p>私は太郎です。Programming が好きで、運動が苦手です。</p>\n") +} + func TestConvertCJKWithExtensionWithEscapedSpaceOption(t *testing.T) { c := qt.New(t) diff --git a/markup/goldmark/goldmark_config/config.go b/markup/goldmark/goldmark_config/config.go index dfbcc5a90..cdfb4e7cc 100644 --- a/markup/goldmark/goldmark_config/config.go +++ b/markup/goldmark/goldmark_config/config.go @@ -44,9 +44,10 @@ var Default = Config{ LinkifyProtocol: "https", TaskList: true, CJK: CJK{ - Enable: false, - EastAsianLineBreaks: false, - EscapedSpace: false, + Enable: false, + EastAsianLineBreaks: false, + EastAsianLineBreaksStyle: "simple", + EscapedSpace: false, }, }, Renderer: Renderer{ @@ -118,6 +119,9 @@ type CJK struct { // Whether softline breaks between east asian wide characters should be ignored. EastAsianLineBreaks bool + // Styles of Line Breaking of EastAsianLineBreaks: "simple" or "css3draft" + EastAsianLineBreaksStyle string + // Whether a '\' escaped half-space(0x20) should not be rendered. EscapedSpace bool } |