@chayns-components/format 5.0.0-beta.650 → 5.0.0-beta.674

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/lib/cjs/types/format.js +2 -0
  2. package/lib/cjs/types/format.js.map +1 -0
  3. package/lib/cjs/utils/escape.js +1 -3
  4. package/lib/cjs/utils/escape.js.map +1 -1
  5. package/lib/cjs/utils/formatString/bb-code/findBBCode.js +6 -4
  6. package/lib/cjs/utils/formatString/bb-code/findBBCode.js.map +1 -1
  7. package/lib/cjs/utils/formatString/bb-code/formatBBCode.js +37 -37
  8. package/lib/cjs/utils/formatString/bb-code/formatBBCode.js.map +1 -1
  9. package/lib/cjs/utils/formatString/formatString.js +30 -42
  10. package/lib/cjs/utils/formatString/formatString.js.map +1 -1
  11. package/lib/cjs/utils/formatString/formatString.test.js +549 -0
  12. package/lib/cjs/utils/formatString/formatString.test.js.map +1 -0
  13. package/lib/cjs/utils/formatString/markdown/formatMarkdown.js +145 -29
  14. package/lib/cjs/utils/formatString/markdown/formatMarkdown.js.map +1 -1
  15. package/lib/esm/types/format.js +2 -0
  16. package/lib/esm/types/format.js.map +1 -0
  17. package/lib/esm/utils/escape.js +0 -1
  18. package/lib/esm/utils/escape.js.map +1 -1
  19. package/lib/esm/utils/formatString/bb-code/findBBCode.js +6 -4
  20. package/lib/esm/utils/formatString/bb-code/findBBCode.js.map +1 -1
  21. package/lib/esm/utils/formatString/bb-code/formatBBCode.js +37 -39
  22. package/lib/esm/utils/formatString/bb-code/formatBBCode.js.map +1 -1
  23. package/lib/esm/utils/formatString/formatString.js +33 -45
  24. package/lib/esm/utils/formatString/formatString.js.map +1 -1
  25. package/lib/esm/utils/formatString/formatString.test.js +547 -0
  26. package/lib/esm/utils/formatString/formatString.test.js.map +1 -0
  27. package/lib/esm/utils/formatString/markdown/formatMarkdown.js +141 -26
  28. package/lib/esm/utils/formatString/markdown/formatMarkdown.js.map +1 -1
  29. package/lib/types/types/format.d.ts +5 -0
  30. package/lib/types/utils/escape.d.ts +0 -1
  31. package/lib/types/utils/formatString/bb-code/findBBCode.d.ts +2 -0
  32. package/lib/types/utils/formatString/bb-code/formatBBCode.d.ts +3 -4
  33. package/lib/types/utils/formatString/formatString.d.ts +1 -3
  34. package/lib/types/utils/formatString/formatString.test.d.ts +1 -0
  35. package/lib/types/utils/formatString/markdown/formatMarkdown.d.ts +3 -1
  36. package/package.json +6 -4
  37. package/lib/cjs/utils/formatString/markdown/formatMarkdownTable.js +0 -86
  38. package/lib/cjs/utils/formatString/markdown/formatMarkdownTable.js.map +0 -1
  39. package/lib/esm/utils/formatString/markdown/formatMarkdownTable.js +0 -78
  40. package/lib/esm/utils/formatString/markdown/formatMarkdownTable.js.map +0 -1
  41. package/lib/types/utils/formatString/markdown/formatMarkdownTable.d.ts +0 -9
