|
| 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 | + // Enables EscapedSpace |
| 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 | +func TestEastAsianLineBreaks(t *testing.T) { |
| 62 | + markdown := goldmark.New(goldmark.WithRendererOptions( |
| 63 | + html.WithXHTML(), |
| 64 | + html.WithUnsafe(), |
| 65 | + )) |
| 66 | + no := 1 |
| 67 | + testutil.DoTestCase( |
| 68 | + markdown, |
| 69 | + testutil.MarkdownTestCase{ |
| 70 | + No: no, |
| 71 | + Description: "Soft line breaks are rendered as a newline, so some asian users will see it as an unnecessary space", |
| 72 | + Markdown: "太郎は\\ **「こんにちわ」**\\ と言った\nんです", |
| 73 | + Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言った\nんです</p>", |
| 74 | + }, |
| 75 | + t, |
| 76 | + ) |
| 77 | + |
| 78 | + // Enables EastAsianLineBreaks |
| 79 | + |
| 80 | + markdown = goldmark.New(goldmark.WithRendererOptions( |
| 81 | + html.WithXHTML(), |
| 82 | + html.WithUnsafe(), |
| 83 | + ), |
| 84 | + goldmark.WithExtensions(NewCJK(WithEastAsianLineBreaks())), |
| 85 | + ) |
| 86 | + |
| 87 | + no = 2 |
| 88 | + testutil.DoTestCase( |
| 89 | + markdown, |
| 90 | + testutil.MarkdownTestCase{ |
| 91 | + No: no, |
| 92 | + Description: "Soft line breaks between east asian wide characters are ignored", |
| 93 | + Markdown: "太郎は\\ **「こんにちわ」**\\ と言った\nんです", |
| 94 | + Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言ったんです</p>", |
| 95 | + }, |
| 96 | + t, |
| 97 | + ) |
| 98 | + |
| 99 | + no = 3 |
| 100 | + testutil.DoTestCase( |
| 101 | + markdown, |
| 102 | + testutil.MarkdownTestCase{ |
| 103 | + No: no, |
| 104 | + Description: "Soft line breaks between western characters are rendered as a newline", |
| 105 | + Markdown: "太郎は\\ **「こんにちわ」**\\ と言ったa\nbんです", |
| 106 | + Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言ったa\nbんです</p>", |
| 107 | + }, |
| 108 | + t, |
| 109 | + ) |
| 110 | + |
| 111 | + no = 4 |
| 112 | + testutil.DoTestCase( |
| 113 | + markdown, |
| 114 | + testutil.MarkdownTestCase{ |
| 115 | + No: no, |
| 116 | + Description: "Soft line breaks between a western character and an east asian wide character are rendered as a newline", |
| 117 | + Markdown: "太郎は\\ **「こんにちわ」**\\ と言ったa\nんです", |
| 118 | + Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言ったa\nんです</p>", |
| 119 | + }, |
| 120 | + t, |
| 121 | + ) |
| 122 | + |
| 123 | + no = 5 |
| 124 | + testutil.DoTestCase( |
| 125 | + markdown, |
| 126 | + testutil.MarkdownTestCase{ |
| 127 | + No: no, |
| 128 | + Description: "Soft line breaks between an east asian wide character and a western character are rendered as a newline", |
| 129 | + Markdown: "太郎は\\ **「こんにちわ」**\\ と言った\nbんです", |
| 130 | + Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言った\nbんです</p>", |
| 131 | + }, |
| 132 | + t, |
| 133 | + ) |
| 134 | + |
| 135 | + // WithHardWraps take precedence over WithEastAsianLineBreaks |
| 136 | + markdown = goldmark.New(goldmark.WithRendererOptions( |
| 137 | + html.WithHardWraps(), |
| 138 | + html.WithXHTML(), |
| 139 | + html.WithUnsafe(), |
| 140 | + ), |
| 141 | + goldmark.WithExtensions(NewCJK(WithEastAsianLineBreaks())), |
| 142 | + ) |
| 143 | + no = 6 |
| 144 | + testutil.DoTestCase( |
| 145 | + markdown, |
| 146 | + testutil.MarkdownTestCase{ |
| 147 | + No: no, |
| 148 | + Description: "WithHardWraps take precedence over WithEastAsianLineBreaks", |
| 149 | + Markdown: "太郎は\\ **「こんにちわ」**\\ と言った\nんです", |
| 150 | + Expected: "<p>太郎は\\ <strong>「こんにちわ」</strong>\\ と言った<br />\nんです</p>", |
| 151 | + }, |
| 152 | + t, |
| 153 | + ) |
| 154 | +} |
0 commit comments