summaryrefslogtreecommitdiff
path: root/vendor/github.com/yuin/goldmark/extension/cjk.go
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2024-10-25 00:47:47 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2024-10-25 00:47:47 +0200
commitc6cc0108ca7738023b45e0eeac0fa2390532dd93 (patch)
tree36890e6cd3091bbab8efbe686cc56f467f645bfd /vendor/github.com/yuin/goldmark/extension/cjk.go
parent0130404a1dc663d4aa68d780c9bcb23a4243e68d (diff)
downloadjbmafp-master.tar.gz
Added vendor lock on depsHEADmaster
Diffstat (limited to 'vendor/github.com/yuin/goldmark/extension/cjk.go')
-rw-r--r--vendor/github.com/yuin/goldmark/extension/cjk.go51
1 files changed, 51 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..cb6f955
--- /dev/null
+++ b/vendor/github.com/yuin/goldmark/extension/cjk.go
@@ -0,0 +1,51 @@
+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)
+
+// WithEastAsianLineBreaks is a functional option that indicates whether softline breaks
+// between east asian wide characters should be ignored.
+func WithEastAsianLineBreaks() CJKOption {
+ return func(c *cjk) {
+ c.EastAsianLineBreaks = true
+ }
+}
+
+// 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 bool
+ EscapedSpace bool
+}
+
+var CJK = NewCJK(WithEastAsianLineBreaks(), WithEscapedSpace())
+
+// NewCJK returns a new extension with given options.
+func NewCJK(opts ...CJKOption) goldmark.Extender {
+ e := &cjk{}
+ for _, opt := range opts {
+ opt(e)
+ }
+ return e
+}
+
+func (e *cjk) Extend(m goldmark.Markdown) {
+ if e.EastAsianLineBreaks {
+ m.Renderer().AddOptions(html.WithEastAsianLineBreaks())
+ }
+ if e.EscapedSpace {
+ m.Renderer().AddOptions(html.WithWriter(html.NewWriter(html.WithEscapedSpace())))
+ m.Parser().AddOptions(parser.WithEscapedSpace())
+ }
+}