@@ -0,0 +1,549 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _formatString = require("./formatString");
5
+ const removeLinebreaks = text => text.replace(/\n/g, '');
6
+ (0, _vitest.describe)('HTML Formatter Function', () => {
7
+ (0, _vitest.describe)('Format Plain Text', () => {
8
+ (0, _vitest.describe)('Line breaks', () => {
9
+ (0, _vitest.test)('should format line breaks correctly', () => {
10
+ const result = (0, _formatString.formatStringToHtml)('Line 1\nLine 2');
11
+ (0, _vitest.expect)(result.html).toEqual('<p>Line 1\nLine 2</p>');
12
+ (0, _vitest.expect)(result.tables).toEqual([]);
13
+ });
14
+ (0, _vitest.test)('should format multiple line breaks correctly', () => {
15
+ const result = (0, _formatString.formatStringToHtml)('Line 1\n\nLine 2');
16
+ (0, _vitest.expect)(result.html).toEqual('<p>Line 1</p>\n<p>Line 2</p>');
17
+ (0, _vitest.expect)(result.tables).toEqual([]);
18
+ });
19
+ (0, _vitest.test)('should remove trailing and leading new lines', () => {
20
+ const result = (0, _formatString.formatStringToHtml)('\n\n\nLine 1\n\n\n');
21
+ (0, _vitest.expect)(result.html).toEqual('<p>Line 1</p>');
22
+ (0, _vitest.expect)(result.tables).toEqual([]);
23
+ });
24
+ });
25
+ (0, _vitest.describe)('Whitespaces', () => {
26
+ (0, _vitest.test)('should not remove repeated whitespaces', () => {
27
+ const result = (0, _formatString.formatStringToHtml)('Text with spaces');
28
+ (0, _vitest.expect)(result.html).toEqual('<p>Text with spaces</p>');
29
+ (0, _vitest.expect)(result.tables).toEqual([]);
30
+ });
31
+ (0, _vitest.test)('should not remove leading and trailing whitespaces', () => {
32
+ const result = (0, _formatString.formatStringToHtml)(' Text ');
33
+ (0, _vitest.expect)(result.html).toEqual('<p> Text </p>');
34
+ (0, _vitest.expect)(result.tables).toEqual([]);
35
+ });
36
+ });
37
+ (0, _vitest.describe)('HTML', () => {
38
+ (0, _vitest.test)('should escape < and > correctly', () => {
39
+ const resultEscape = (0, _formatString.formatStringToHtml)('<div>Test</div>');
40
+ (0, _vitest.expect)(resultEscape.html).toEqual('<p>&lt;div&gt;Test&lt;/div&gt;</p>');
41
+ (0, _vitest.expect)(resultEscape.tables).toEqual([]);
42
+ });
43
+ (0, _vitest.test)('should not escape &', () => {
44
+ const resultEscape1 = (0, _formatString.formatStringToHtml)('&lt;div&gt;Test&lt;/div&gt;');
45
+ (0, _vitest.expect)(resultEscape1.html).toEqual('<p>&lt;div&gt;Test&lt;/div&gt;</p>');
46
+ (0, _vitest.expect)(resultEscape1.tables).toEqual([]);
47
+ const resultEscape2 = (0, _formatString.formatStringToHtml)('&amp;lt;div&amp;gt;Test&amp;lt;/div&amp;gt;');
48
+ (0, _vitest.expect)(resultEscape2.html).toEqual('<p>&amp;lt;div&amp;gt;Test&amp;lt;/div&amp;gt;</p>');
49
+ (0, _vitest.expect)(resultEscape2.tables).toEqual([]);
50
+ });
51
+
52
+ // TODO Decide if & should be escaped, when they are not part of an HTML entity.
53
+ });
54
+ (0, _vitest.describe)('URLs', () => {
55
+ (0, _vitest.test)('should not format URLs', () => {
56
+ const result = (0, _formatString.formatStringToHtml)('https://example.com');
57
+ (0, _vitest.expect)(result.html).toEqual('<p>https://example.com</p>');
58
+ (0, _vitest.expect)(result.tables).toEqual([]);
59
+ });
60
+ });
61
+ });
62
+ (0, _vitest.describe)('Format Markdown', () => {
63
+ (0, _vitest.describe)('All Elements', () => {
64
+ (0, _vitest.test)('should format text styling correctly', () => {
65
+ const boldResult = (0, _formatString.formatStringToHtml)('**bold**');
66
+ (0, _vitest.expect)(boldResult.html).toEqual('<p><strong>bold</strong></p>');
67
+ (0, _vitest.expect)(boldResult.tables).toEqual([]);
68
+ const italicResult = (0, _formatString.formatStringToHtml)('*italic*');
69
+ (0, _vitest.expect)(italicResult.html).toEqual('<p><em>italic</em></p>');
70
+ (0, _vitest.expect)(italicResult.tables).toEqual([]);
71
+ const inlineCodeResult = (0, _formatString.formatStringToHtml)('`inline code`');
72
+ (0, _vitest.expect)(inlineCodeResult.html).toEqual('<p><code>inline code</code></p>');
73
+ (0, _vitest.expect)(inlineCodeResult.tables).toEqual([]);
74
+ });
75
+ (0, _vitest.test)('should format headings correctly', () => {
76
+ const h1Result = (0, _formatString.formatStringToHtml)('# h1');
77
+ (0, _vitest.expect)(h1Result.html).toEqual('<h1>h1</h1>');
78
+ (0, _vitest.expect)(h1Result.tables).toEqual([]);
79
+ const h2Result = (0, _formatString.formatStringToHtml)('## h2');
80
+ (0, _vitest.expect)(h2Result.html).toEqual('<h2>h2</h2>');
81
+ (0, _vitest.expect)(h2Result.tables).toEqual([]);
82
+ const h3Result = (0, _formatString.formatStringToHtml)('### h3');
83
+ (0, _vitest.expect)(h3Result.html).toEqual('<h3>h3</h3>');
84
+ (0, _vitest.expect)(h3Result.tables).toEqual([]);
85
+ const h4Result = (0, _formatString.formatStringToHtml)('#### h4');
86
+ (0, _vitest.expect)(h4Result.html).toEqual('<h4>h4</h4>');
87
+ (0, _vitest.expect)(h4Result.tables).toEqual([]);
88
+ const h5Result = (0, _formatString.formatStringToHtml)('##### h5');
89
+ (0, _vitest.expect)(h5Result.html).toEqual('<h5>h5</h5>');
90
+ (0, _vitest.expect)(h5Result.tables).toEqual([]);
91
+ const h6Result = (0, _formatString.formatStringToHtml)('###### h6');
92
+ (0, _vitest.expect)(h6Result.html).toEqual('<h6>h6</h6>');
93
+ (0, _vitest.expect)(h6Result.tables).toEqual([]);
94
+ });
95
+ (0, _vitest.test)('should format links correctly', () => {
96
+ const result = (0, _formatString.formatStringToHtml)('[Link](https://example.com)');
97
+ (0, _vitest.expect)(result.html).toEqual('<p><a href="https://example.com">Link</a></p>');
98
+ (0, _vitest.expect)(result.tables).toEqual([]);
99
+ });
100
+ (0, _vitest.test)('should format images correctly', () => {
101
+ const result = (0, _formatString.formatStringToHtml)('![Alt Text](https://example.com/image.jpg)');
102
+ (0, _vitest.expect)(result.html).toEqual('<p><img src="https://example.com/image.jpg" alt="Alt Text"></p>');
103
+ (0, _vitest.expect)(result.tables).toEqual([]);
104
+ });
105
+ (0, _vitest.test)('should format lists correctly', () => {
106
+ const expectedUnorderedListResult = '<ul>\n<li>Item 1</li>\n<li>Item 2</li>\n<li>Item 3</li>\n</ul>';
107
+ const expectedOrderedListResult = '<ol>\n<li>Item 1</li>\n<li>Item 2</li>\n<li>Item 3</li>\n</ol>';
108
+ const unorderedListResult1 = (0, _formatString.formatStringToHtml)('- Item 1\n- Item 2\n- Item 3');
109
+ (0, _vitest.expect)(unorderedListResult1.html).toEqual(expectedUnorderedListResult);
110
+ (0, _vitest.expect)(unorderedListResult1.tables).toEqual([]);
111
+ const unorderedListResult2 = (0, _formatString.formatStringToHtml)('* Item 1\n* Item 2\n* Item 3');
112
+ (0, _vitest.expect)(unorderedListResult2.html).toEqual(expectedUnorderedListResult);
113
+ (0, _vitest.expect)(unorderedListResult2.tables).toEqual([]);
114
+ const orderedListResult = (0, _formatString.formatStringToHtml)('1. Item 1\n2. Item 2\n3. Item 3');
115
+ (0, _vitest.expect)(orderedListResult.html).toEqual(expectedOrderedListResult);
116
+ (0, _vitest.expect)(orderedListResult.tables).toEqual([]);
117
+ const orderedListResult2 = (0, _formatString.formatStringToHtml)('1) Item 1\n2) Item 2\n3) Item 3');
118
+ (0, _vitest.expect)(orderedListResult2.html).toEqual(expectedOrderedListResult);
119
+ (0, _vitest.expect)(orderedListResult2.tables).toEqual([]);
120
+ });
121
+ (0, _vitest.test)('should format thematic breaks correctly', () => {
122
+ const expectedThematicBreakResult = '<hr>';
123
+ const result1 = (0, _formatString.formatStringToHtml)('---');
124
+ (0, _vitest.expect)(result1.html).toEqual(expectedThematicBreakResult);
125
+ (0, _vitest.expect)(result1.tables).toEqual([]);
126
+ const result2 = (0, _formatString.formatStringToHtml)('***');
127
+ (0, _vitest.expect)(result2.html).toEqual(expectedThematicBreakResult);
128
+ (0, _vitest.expect)(result2.tables).toEqual([]);
129
+ });
130
+ (0, _vitest.test)('should format code blocks correctly', () => {
131
+ const resultWithoutLanguage = (0, _formatString.formatStringToHtml)('```\nconst a = 1;\n```');
132
+ (0, _vitest.expect)(resultWithoutLanguage.html).toEqual('<pre><code>const a = 1;</code></pre>');
133
+ (0, _vitest.expect)(resultWithoutLanguage.tables).toEqual([]);
134
+ const resultWithLanguage = (0, _formatString.formatStringToHtml)('```js\nconst a = 1;\n```');
135
+ (0, _vitest.expect)(resultWithLanguage.html).toEqual('<pre><code class="language-js">const a = 1;</code></pre>');
136
+ (0, _vitest.expect)(resultWithLanguage.tables).toEqual([]);
137
+ });
138
+ (0, _vitest.test)('should format tables correctly', () => {
139
+ const inputString = '| Header 1 | Header 2 |\n|----------|----------|\n| Cell 1 | Cell 2 |';
140
+ const result = (0, _formatString.formatStringToHtml)(inputString);
141
+ (0, _vitest.expect)(removeLinebreaks(result.html)).toEqual('<table id="formatted-table-0"><thead><tr><th>Header 1</th><th>Header 2</th></tr></thead><tbody><tr><td>Cell 1</td><td>Cell 2</td></tr></tbody></table>');
142
+ (0, _vitest.expect)(result.tables).toEqual([{
143
+ csv: 'Header 1,Header 2\nCell 1,Cell 2\n',
144
+ raw: inputString,
145
+ id: 'formatted-table-0'
146
+ }]);
147
+ });
148
+ });
149
+ (0, _vitest.describe)('Inline Code', () => {
150
+ (0, _vitest.describe)('HTML In Code', () => {
151
+ (0, _vitest.test)('should escape < and > within inline code correctly', () => {
152
+ const result1 = (0, _formatString.formatStringToHtml)('`<div>Test</div>`');
153
+ (0, _vitest.expect)(result1.html).toEqual('<p><code>&lt;div&gt;Test&lt;/div&gt;</code></p>');
154
+ (0, _vitest.expect)(result1.tables).toEqual([]);
155
+ });
156
+ (0, _vitest.test)('should not escape & within inline code', () => {
157
+ const resultEscape1 = (0, _formatString.formatStringToHtml)('`&lt;div&gt;Test&lt;/div&gt;`');
158
+ (0, _vitest.expect)(resultEscape1.html).toEqual('<p><code>&lt;div&gt;Test&lt;/div&gt;</code></p>');
159
+ (0, _vitest.expect)(resultEscape1.tables).toEqual([]);
160
+ const resultEscape2 = (0, _formatString.formatStringToHtml)('`&amp;lt;div&amp;gt;Test&amp;lt;/div&amp;gt;`');
161
+ (0, _vitest.expect)(resultEscape2.html).toEqual('<p><code>&amp;lt;div&amp;gt;Test&amp;lt;/div&amp;gt;</code></p>');
162
+ (0, _vitest.expect)(resultEscape2.tables).toEqual([]);
163
+ });
164
+ });
165
+ (0, _vitest.test)('should not format markdown within inline code', () => {
166
+ const result = (0, _formatString.formatStringToHtml)('`**bold** *italic*`');
167
+ (0, _vitest.expect)(result.html).toEqual('<p><code>**bold** *italic*</code></p>');
168
+ (0, _vitest.expect)(result.tables).toEqual([]);
169
+ });
170
+ (0, _vitest.test)('should not format bb-code within inline code', () => {
171
+ const result = (0, _formatString.formatStringToHtml)('`[b]bold[/b]`', {
172
+ parseBBCode: true
173
+ });
174
+ (0, _vitest.expect)(result.html).toEqual('<p><code>[b]bold[/b]</code></p>');
175
+ (0, _vitest.expect)(result.tables).toEqual([]);
176
+ });
177
+ });
178
+ (0, _vitest.describe)('Codeblock', () => {
179
+ (0, _vitest.test)('should format code blocks with multiple lines correctly', () => {
180
+ const resultWithoutLanguage = (0, _formatString.formatStringToHtml)('```\nconst a = 1;\nconst b = 2;\n```');
181
+ (0, _vitest.expect)(resultWithoutLanguage.html).toEqual('<pre><code>const a = 1;\nconst b = 2;</code></pre>');
182
+ (0, _vitest.expect)(resultWithoutLanguage.tables).toEqual([]);
183
+ const resultWithLanguage = (0, _formatString.formatStringToHtml)('```js\nconst a = 1;\nconst b = 2;\n```');
184
+ (0, _vitest.expect)(resultWithLanguage.html).toEqual('<pre><code class="language-js">const a = 1;\nconst b = 2;</code></pre>');
185
+ (0, _vitest.expect)(resultWithLanguage.tables).toEqual([]);
186
+ });
187
+ (0, _vitest.describe)('HTML In Code', () => {
188
+ (0, _vitest.test)('should escape < and > within code block', () => {
189
+ const resultWithoutLanguage = (0, _formatString.formatStringToHtml)('```\n<div>Test</div>\n```');
190
+ (0, _vitest.expect)(resultWithoutLanguage.html).toEqual('<pre><code>&lt;div&gt;Test&lt;/div&gt;</code></pre>');
191
+ (0, _vitest.expect)(resultWithoutLanguage.tables).toEqual([]);
192
+ const resultWithLanguage = (0, _formatString.formatStringToHtml)('```html\n<div>Test</div>\n```');
193
+ (0, _vitest.expect)(resultWithLanguage.html).toEqual('<pre><code class="language-html">&lt;div&gt;Test&lt;/div&gt;</code></pre>');
194
+ (0, _vitest.expect)(resultWithLanguage.tables).toEqual([]);
195
+ });
196
+ (0, _vitest.test)('should not escape & within code block', () => {
197
+ const resultEscape1 = (0, _formatString.formatStringToHtml)('```\n&lt;div&gt;Test&lt;/div&gt;\n```');
198
+ (0, _vitest.expect)(resultEscape1.html).toEqual('<pre><code>&lt;div&gt;Test&lt;/div&gt;</code></pre>');
199
+ (0, _vitest.expect)(resultEscape1.tables).toEqual([]);
200
+ const resultEscape2 = (0, _formatString.formatStringToHtml)('```\n&amp;lt;div&amp;gt;Test&amp;lt;/div&amp;gt;\n```');
201
+ (0, _vitest.expect)(resultEscape2.html).toEqual('<pre><code>&amp;lt;div&amp;gt;Test&amp;lt;/div&amp;gt;</code></pre>');
202
+ (0, _vitest.expect)(resultEscape2.tables).toEqual([]);
203
+ });
204
+ });
205
+ (0, _vitest.test)('should not format markdown within code block', () => {
206
+ const resultWithoutLanguage = (0, _formatString.formatStringToHtml)('```\n**Test**\n```');
207
+ (0, _vitest.expect)(resultWithoutLanguage.html).toEqual('<pre><code>**Test**</code></pre>');
208
+ (0, _vitest.expect)(resultWithoutLanguage.tables).toEqual([]);
209
+ const resultWithLanguage = (0, _formatString.formatStringToHtml)('```html\n**Test**\n```');
210
+ (0, _vitest.expect)(resultWithLanguage.html).toEqual('<pre><code class="language-html">**Test**</code></pre>');
211
+ (0, _vitest.expect)(resultWithLanguage.tables).toEqual([]);
212
+ });
213
+ (0, _vitest.test)('should not format bb-code within code block', () => {
214
+ const resultWithoutLanguage = (0, _formatString.formatStringToHtml)('```\n[b]Test[/b]\n```');
215
+ (0, _vitest.expect)(resultWithoutLanguage.html).toEqual('<pre><code>[b]Test[/b]</code></pre>');
216
+ (0, _vitest.expect)(resultWithoutLanguage.tables).toEqual([]);
217
+ const resultWithLanguage = (0, _formatString.formatStringToHtml)('```html\n[b]Test[/b]\n```');
218
+ (0, _vitest.expect)(resultWithLanguage.html).toEqual('<pre><code class="language-html">[b]Test[/b]</code></pre>');
219
+ (0, _vitest.expect)(resultWithLanguage.tables).toEqual([]);
220
+ });
221
+ });
222
+ (0, _vitest.describe)('Table', () => {
223
+ (0, _vitest.test)('should format markdown within table correctly', () => {
224
+ const inputString = '| Header 1 | Header 2 |\n|----------|----------|\n| **Cell 1** | *Cell 2* |';
225
+ const result = (0, _formatString.formatStringToHtml)(inputString);
226
+ (0, _vitest.expect)(removeLinebreaks(result.html)).toEqual('<table id="formatted-table-0"><thead><tr><th>Header 1</th><th>Header 2</th></tr></thead><tbody><tr><td><strong>Cell 1</strong></td><td><em>Cell 2</em></td></tr></tbody></table>');
227
+ (0, _vitest.expect)(result.tables).toEqual([{
228
+ csv: 'Header 1,Header 2\n**Cell 1**,*Cell 2*\n',
229
+ raw: inputString,
230
+ id: 'formatted-table-0'
231
+ }]);
232
+ });
233
+ (0, _vitest.test)('should format bb-code within table correctly', () => {
234
+ const inputString = '| Header 1 | Header 2 |\n|----------|----------|\n| [b]Cell 1[/b] | [i]Cell 2[/i] |';
235
+ const result = (0, _formatString.formatStringToHtml)(inputString, {
236
+ parseBBCode: true
237
+ });
238
+ (0, _vitest.expect)(removeLinebreaks(result.html)).toEqual('<table id="formatted-table-0"><thead><tr><th>Header 1</th><th>Header 2</th></tr></thead><tbody><tr><td><b>Cell 1</b></td><td><i>Cell 2</i></td></tr></tbody></table>');
239
+ (0, _vitest.expect)(result.tables).toEqual([{
240
+ csv: 'Header 1,Header 2\n[b]Cell 1[/b],[i]Cell 2[/i]\n',
241
+ raw: inputString,
242
+ id: 'formatted-table-0'
243
+ }]);
244
+ });
245
+ (0, _vitest.test)('should format html within table correctly', () => {
246
+ const inputString = '| Header 1 | Header 2 | Header 3 |\n|----------|----------|----------|\n| <div>Cell 1</div> | &lt;div&gt;Cell 2&lt;/div&gt; | &amp;lt;div&amp;gt;Cell 3&amp;lt;/div&amp;gt; |';
247
+ const result = (0, _formatString.formatStringToHtml)(inputString, {
248
+ parseBBCode: true
249
+ });
250
+ (0, _vitest.expect)(removeLinebreaks(result.html)).toEqual('<table id="formatted-table-0"><thead><tr><th>Header 1</th><th>Header 2</th><th>Header 3</th></tr></thead><tbody><tr><td>&lt;div&gt;Cell 1&lt;/div&gt;</td><td>&lt;div&gt;Cell 2&lt;/div&gt;</td><td>&amp;lt;div&amp;gt;Cell 3&amp;lt;/div&amp;gt;</td></tr></tbody></table>');
251
+ (0, _vitest.expect)(result.tables).toEqual([{
252
+ csv: 'Header 1,Header 2,Header 3\n<div>Cell 1</div>,<div>Cell 2</div>,&lt;div&gt;Cell 3&lt;/div&gt;\n',
253
+ raw: '| Header 1 | Header 2 | Header 3 |\n|----------|----------|----------|\n| <div>Cell 1</div> | <div>Cell 2</div> | &lt;div&gt;Cell 3&lt;/div&gt; |',
254
+ id: 'formatted-table-0'
255
+ }]);
256
+ });
257
+ (0, _vitest.test)('should format multiple tables correctly', () => {
258
+ const table1 = '| Header 1 | Header 2 |\n|----------|----------|\n| Cell 1 | Cell 2 |';
259
+ const getTable1Result = index => `<table id="formatted-table-${index}"><thead><tr><th>Header 1</th><th>Header 2</th></tr></thead><tbody><tr><td>Cell 1</td><td>Cell 2</td></tr></tbody></table>`;
260
+ const table1Csv = 'Header 1,Header 2\nCell 1,Cell 2\n';
261
+ const table2 = '| Header 3 | Header 4 |\n|----------|----------|\n| Cell 3 | Cell 4 |';
262
+ const getTable2TResult = index => `<table id="formatted-table-${index}"><thead><tr><th>Header 3</th><th>Header 4</th></tr></thead><tbody><tr><td>Cell 3</td><td>Cell 4</td></tr></tbody></table>`;
263
+ const table2Csv = 'Header 3,Header 4\nCell 3,Cell 4\n';
264
+ const result1 = (0, _formatString.formatStringToHtml)(`${table1}\n\n${table2}`);
265
+ (0, _vitest.expect)(removeLinebreaks(result1.html)).toEqual(`${getTable1Result(0)}${getTable2TResult(1)}`);
266
+ (0, _vitest.expect)(result1.tables).toEqual([{
267
+ csv: table1Csv,
268
+ raw: `${table1}\n\n`,
269
+ id: 'formatted-table-0'
270
+ }, {
271
+ csv: table2Csv,
272
+ raw: table2,
273
+ id: 'formatted-table-1'
274
+ }]);
275
+
276
+ // Tables in reverse order.
277
+ const result2 = (0, _formatString.formatStringToHtml)(`${table2}\n\n${table1}`);
278
+ (0, _vitest.expect)(removeLinebreaks(result2.html)).toEqual(`${getTable2TResult(0)}${getTable1Result(1)}`);
279
+ (0, _vitest.expect)(result2.tables).toEqual([{
280
+ csv: table2Csv,
281
+ raw: `${table2}\n\n`,
282
+ id: 'formatted-table-0'
283
+ }, {
284
+ csv: table1Csv,
285
+ raw: table1,
286
+ id: 'formatted-table-1'
287
+ }]);
288
+ });
289
+ });
290
+ (0, _vitest.describe)('List', () => {
291
+ (0, _vitest.test)('should format markdown within list correctly', () => {
292
+ const result = (0, _formatString.formatStringToHtml)('- **Item 1**\n- *Item 2*');
293
+ (0, _vitest.expect)(removeLinebreaks(result.html)).toEqual('<ul><li><strong>Item 1</strong></li><li><em>Item 2</em></li></ul>');
294
+ (0, _vitest.expect)(result.tables).toEqual([]);
295
+ });
296
+ (0, _vitest.test)('should format task lists correctly', () => {
297
+ const result1 = (0, _formatString.formatStringToHtml)('- [ ] 1\n- [x] 2\n- [X] 3');
298
+ (0, _vitest.expect)(removeLinebreaks(result1.html)).toEqual('<ul><li>[ ] 1</li><li>[x] 2</li><li>[x] 3</li></ul>');
299
+ (0, _vitest.expect)(result1.tables).toEqual([]);
300
+ });
301
+ });
302
+ (0, _vitest.describe)('Combined Elements', () => {
303
+ (0, _vitest.test)('should format code block within list correctly', () => {
304
+ const result = (0, _formatString.formatStringToHtml)('* test\n ```\n test\n ```');
305
+ (0, _vitest.expect)(removeLinebreaks(result.html)).toEqual('<ul><li>test<pre><code>test</code></pre></li></ul>');
306
+ (0, _vitest.expect)(result.tables).toEqual([]);
307
+ });
308
+ });
309
+ (0, _vitest.describe)('Conflicts with BB-Code', () => {
310
+ (0, _vitest.test)('should not format bb code tag followed by paranthese to link', () => {
311
+ const result = (0, _formatString.formatStringToHtml)('[b]bold[/b](test)', {
312
+ parseBBCode: true
313
+ });
314
+ (0, _vitest.expect)(result.html).toEqual('<p><b>bold</b>(test)</p>');
315
+ (0, _vitest.expect)(result.tables).toEqual([]);
316
+ });
317
+ });
318
+ });
319
+ (0, _vitest.describe)('Format BB-Code', () => {
320
+ (0, _vitest.describe)('All Elements', () => {
321
+ (0, _vitest.describe)('Inline Elements', () => {
322
+ // b, strong, i, em, u, s, span, img
323
+ (0, _vitest.test)('should format b tag correctly', () => {
324
+ const result = (0, _formatString.formatStringToHtml)('[b]bold[/b]', {
325
+ parseBBCode: true
326
+ });
327
+ (0, _vitest.expect)(result.html).toEqual('<p><b>bold</b></p>');
328
+ (0, _vitest.expect)(result.tables).toEqual([]);
329
+ });
330
+ (0, _vitest.test)('should format strong tag correctly', () => {
331
+ const result = (0, _formatString.formatStringToHtml)('[strong]bold[/strong]', {
332
+ parseBBCode: true
333
+ });
334
+ (0, _vitest.expect)(result.html).toEqual('<p><strong>bold</strong></p>');
335
+ (0, _vitest.expect)(result.tables).toEqual([]);
336
+ });
337
+ (0, _vitest.test)('should format i tag correctly', () => {
338
+ const result = (0, _formatString.formatStringToHtml)('[i]italic[/i]', {
339
+ parseBBCode: true
340
+ });
341
+ (0, _vitest.expect)(result.html).toEqual('<p><i>italic</i></p>');
342
+ (0, _vitest.expect)(result.tables).toEqual([]);
343
+ });
344
+ (0, _vitest.test)('should format em tag correctly', () => {
345
+ const result = (0, _formatString.formatStringToHtml)('[em]italic[/em]', {
346
+ parseBBCode: true
347
+ });
348
+ (0, _vitest.expect)(result.html).toEqual('<p><em>italic</em></p>');
349
+ (0, _vitest.expect)(result.tables).toEqual([]);
350
+ });
351
+ (0, _vitest.test)('should format u tag correctly', () => {
352
+ const result = (0, _formatString.formatStringToHtml)('[u]underline[/u]', {
353
+ parseBBCode: true
354
+ });
355
+ (0, _vitest.expect)(result.html).toEqual('<p><u>underline</u></p>');
356
+ (0, _vitest.expect)(result.tables).toEqual([]);
357
+ });
358
+ (0, _vitest.test)('should format s tag correctly', () => {
359
+ const result = (0, _formatString.formatStringToHtml)('[s]strike[/s]', {
360
+ parseBBCode: true
361
+ });
362
+ (0, _vitest.expect)(result.html).toEqual('<p><s>strike</s></p>');
363
+ (0, _vitest.expect)(result.tables).toEqual([]);
364
+ });
365
+ (0, _vitest.test)('should format span tag correctly', () => {
366
+ const result = (0, _formatString.formatStringToHtml)('[span]span[/span]', {
367
+ parseBBCode: true
368
+ });
369
+ (0, _vitest.expect)(result.html).toEqual('<p><span>span</span></p>');
370
+ (0, _vitest.expect)(result.tables).toEqual([]);
371
+ });
372
+ (0, _vitest.test)('should format img tag correctly', () => {
373
+ const result = (0, _formatString.formatStringToHtml)('[img src="https://example.com/image.jpg"][/img]', {
374
+ parseBBCode: true
375
+ });
376
+ (0, _vitest.expect)(result.html).toEqual('<p><img src="https://example.com/image.jpg"></p>');
377
+ (0, _vitest.expect)(result.tables).toEqual([]);
378
+ });
379
+ });
380
+ (0, _vitest.describe)('Block Level Elements', () => {
381
+ (0, _vitest.test)('should format center tag correctly', () => {
382
+ const result = (0, _formatString.formatStringToHtml)('[center]centered text[/center]', {
383
+ parseBBCode: true
384
+ });
385
+ (0, _vitest.expect)(result.html).toEqual('<p><center>centered text</center></p>');
386
+ (0, _vitest.expect)(result.tables).toEqual([]);
387
+ });
388
+ (0, _vitest.test)('should format ul tag correctly', () => {
389
+ const result = (0, _formatString.formatStringToHtml)('[ul][li]Item 1[/li][li]Item 2[/li][/ul]', {
390
+ parseBBCode: true
391
+ });
392
+ (0, _vitest.expect)(result.html).toEqual('<p><ul><li>Item 1</li><li>Item 2</li></ul></p>');
393
+ (0, _vitest.expect)(result.tables).toEqual([]);
394
+ });
395
+ (0, _vitest.test)('should format ol tag correctly', () => {
396
+ const result = (0, _formatString.formatStringToHtml)('[ol][li]Item 1[/li][li]Item 2[/li][/ol]', {
397
+ parseBBCode: true
398
+ });
399
+ (0, _vitest.expect)(result.html).toEqual('<p><ol><li>Item 1</li><li>Item 2</li></ol></p>');
400
+ (0, _vitest.expect)(result.tables).toEqual([]);
401
+ });
402
+ (0, _vitest.test)('should format li tag correctly', () => {
403
+ const result = (0, _formatString.formatStringToHtml)('[li]Item[/li]', {
404
+ parseBBCode: true
405
+ });
406
+ (0, _vitest.expect)(result.html).toEqual('<p><li>Item</li></p>');
407
+ (0, _vitest.expect)(result.tables).toEqual([]);
408
+ });
409
+ (0, _vitest.test)('should format heading tags correctly', () => {
410
+ const getHeadingInput = tag => `[${tag}]${tag}[/${tag}]`;
411
+ const getHeadingOutput = tag => `<p><${tag}>${tag}</${tag}></p>`;
412
+ const headingTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
413
+ headingTags.forEach(tag => {
414
+ const result = (0, _formatString.formatStringToHtml)(getHeadingInput(tag), {
415
+ parseBBCode: true
416
+ });
417
+ (0, _vitest.expect)(result.html).toEqual(getHeadingOutput(tag));
418
+ (0, _vitest.expect)(result.tables).toEqual([]);
419
+ });
420
+ });
421
+ (0, _vitest.test)('should format p tag correctly', () => {
422
+ const result = (0, _formatString.formatStringToHtml)('[p]paragraph[/p]', {
423
+ parseBBCode: true
424
+ });
425
+ (0, _vitest.expect)(result.html).toEqual('<p><p>paragraph</p></p>');
426
+ (0, _vitest.expect)(result.tables).toEqual([]);
427
+ });
428
+ });
429
+ (0, _vitest.describe)('Custom Elements', () => {
430
+ (0, _vitest.test)('should format custom tags correctly', () => {
431
+ const input = '[custom attribute1="test1" attribute2="test2"]custom[/custom]';
432
+ const output = '<p><bb-code-custom attribute1="test1" attribute2="test2">custom</bb-code-custom></p>';
433
+ const result1 = (0, _formatString.formatStringToHtml)(input, {
434
+ parseBBCode: true,
435
+ customInlineLevelBBCodeTags: ['custom']
436
+ });
437
+ (0, _vitest.expect)(result1.html).toEqual(output);
438
+ (0, _vitest.expect)(result1.tables).toEqual([]);
439
+ const result2 = (0, _formatString.formatStringToHtml)(input, {
440
+ parseBBCode: true,
441
+ customBlockLevelBBCodeTags: ['custom']
442
+ });
443
+ (0, _vitest.expect)(result2.html).toEqual(output);
444
+ (0, _vitest.expect)(result2.tables).toEqual([]);
445
+ });
446
+ (0, _vitest.test)('should not format unknown custom tags', () => {
447
+ const result = (0, _formatString.formatStringToHtml)('[unknown]unknown[/unknown]', {
448
+ parseBBCode: true
449
+ });
450
+ (0, _vitest.expect)(result.html).toEqual('<p>[unknown]unknown[/unknown]</p>');
451
+ (0, _vitest.expect)(result.tables).toEqual([]);
452
+ });
453
+ });
454
+ (0, _vitest.describe)('Line breaks', () => {
455
+ (0, _vitest.describe)('Between Elements', () => {
456
+ (0, _vitest.test)('should format line breaks between block level elements correctly', () => {
457
+ const result1 = (0, _formatString.formatStringToHtml)('[h1]h1[/h1]\n[h2]h2[/h2]', {
458
+ parseBBCode: true
459
+ });
460
+ (0, _vitest.expect)(result1.html).toEqual('<p><h1>h1</h1><h2>h2</h2></p>');
461
+ (0, _vitest.expect)(result1.tables).toEqual([]);
462
+ const result2 = (0, _formatString.formatStringToHtml)('[h1]h1[/h1]\n\n[h2]h2[/h2]', {
463
+ parseBBCode: true
464
+ });
465
+ (0, _vitest.expect)(result2.html).toEqual('<p><h1>h1</h1></p>\n<p><h2>h2</h2></p>');
466
+ (0, _vitest.expect)(result2.tables).toEqual([]);
467
+ });
468
+ (0, _vitest.test)('should format line breaks between inline elements correctly', () => {
469
+ const result1 = (0, _formatString.formatStringToHtml)('[b]bold[/b]\n[i]italic[/i]', {
470
+ parseBBCode: true
471
+ });
472
+ (0, _vitest.expect)(result1.html).toEqual('<p><b>bold</b>\n<i>italic</i></p>');
473
+ (0, _vitest.expect)(result1.tables).toEqual([]);
474
+ const result2 = (0, _formatString.formatStringToHtml)('[b]bold[/b]\n\n[i]italic[/i]', {
475
+ parseBBCode: true
476
+ });
477
+ (0, _vitest.expect)(result2.html).toEqual('<p><b>bold</b></p>\n<p><i>italic</i></p>');
478
+ (0, _vitest.expect)(result2.tables).toEqual([]);
479
+ });
480
+ });
481
+ (0, _vitest.describe)('Within Elements', () => {
482
+ (0, _vitest.test)('should format line breaks within block level elements correctly', () => {
483
+ const result = (0, _formatString.formatStringToHtml)('[h1]Line 1\nLine 2[/h1]', {
484
+ parseBBCode: true
485
+ });
486
+ (0, _vitest.expect)(result.html).toEqual('<p><h1>Line 1\nLine 2</h1></p>');
487
+ (0, _vitest.expect)(result.tables).toEqual([]);
488
+ });
489
+
490
+ // This is a test that would fail!
491
+ // test('should format multiple line breaks within block level elements correctly', () => {
492
+ // const result = formatStringToHtml('[h1]Line 1\n\nLine 2[/h1]', {
493
+ // parseBBCode: true,
494
+ // });
495
+ // expect(result.html).toEqual('<p><h1>Line 1\nLine 2</h1></p>');
496
+ // expect(result.tables).toEqual([]);
497
+ // });
498
+
499
+ (0, _vitest.test)('should remove trailing and leading new lines within block level elements', () => {
500
+ const result = (0, _formatString.formatStringToHtml)('[h1]\n\n\nLine 1\n\n\n[/h1]', {
501
+ parseBBCode: true
502
+ });
503
+ (0, _vitest.expect)(result.html).toEqual('<p><h1>Line 1</h1></p>');
504
+ (0, _vitest.expect)(result.tables).toEqual([]);
505
+ });
506
+ });
507
+ });
508
+ (0, _vitest.test)('should not format url in tag attributes', () => {
509
+ const result = (0, _formatString.formatStringToHtml)('[link url="https://www.google.com"]Google[/link]', {
510
+ parseBBCode: true,
511
+ customInlineLevelBBCodeTags: ['link']
512
+ });
513
+ (0, _vitest.expect)(result.html).toEqual('<p><bb-code-link url="https://www.google.com">Google</bb-code-link></p>');
514
+ (0, _vitest.expect)(result.tables).toEqual([]);
515
+ });
516
+ (0, _vitest.test)('should apply style attribute correctly', () => {
517
+ const result = (0, _formatString.formatStringToHtml)('[span style="color: red;"]red text[/span]', {
518
+ parseBBCode: true
519
+ });
520
+ (0, _vitest.expect)(result.html).toEqual('<p><span style="color: red;">red text</span></p>');
521
+ (0, _vitest.expect)(result.tables).toEqual([]);
522
+ });
523
+ (0, _vitest.test)('should format nested elements correctly', () => {
524
+ const result = (0, _formatString.formatStringToHtml)('[b][i]bold italic[/i][/b]', {
525
+ parseBBCode: true
526
+ });
527
+ (0, _vitest.expect)(result.html).toEqual('<p><b><i>bold italic</i></b></p>');
528
+ (0, _vitest.expect)(result.tables).toEqual([]);
529
+ });
530
+ });
531
+ });
532
+ (0, _vitest.describe)('Combined Formatting (Markdown + BB-Code)', () => {
533
+ (0, _vitest.test)('should format bb-code within markdown correctly', () => {
534
+ const result = (0, _formatString.formatStringToHtml)('*[b]bold[/b]*', {
535
+ parseBBCode: true
536
+ });
537
+ (0, _vitest.expect)(result.html).toEqual('<p><em><b>bold</b></em></p>');
538
+ (0, _vitest.expect)(result.tables).toEqual([]);
539
+ });
540
+ (0, _vitest.test)('should format markdown within bb-code correctly', () => {
541
+ const result = (0, _formatString.formatStringToHtml)('[b]*bold*[/b]', {
542
+ parseBBCode: true
543
+ });
544
+ (0, _vitest.expect)(result.html).toEqual('<p><b><em>bold</em></b></p>');
545
+ (0, _vitest.expect)(result.tables).toEqual([]);
546
+ });
547
+ });
548
+ });
549
+ //# sourceMappingURL=formatString.test.js.map