1 package extension
2
3 import (
4 "testing"
5
6 "github.com/yuin/goldmark"
7 "github.com/yuin/goldmark/renderer/html"
8 "github.com/yuin/goldmark/testutil"
9 )
10
11 func TestEscapedSpace(t *testing.T) {
12 markdown := goldmark.New(goldmark.WithRendererOptions(
13 html.WithXHTML(),
14 html.WithUnsafe(),
15 ))
16 no := 1
17 testutil.DoTestCase(
18 markdown,
19 testutil.MarkdownTestCase{
20 No: no,
21 Description: "Without spaces around an emphasis started with east asian punctuations, it is not interpreted as an emphasis(as defined in CommonMark spec)",
22 Markdown: "太郎は**「こんにちわ」**と言った\nんです",
23 Expected: "<p>太郎は**「こんにちわ」**と言った\nんです</p>",
24 },
25 t,
26 )
27
28 no = 2
29 testutil.DoTestCase(
30 markdown,
31 testutil.MarkdownTestCase{
32 No: no,
33 Description: "With spaces around an emphasis started with east asian punctuations, it is interpreted as an emphasis(but remains unnecessary spaces)",
34 Markdown: "太郎は **「こんにちわ」** と言った\nんです",
35 Expected: "<p>太郎は <strong>「こんにちわ」</strong> と言った\nんです</p>",
36 },
37 t,
38 )
39
40
41 markdown = goldmark.New(goldmark.WithRendererOptions(
42 html.WithXHTML(),
43 html.WithUnsafe(),
44 ),
45 goldmark.WithExtensions(NewCJK(WithEscapedSpace())),
46 )
47
48 no = 3
49 testutil.DoTestCase(
50 markdown,
51 testutil.MarkdownTestCase{
52 No: no,
53 Description: "With spaces around an emphasis started with east asian punctuations,it is interpreted as an emphasis",
54 Markdown: "太郎は\\ **「こんにちわ」**\\ と言った\nんです",
55 Expected: "<p>太郎は<strong>「こんにちわ」</strong>と言った\nんです</p>",
56 },
57 t,
58 )
59
60
61
62
63 markdown = goldmark.New(goldmark.WithRendererOptions(
64 html.WithXHTML(),
65 html.WithUnsafe(),
66 ),
67 goldmark.WithExtensions(
68 NewCJK(WithEscapedSpace()),
69 Linkify,
70 ),
71 )
72
73 no = 4
74 testutil.DoTestCase(
75 markdown,
76 testutil.MarkdownTestCase{
77 No: no,
78 Description: "Escaped space and linkfy extension",
79 Markdown: "太郎は\\ **「こんにちわ」**\\ と言った\nんです",
80 Expected: "<p>太郎は<strong>「こんにちわ」</strong>と言った\nんです</p>",
81 },
82 t,
83 )
84 }
85
86 func TestEastAsianLineBreaks(t *testing.T) {
87 markdown := goldmark.New(goldmark.WithRendererOptions(
88 html.WithXHTML(),
89 html.WithUnsafe(),
90 ))
91 no := 1
92 testutil.DoTestCase(
93 markdown,
94 testutil.MarkdownTestCase{
95 No: no,
96 Description: "Soft line breaks are rendered as a newline, so some asian users will see it as an unnecessary space",
97 Markdown: "太郎は\\ **「こんにちわ」**\\ と言った\nんです",
98 Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言った\nんです</p>",
99 },
100 t,
101 )
102
103
104
105 markdown = goldmark.New(goldmark.WithRendererOptions(
106 html.WithXHTML(),
107 html.WithUnsafe(),
108 ),
109 goldmark.WithExtensions(NewCJK(WithEastAsianLineBreaks())),
110 )
111
112 no = 2
113 testutil.DoTestCase(
114 markdown,
115 testutil.MarkdownTestCase{
116 No: no,
117 Description: "Soft line breaks between east asian wide characters are ignored",
118 Markdown: "太郎は\\ **「こんにちわ」**\\ と言った\nんです",
119 Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言ったんです</p>",
120 },
121 t,
122 )
123
124 no = 3
125 testutil.DoTestCase(
126 markdown,
127 testutil.MarkdownTestCase{
128 No: no,
129 Description: "Soft line breaks between western characters are rendered as a newline",
130 Markdown: "太郎は\\ **「こんにちわ」**\\ と言ったa\nbんです",
131 Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言ったa\nbんです</p>",
132 },
133 t,
134 )
135
136 no = 4
137 testutil.DoTestCase(
138 markdown,
139 testutil.MarkdownTestCase{
140 No: no,
141 Description: "Soft line breaks between a western character and an east asian wide character are rendered as a newline",
142 Markdown: "太郎は\\ **「こんにちわ」**\\ と言ったa\nんです",
143 Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言ったa\nんです</p>",
144 },
145 t,
146 )
147
148 no = 5
149 testutil.DoTestCase(
150 markdown,
151 testutil.MarkdownTestCase{
152 No: no,
153 Description: "Soft line breaks between an east asian wide character and a western character are rendered as a newline",
154 Markdown: "太郎は\\ **「こんにちわ」**\\ と言った\nbんです",
155 Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言った\nbんです</p>",
156 },
157 t,
158 )
159
160
161 markdown = goldmark.New(goldmark.WithRendererOptions(
162 html.WithHardWraps(),
163 html.WithXHTML(),
164 html.WithUnsafe(),
165 ),
166 goldmark.WithExtensions(NewCJK(WithEastAsianLineBreaks())),
167 )
168 no = 6
169 testutil.DoTestCase(
170 markdown,
171 testutil.MarkdownTestCase{
172 No: no,
173 Description: "WithHardWraps take precedence over WithEastAsianLineBreaks",
174 Markdown: "太郎は\\ **「こんにちわ」**\\ と言った\nんです",
175 Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言った<br />\nんです</p>",
176 },
177 t,
178 )
179
180
181 markdown = goldmark.New(goldmark.WithRendererOptions(
182 html.WithXHTML(),
183 html.WithUnsafe(),
184 ),
185 goldmark.WithExtensions(
186 NewCJK(WithEastAsianLineBreaks()),
187 Linkify,
188 ),
189 )
190 no = 7
191 testutil.DoTestCase(
192 markdown,
193 testutil.MarkdownTestCase{
194 No: no,
195 Description: "WithEastAsianLineBreaks and linkfy extension",
196 Markdown: "太郎は\\ **「こんにちわ」**\\ と言った\r\nんです",
197 Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言ったんです</p>",
198 },
199 t,
200 )
201 no = 8
202 testutil.DoTestCase(
203 markdown,
204 testutil.MarkdownTestCase{
205 No: no,
206 Description: "Soft line breaks between east asian wide characters or punctuations are ignored",
207 Markdown: "太郎は\\ **「こんにちわ」**\\ と、\r\n言った\r\nんです",
208 Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と、言ったんです</p>",
209 },
210 t,
211 )
212 no = 9
213 testutil.DoTestCase(
214 markdown,
215 testutil.MarkdownTestCase{
216 No: no,
217 Description: "Soft line breaks between an east asian wide character and a western character are ignored",
218 Markdown: "私はプログラマーです。\n東京の会社に勤めています。\nGoでWebアプリケーションを開発しています。",
219 Expected: "<p>私はプログラマーです。東京の会社に勤めています。\nGoでWebアプリケーションを開発しています。</p>",
220 },
221 t,
222 )
223
224
225 markdown = goldmark.New(goldmark.WithRendererOptions(
226 html.WithXHTML(),
227 html.WithUnsafe(),
228 ),
229 goldmark.WithExtensions(
230 NewCJK(WithEastAsianLineBreaks(EastAsianLineBreaksCSS3Draft)),
231 ),
232 )
233 no = 10
234 testutil.DoTestCase(
235 markdown,
236 testutil.MarkdownTestCase{
237 No: no,
238 Description: "Soft line breaks between a western character and an east asian wide character are ignored",
239 Markdown: "太郎は\\ **「こんにちわ」**\\ と言ったa\nんです",
240 Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言ったaんです</p>",
241 },
242 t,
243 )
244
245 no = 11
246 testutil.DoTestCase(
247 markdown,
248 testutil.MarkdownTestCase{
249 No: no,
250 Description: "Soft line breaks between an east asian wide character and a western character are ignored",
251 Markdown: "太郎は\\ **「こんにちわ」**\\ と言った\nbんです",
252 Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言ったbんです</p>",
253 },
254 t,
255 )
256
257 no = 12
258 testutil.DoTestCase(
259 markdown,
260 testutil.MarkdownTestCase{
261 No: no,
262 Description: "Soft line breaks between an east asian wide character and a western character are ignored",
263 Markdown: "私はプログラマーです。\n東京の会社に勤めています。\nGoでWebアプリケーションを開発しています。",
264 Expected: "<p>私はプログラマーです。東京の会社に勤めています。GoでWebアプリケーションを開発しています。</p>",
265 },
266 t,
267 )
268
269 }
270
View as plain text