summaryrefslogtreecommitdiff
path: root/vendor/github.com/yuin/goldmark/extension/cjk.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2025-09-30 13:34:10 +0200
committerStefan Majewsky <majewsky@gmx.net>2025-09-30 13:37:25 +0200
commite75d9e371269a4e46bffa6b3dd1fc7d040e82750 (patch)
treec1f2a9aa8022a2710af5e5a577578855584540df /vendor/github.com/yuin/goldmark/extension/cjk.go
parent0bb27576a37de4bf76dab35c73fa8790fcfa706a (diff)
downloadgofu-f8e0b3d1a52bae7500f4871cfcc855230216c279.tar.gz
add mdeditv2025.1
Diffstat (limited to 'vendor/github.com/yuin/goldmark/extension/cjk.go')
-rw-r--r--vendor/github.com/yuin/goldmark/extension/cjk.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/vendor/github.com/yuin/goldmark/extension/cjk.go b/vendor/github.com/yuin/goldmark/extension/cjk.go
new file mode 100644
index 0000000..a3238c2
--- /dev/null
+++ b/vendor/github.com/yuin/goldmark/extension/cjk.go
@@ -0,0 +1,72 @@
+package extension
+
+import (
+ "github.com/yuin/goldmark"
+ "github.com/yuin/goldmark/parser"
+ "github.com/yuin/goldmark/renderer/html"
+)
+
+// A CJKOption sets options for CJK support mostly for HTML based renderers.
+type CJKOption func(*cjk)
+
+// A EastAsianLineBreaks is a style of east asian line breaks.
+type EastAsianLineBreaks int
+
+const (
+ //EastAsianLineBreaksNone renders line breaks as it is.
+ EastAsianLineBreaksNone EastAsianLineBreaks = iota
+ // EastAsianLineBreaksSimple is a style where soft line breaks are ignored
+ // if both sides of the break are east asian wide characters.
+ EastAsianLineBreaksSimple
+ // EastAsianLineBreaksCSS3Draft is a style where soft line breaks are ignored
+ // even if only one side of the break is an east asian wide character.
+ EastAsianLineBreaksCSS3Draft
+)
+
+// WithEastAsianLineBreaks is a functional option that indicates whether softline breaks
+// between east asian wide characters should be ignored.
+// style defauts to [EastAsianLineBreaksSimple] .
+func WithEastAsianLineBreaks(style ...EastAsianLineBreaks) CJKOption {
+ return func(c *cjk) {
+ if len(style) == 0 {
+ c.EastAsianLineBreaks = EastAsianLineBreaksSimple
+ return
+ }
+ c.EastAsianLineBreaks = style[0]
+ }
+}
+
+// WithEscapedSpace is a functional option that indicates that a '\' escaped half-space(0x20) should not be rendered.
+func WithEscapedSpace() CJKOption {
+ return func(c *cjk) {
+ c.EscapedSpace = true
+ }
+}
+
+type cjk struct {
+ EastAsianLineBreaks EastAsianLineBreaks
+ EscapedSpace bool
+}
+
+// CJK is a goldmark extension that provides functionalities for CJK languages.
+var CJK = NewCJK(WithEastAsianLineBreaks(), WithEscapedSpace())
+
+// NewCJK returns a new extension with given options.
+func NewCJK(opts ...CJKOption) goldmark.Extender {
+ e := &cjk{
+ EastAsianLineBreaks: EastAsianLineBreaksNone,
+ }
+ for _, opt := range opts {
+ opt(e)
+ }
+ return e
+}
+
+func (e *cjk) Extend(m goldmark.Markdown) {
+ m.Renderer().AddOptions(html.WithEastAsianLineBreaks(
+ html.EastAsianLineBreaks(e.EastAsianLineBreaks)))
+ if e.EscapedSpace {
+ m.Renderer().AddOptions(html.WithWriter(html.NewWriter(html.WithEscapedSpace())))
+ m.Parser().AddOptions(parser.WithEscapedSpace())
+ }
+}