@chayns-components/format 5.0.0-beta.651 → 5.0.0-beta.682

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 (56) hide show
  1. package/lib/cjs/constants/format.js +8 -0
  2. package/lib/cjs/constants/format.js.map +1 -0
  3. package/lib/cjs/index.js +7 -0
  4. package/lib/cjs/index.js.map +1 -1
  5. package/lib/cjs/types/format.js +2 -0
  6. package/lib/cjs/types/format.js.map +1 -0
  7. package/lib/cjs/utils/escape.js +1 -5
  8. package/lib/cjs/utils/escape.js.map +1 -1
  9. package/lib/cjs/utils/formatString/bb-code/findBBCode.js +6 -4
  10. package/lib/cjs/utils/formatString/bb-code/findBBCode.js.map +1 -1
  11. package/lib/cjs/utils/formatString/bb-code/formatBBCode.js +38 -38
  12. package/lib/cjs/utils/formatString/bb-code/formatBBCode.js.map +1 -1
  13. package/lib/cjs/utils/formatString/formatString.js +30 -42
  14. package/lib/cjs/utils/formatString/formatString.js.map +1 -1
  15. package/lib/cjs/utils/formatString/formatString.test.js +549 -0
  16. package/lib/cjs/utils/formatString/formatString.test.js.map +1 -0
  17. package/lib/cjs/utils/formatString/markdown/formatMarkdown.js +145 -30
  18. package/lib/cjs/utils/formatString/markdown/formatMarkdown.js.map +1 -1
  19. package/lib/esm/constants/format.js +2 -0
  20. package/lib/esm/constants/format.js.map +1 -0
  21. package/lib/esm/index.js +1 -0
  22. package/lib/esm/index.js.map +1 -1
  23. package/lib/esm/types/format.js +2 -0
  24. package/lib/esm/types/format.js.map +1 -0
  25. package/lib/esm/utils/escape.js +0 -3
  26. package/lib/esm/utils/escape.js.map +1 -1
  27. package/lib/esm/utils/formatString/bb-code/findBBCode.js +6 -4
  28. package/lib/esm/utils/formatString/bb-code/findBBCode.js.map +1 -1
  29. package/lib/esm/utils/formatString/bb-code/formatBBCode.js +38 -40
  30. package/lib/esm/utils/formatString/bb-code/formatBBCode.js.map +1 -1
  31. package/lib/esm/utils/formatString/formatString.js +33 -45
  32. package/lib/esm/utils/formatString/formatString.js.map +1 -1
  33. package/lib/esm/utils/formatString/formatString.test.js +547 -0
  34. package/lib/esm/utils/formatString/formatString.test.js.map +1 -0
  35. package/lib/esm/utils/formatString/markdown/formatMarkdown.js +141 -27
  36. package/lib/esm/utils/formatString/markdown/formatMarkdown.js.map +1 -1
  37. package/lib/types/constants/format.d.ts +1 -0
  38. package/lib/types/index.d.ts +2 -0
  39. package/lib/types/types/format.d.ts +5 -0
  40. package/lib/types/utils/escape.d.ts +0 -3
  41. package/lib/types/utils/formatString/bb-code/findBBCode.d.ts +2 -0
  42. package/lib/types/utils/formatString/bb-code/formatBBCode.d.ts +4 -2
  43. package/lib/types/utils/formatString/formatString.d.ts +1 -3
  44. package/lib/types/utils/formatString/formatString.test.d.ts +1 -0
  45. package/lib/types/utils/formatString/markdown/formatMarkdown.d.ts +3 -1
  46. package/package.json +6 -4
  47. package/lib/cjs/utils/formatString/markdown/InternalHTMLRenderer.js +0 -287
  48. package/lib/cjs/utils/formatString/markdown/InternalHTMLRenderer.js.map +0 -1
  49. package/lib/cjs/utils/formatString/markdown/formatMarkdownTable.js +0 -86
  50. package/lib/cjs/utils/formatString/markdown/formatMarkdownTable.js.map +0 -1
  51. package/lib/esm/utils/formatString/markdown/InternalHTMLRenderer.js +0 -278
  52. package/lib/esm/utils/formatString/markdown/InternalHTMLRenderer.js.map +0 -1
  53. package/lib/esm/utils/formatString/markdown/formatMarkdownTable.js +0 -78
  54. package/lib/esm/utils/formatString/markdown/formatMarkdownTable.js.map +0 -1
  55. package/lib/types/utils/formatString/markdown/InternalHTMLRenderer.d.ts +0 -5
  56. package/lib/types/utils/formatString/markdown/formatMarkdownTable.d.ts +0 -9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatString.test.js","names":["describe","expect","test","formatStringToHtml","removeLinebreaks","text","replace","result","html","toEqual","tables","resultEscape","resultEscape1","resultEscape2","boldResult","italicResult","inlineCodeResult","h1Result","h2Result","h3Result","h4Result","h5Result","h6Result","expectedUnorderedListResult","expectedOrderedListResult","unorderedListResult1","unorderedListResult2","orderedListResult","orderedListResult2","expectedThematicBreakResult","result1","result2","resultWithoutLanguage","resultWithLanguage","inputString","csv","raw","id","parseBBCode","table1","getTable1Result","index","table1Csv","table2","getTable2TResult","table2Csv","getHeadingInput","tag","getHeadingOutput","headingTags","forEach","input","output","customInlineLevelBBCodeTags","customBlockLevelBBCodeTags"],"sources":["../../../../src/utils/formatString/formatString.test.ts"],"sourcesContent":["import { describe, expect, test } from 'vitest';\nimport { formatStringToHtml } from './formatString';\n\nconst removeLinebreaks = (text: string) => text.replace(/\\n/g, '');\n\ndescribe('HTML Formatter Function', () => {\n describe('Format Plain Text', () => {\n describe('Line breaks', () => {\n test('should format line breaks correctly', () => {\n const result = formatStringToHtml('Line 1\\nLine 2');\n expect(result.html).toEqual('<p>Line 1\\nLine 2</p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should format multiple line breaks correctly', () => {\n const result = formatStringToHtml('Line 1\\n\\nLine 2');\n expect(result.html).toEqual('<p>Line 1</p>\\n<p>Line 2</p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should remove trailing and leading new lines', () => {\n const result = formatStringToHtml('\\n\\n\\nLine 1\\n\\n\\n');\n expect(result.html).toEqual('<p>Line 1</p>');\n expect(result.tables).toEqual([]);\n });\n });\n\n describe('Whitespaces', () => {\n test('should not remove repeated whitespaces', () => {\n const result = formatStringToHtml('Text with spaces');\n expect(result.html).toEqual('<p>Text with spaces</p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should not remove leading and trailing whitespaces', () => {\n const result = formatStringToHtml(' Text ');\n expect(result.html).toEqual('<p> Text </p>');\n expect(result.tables).toEqual([]);\n });\n });\n\n describe('HTML', () => {\n test('should escape < and > correctly', () => {\n const resultEscape = formatStringToHtml('<div>Test</div>');\n expect(resultEscape.html).toEqual('<p>&lt;div&gt;Test&lt;/div&gt;</p>');\n expect(resultEscape.tables).toEqual([]);\n });\n\n test('should not escape &', () => {\n const resultEscape1 = formatStringToHtml('&lt;div&gt;Test&lt;/div&gt;');\n expect(resultEscape1.html).toEqual('<p>&lt;div&gt;Test&lt;/div&gt;</p>');\n expect(resultEscape1.tables).toEqual([]);\n\n const resultEscape2 = formatStringToHtml(\n '&amp;lt;div&amp;gt;Test&amp;lt;/div&amp;gt;',\n );\n expect(resultEscape2.html).toEqual(\n '<p>&amp;lt;div&amp;gt;Test&amp;lt;/div&amp;gt;</p>',\n );\n expect(resultEscape2.tables).toEqual([]);\n });\n\n // TODO Decide if & should be escaped, when they are not part of an HTML entity.\n });\n\n describe('URLs', () => {\n test('should not format URLs', () => {\n const result = formatStringToHtml('https://example.com');\n expect(result.html).toEqual('<p>https://example.com</p>');\n expect(result.tables).toEqual([]);\n });\n });\n });\n\n describe('Format Markdown', () => {\n describe('All Elements', () => {\n test('should format text styling correctly', () => {\n const boldResult = formatStringToHtml('**bold**');\n expect(boldResult.html).toEqual('<p><strong>bold</strong></p>');\n expect(boldResult.tables).toEqual([]);\n\n const italicResult = formatStringToHtml('*italic*');\n expect(italicResult.html).toEqual('<p><em>italic</em></p>');\n expect(italicResult.tables).toEqual([]);\n\n const inlineCodeResult = formatStringToHtml('`inline code`');\n expect(inlineCodeResult.html).toEqual('<p><code>inline code</code></p>');\n expect(inlineCodeResult.tables).toEqual([]);\n });\n\n test('should format headings correctly', () => {\n const h1Result = formatStringToHtml('# h1');\n expect(h1Result.html).toEqual('<h1>h1</h1>');\n expect(h1Result.tables).toEqual([]);\n\n const h2Result = formatStringToHtml('## h2');\n expect(h2Result.html).toEqual('<h2>h2</h2>');\n expect(h2Result.tables).toEqual([]);\n\n const h3Result = formatStringToHtml('### h3');\n expect(h3Result.html).toEqual('<h3>h3</h3>');\n expect(h3Result.tables).toEqual([]);\n\n const h4Result = formatStringToHtml('#### h4');\n expect(h4Result.html).toEqual('<h4>h4</h4>');\n expect(h4Result.tables).toEqual([]);\n\n const h5Result = formatStringToHtml('##### h5');\n expect(h5Result.html).toEqual('<h5>h5</h5>');\n expect(h5Result.tables).toEqual([]);\n\n const h6Result = formatStringToHtml('###### h6');\n expect(h6Result.html).toEqual('<h6>h6</h6>');\n expect(h6Result.tables).toEqual([]);\n });\n\n test('should format links correctly', () => {\n const result = formatStringToHtml('[Link](https://example.com)');\n expect(result.html).toEqual('<p><a href=\"https://example.com\">Link</a></p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should format images correctly', () => {\n const result = formatStringToHtml('![Alt Text](https://example.com/image.jpg)');\n expect(result.html).toEqual(\n '<p><img src=\"https://example.com/image.jpg\" alt=\"Alt Text\"></p>',\n );\n expect(result.tables).toEqual([]);\n });\n\n test('should format lists correctly', () => {\n const expectedUnorderedListResult =\n '<ul>\\n<li>Item 1</li>\\n<li>Item 2</li>\\n<li>Item 3</li>\\n</ul>';\n const expectedOrderedListResult =\n '<ol>\\n<li>Item 1</li>\\n<li>Item 2</li>\\n<li>Item 3</li>\\n</ol>';\n\n const unorderedListResult1 = formatStringToHtml('- Item 1\\n- Item 2\\n- Item 3');\n expect(unorderedListResult1.html).toEqual(expectedUnorderedListResult);\n expect(unorderedListResult1.tables).toEqual([]);\n\n const unorderedListResult2 = formatStringToHtml('* Item 1\\n* Item 2\\n* Item 3');\n expect(unorderedListResult2.html).toEqual(expectedUnorderedListResult);\n expect(unorderedListResult2.tables).toEqual([]);\n\n const orderedListResult = formatStringToHtml('1. Item 1\\n2. Item 2\\n3. Item 3');\n expect(orderedListResult.html).toEqual(expectedOrderedListResult);\n expect(orderedListResult.tables).toEqual([]);\n\n const orderedListResult2 = formatStringToHtml('1) Item 1\\n2) Item 2\\n3) Item 3');\n expect(orderedListResult2.html).toEqual(expectedOrderedListResult);\n expect(orderedListResult2.tables).toEqual([]);\n });\n\n test('should format thematic breaks correctly', () => {\n const expectedThematicBreakResult = '<hr>';\n\n const result1 = formatStringToHtml('---');\n expect(result1.html).toEqual(expectedThematicBreakResult);\n expect(result1.tables).toEqual([]);\n\n const result2 = formatStringToHtml('***');\n expect(result2.html).toEqual(expectedThematicBreakResult);\n expect(result2.tables).toEqual([]);\n });\n\n test('should format code blocks correctly', () => {\n const resultWithoutLanguage = formatStringToHtml('```\\nconst a = 1;\\n```');\n expect(resultWithoutLanguage.html).toEqual('<pre><code>const a = 1;</code></pre>');\n expect(resultWithoutLanguage.tables).toEqual([]);\n\n const resultWithLanguage = formatStringToHtml('```js\\nconst a = 1;\\n```');\n expect(resultWithLanguage.html).toEqual(\n '<pre><code class=\"language-js\">const a = 1;</code></pre>',\n );\n expect(resultWithLanguage.tables).toEqual([]);\n });\n\n test('should format tables correctly', () => {\n const inputString =\n '| Header 1 | Header 2 |\\n|----------|----------|\\n| Cell 1 | Cell 2 |';\n const result = formatStringToHtml(inputString);\n expect(removeLinebreaks(result.html)).toEqual(\n '<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>',\n );\n expect(result.tables).toEqual([\n {\n csv: 'Header 1,Header 2\\nCell 1,Cell 2\\n',\n raw: inputString,\n id: 'formatted-table-0',\n },\n ]);\n });\n });\n\n describe('Inline Code', () => {\n describe('HTML In Code', () => {\n test('should escape < and > within inline code correctly', () => {\n const result1 = formatStringToHtml('`<div>Test</div>`');\n expect(result1.html).toEqual('<p><code>&lt;div&gt;Test&lt;/div&gt;</code></p>');\n expect(result1.tables).toEqual([]);\n });\n\n test('should not escape & within inline code', () => {\n const resultEscape1 = formatStringToHtml('`&lt;div&gt;Test&lt;/div&gt;`');\n expect(resultEscape1.html).toEqual(\n '<p><code>&lt;div&gt;Test&lt;/div&gt;</code></p>',\n );\n expect(resultEscape1.tables).toEqual([]);\n\n const resultEscape2 = formatStringToHtml(\n '`&amp;lt;div&amp;gt;Test&amp;lt;/div&amp;gt;`',\n );\n expect(resultEscape2.html).toEqual(\n '<p><code>&amp;lt;div&amp;gt;Test&amp;lt;/div&amp;gt;</code></p>',\n );\n expect(resultEscape2.tables).toEqual([]);\n });\n });\n\n test('should not format markdown within inline code', () => {\n const result = formatStringToHtml('`**bold** *italic*`');\n expect(result.html).toEqual('<p><code>**bold** *italic*</code></p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should not format bb-code within inline code', () => {\n const result = formatStringToHtml('`[b]bold[/b]`', { parseBBCode: true });\n expect(result.html).toEqual('<p><code>[b]bold[/b]</code></p>');\n expect(result.tables).toEqual([]);\n });\n });\n\n describe('Codeblock', () => {\n test('should format code blocks with multiple lines correctly', () => {\n const resultWithoutLanguage = formatStringToHtml(\n '```\\nconst a = 1;\\nconst b = 2;\\n```',\n );\n expect(resultWithoutLanguage.html).toEqual(\n '<pre><code>const a = 1;\\nconst b = 2;</code></pre>',\n );\n expect(resultWithoutLanguage.tables).toEqual([]);\n\n const resultWithLanguage = formatStringToHtml(\n '```js\\nconst a = 1;\\nconst b = 2;\\n```',\n );\n expect(resultWithLanguage.html).toEqual(\n '<pre><code class=\"language-js\">const a = 1;\\nconst b = 2;</code></pre>',\n );\n expect(resultWithLanguage.tables).toEqual([]);\n });\n\n describe('HTML In Code', () => {\n test('should escape < and > within code block', () => {\n const resultWithoutLanguage = formatStringToHtml('```\\n<div>Test</div>\\n```');\n expect(resultWithoutLanguage.html).toEqual(\n '<pre><code>&lt;div&gt;Test&lt;/div&gt;</code></pre>',\n );\n expect(resultWithoutLanguage.tables).toEqual([]);\n\n const resultWithLanguage = formatStringToHtml('```html\\n<div>Test</div>\\n```');\n expect(resultWithLanguage.html).toEqual(\n '<pre><code class=\"language-html\">&lt;div&gt;Test&lt;/div&gt;</code></pre>',\n );\n expect(resultWithLanguage.tables).toEqual([]);\n });\n\n test('should not escape & within code block', () => {\n const resultEscape1 = formatStringToHtml(\n '```\\n&lt;div&gt;Test&lt;/div&gt;\\n```',\n );\n expect(resultEscape1.html).toEqual(\n '<pre><code>&lt;div&gt;Test&lt;/div&gt;</code></pre>',\n );\n expect(resultEscape1.tables).toEqual([]);\n\n const resultEscape2 = formatStringToHtml(\n '```\\n&amp;lt;div&amp;gt;Test&amp;lt;/div&amp;gt;\\n```',\n );\n expect(resultEscape2.html).toEqual(\n '<pre><code>&amp;lt;div&amp;gt;Test&amp;lt;/div&amp;gt;</code></pre>',\n );\n expect(resultEscape2.tables).toEqual([]);\n });\n });\n\n test('should not format markdown within code block', () => {\n const resultWithoutLanguage = formatStringToHtml('```\\n**Test**\\n```');\n expect(resultWithoutLanguage.html).toEqual('<pre><code>**Test**</code></pre>');\n expect(resultWithoutLanguage.tables).toEqual([]);\n\n const resultWithLanguage = formatStringToHtml('```html\\n**Test**\\n```');\n expect(resultWithLanguage.html).toEqual(\n '<pre><code class=\"language-html\">**Test**</code></pre>',\n );\n expect(resultWithLanguage.tables).toEqual([]);\n });\n\n test('should not format bb-code within code block', () => {\n const resultWithoutLanguage = formatStringToHtml('```\\n[b]Test[/b]\\n```');\n expect(resultWithoutLanguage.html).toEqual('<pre><code>[b]Test[/b]</code></pre>');\n expect(resultWithoutLanguage.tables).toEqual([]);\n\n const resultWithLanguage = formatStringToHtml('```html\\n[b]Test[/b]\\n```');\n expect(resultWithLanguage.html).toEqual(\n '<pre><code class=\"language-html\">[b]Test[/b]</code></pre>',\n );\n expect(resultWithLanguage.tables).toEqual([]);\n });\n });\n\n describe('Table', () => {\n test('should format markdown within table correctly', () => {\n const inputString =\n '| Header 1 | Header 2 |\\n|----------|----------|\\n| **Cell 1** | *Cell 2* |';\n const result = formatStringToHtml(inputString);\n expect(removeLinebreaks(result.html)).toEqual(\n '<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>',\n );\n expect(result.tables).toEqual([\n {\n csv: 'Header 1,Header 2\\n**Cell 1**,*Cell 2*\\n',\n raw: inputString,\n id: 'formatted-table-0',\n },\n ]);\n });\n\n test('should format bb-code within table correctly', () => {\n const inputString =\n '| Header 1 | Header 2 |\\n|----------|----------|\\n| [b]Cell 1[/b] | [i]Cell 2[/i] |';\n const result = formatStringToHtml(inputString, {\n parseBBCode: true,\n });\n expect(removeLinebreaks(result.html)).toEqual(\n '<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>',\n );\n expect(result.tables).toEqual([\n {\n csv: 'Header 1,Header 2\\n[b]Cell 1[/b],[i]Cell 2[/i]\\n',\n raw: inputString,\n id: 'formatted-table-0',\n },\n ]);\n });\n\n test('should format html within table correctly', () => {\n const inputString =\n '| 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; |';\n const result = formatStringToHtml(inputString, {\n parseBBCode: true,\n });\n expect(removeLinebreaks(result.html)).toEqual(\n '<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>',\n );\n expect(result.tables).toEqual([\n {\n 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',\n 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; |',\n id: 'formatted-table-0',\n },\n ]);\n });\n\n test('should format multiple tables correctly', () => {\n const table1 =\n '| Header 1 | Header 2 |\\n|----------|----------|\\n| Cell 1 | Cell 2 |';\n const getTable1Result = (index: number) =>\n `<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>`;\n const table1Csv = 'Header 1,Header 2\\nCell 1,Cell 2\\n';\n const table2 =\n '| Header 3 | Header 4 |\\n|----------|----------|\\n| Cell 3 | Cell 4 |';\n const getTable2TResult = (index: number) =>\n `<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>`;\n const table2Csv = 'Header 3,Header 4\\nCell 3,Cell 4\\n';\n\n const result1 = formatStringToHtml(`${table1}\\n\\n${table2}`);\n expect(removeLinebreaks(result1.html)).toEqual(\n `${getTable1Result(0)}${getTable2TResult(1)}`,\n );\n expect(result1.tables).toEqual([\n {\n csv: table1Csv,\n raw: `${table1}\\n\\n`,\n id: 'formatted-table-0',\n },\n {\n csv: table2Csv,\n raw: table2,\n id: 'formatted-table-1',\n },\n ]);\n\n // Tables in reverse order.\n const result2 = formatStringToHtml(`${table2}\\n\\n${table1}`);\n expect(removeLinebreaks(result2.html)).toEqual(\n `${getTable2TResult(0)}${getTable1Result(1)}`,\n );\n expect(result2.tables).toEqual([\n {\n csv: table2Csv,\n raw: `${table2}\\n\\n`,\n id: 'formatted-table-0',\n },\n {\n csv: table1Csv,\n raw: table1,\n id: 'formatted-table-1',\n },\n ]);\n });\n });\n\n describe('List', () => {\n test('should format markdown within list correctly', () => {\n const result = formatStringToHtml('- **Item 1**\\n- *Item 2*');\n expect(removeLinebreaks(result.html)).toEqual(\n '<ul><li><strong>Item 1</strong></li><li><em>Item 2</em></li></ul>',\n );\n expect(result.tables).toEqual([]);\n });\n\n test('should format task lists correctly', () => {\n const result1 = formatStringToHtml('- [ ] 1\\n- [x] 2\\n- [X] 3');\n expect(removeLinebreaks(result1.html)).toEqual(\n '<ul><li>[ ] 1</li><li>[x] 2</li><li>[x] 3</li></ul>',\n );\n expect(result1.tables).toEqual([]);\n });\n });\n\n describe('Combined Elements', () => {\n test('should format code block within list correctly', () => {\n const result = formatStringToHtml('* test\\n ```\\n test\\n ```');\n expect(removeLinebreaks(result.html)).toEqual(\n '<ul><li>test<pre><code>test</code></pre></li></ul>',\n );\n expect(result.tables).toEqual([]);\n });\n });\n\n describe('Conflicts with BB-Code', () => {\n test('should not format bb code tag followed by paranthese to link', () => {\n const result = formatStringToHtml('[b]bold[/b](test)', { parseBBCode: true });\n expect(result.html).toEqual('<p><b>bold</b>(test)</p>');\n expect(result.tables).toEqual([]);\n });\n });\n });\n\n describe('Format BB-Code', () => {\n describe('All Elements', () => {\n describe('Inline Elements', () => {\n // b, strong, i, em, u, s, span, img\n test('should format b tag correctly', () => {\n const result = formatStringToHtml('[b]bold[/b]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><b>bold</b></p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should format strong tag correctly', () => {\n const result = formatStringToHtml('[strong]bold[/strong]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><strong>bold</strong></p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should format i tag correctly', () => {\n const result = formatStringToHtml('[i]italic[/i]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><i>italic</i></p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should format em tag correctly', () => {\n const result = formatStringToHtml('[em]italic[/em]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><em>italic</em></p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should format u tag correctly', () => {\n const result = formatStringToHtml('[u]underline[/u]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><u>underline</u></p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should format s tag correctly', () => {\n const result = formatStringToHtml('[s]strike[/s]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><s>strike</s></p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should format span tag correctly', () => {\n const result = formatStringToHtml('[span]span[/span]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><span>span</span></p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should format img tag correctly', () => {\n const result = formatStringToHtml(\n '[img src=\"https://example.com/image.jpg\"][/img]',\n {\n parseBBCode: true,\n },\n );\n expect(result.html).toEqual('<p><img src=\"https://example.com/image.jpg\"></p>');\n expect(result.tables).toEqual([]);\n });\n });\n\n describe('Block Level Elements', () => {\n test('should format center tag correctly', () => {\n const result = formatStringToHtml('[center]centered text[/center]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><center>centered text</center></p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should format ul tag correctly', () => {\n const result = formatStringToHtml('[ul][li]Item 1[/li][li]Item 2[/li][/ul]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><ul><li>Item 1</li><li>Item 2</li></ul></p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should format ol tag correctly', () => {\n const result = formatStringToHtml('[ol][li]Item 1[/li][li]Item 2[/li][/ol]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><ol><li>Item 1</li><li>Item 2</li></ol></p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should format li tag correctly', () => {\n const result = formatStringToHtml('[li]Item[/li]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><li>Item</li></p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should format heading tags correctly', () => {\n const getHeadingInput = (tag: string) => `[${tag}]${tag}[/${tag}]`;\n const getHeadingOutput = (tag: string) => `<p><${tag}>${tag}</${tag}></p>`;\n const headingTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];\n\n headingTags.forEach((tag) => {\n const result = formatStringToHtml(getHeadingInput(tag), {\n parseBBCode: true,\n });\n expect(result.html).toEqual(getHeadingOutput(tag));\n expect(result.tables).toEqual([]);\n });\n });\n\n test('should format p tag correctly', () => {\n const result = formatStringToHtml('[p]paragraph[/p]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><p>paragraph</p></p>');\n expect(result.tables).toEqual([]);\n });\n });\n\n describe('Custom Elements', () => {\n test('should format custom tags correctly', () => {\n const input = '[custom attribute1=\"test1\" attribute2=\"test2\"]custom[/custom]';\n const output =\n '<p><bb-code-custom attribute1=\"test1\" attribute2=\"test2\">custom</bb-code-custom></p>';\n const result1 = formatStringToHtml(input, {\n parseBBCode: true,\n customInlineLevelBBCodeTags: ['custom'],\n });\n expect(result1.html).toEqual(output);\n expect(result1.tables).toEqual([]);\n\n const result2 = formatStringToHtml(input, {\n parseBBCode: true,\n customBlockLevelBBCodeTags: ['custom'],\n });\n expect(result2.html).toEqual(output);\n expect(result2.tables).toEqual([]);\n });\n\n test('should not format unknown custom tags', () => {\n const result = formatStringToHtml('[unknown]unknown[/unknown]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p>[unknown]unknown[/unknown]</p>');\n expect(result.tables).toEqual([]);\n });\n });\n\n describe('Line breaks', () => {\n describe('Between Elements', () => {\n test('should format line breaks between block level elements correctly', () => {\n const result1 = formatStringToHtml('[h1]h1[/h1]\\n[h2]h2[/h2]', {\n parseBBCode: true,\n });\n expect(result1.html).toEqual('<p><h1>h1</h1><h2>h2</h2></p>');\n expect(result1.tables).toEqual([]);\n\n const result2 = formatStringToHtml('[h1]h1[/h1]\\n\\n[h2]h2[/h2]', {\n parseBBCode: true,\n });\n expect(result2.html).toEqual('<p><h1>h1</h1></p>\\n<p><h2>h2</h2></p>');\n expect(result2.tables).toEqual([]);\n });\n\n test('should format line breaks between inline elements correctly', () => {\n const result1 = formatStringToHtml('[b]bold[/b]\\n[i]italic[/i]', {\n parseBBCode: true,\n });\n expect(result1.html).toEqual('<p><b>bold</b>\\n<i>italic</i></p>');\n expect(result1.tables).toEqual([]);\n\n const result2 = formatStringToHtml('[b]bold[/b]\\n\\n[i]italic[/i]', {\n parseBBCode: true,\n });\n expect(result2.html).toEqual('<p><b>bold</b></p>\\n<p><i>italic</i></p>');\n expect(result2.tables).toEqual([]);\n });\n });\n\n describe('Within Elements', () => {\n test('should format line breaks within block level elements correctly', () => {\n const result = formatStringToHtml('[h1]Line 1\\nLine 2[/h1]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><h1>Line 1\\nLine 2</h1></p>');\n expect(result.tables).toEqual([]);\n });\n\n // This is a test that would fail!\n // test('should format multiple line breaks within block level elements correctly', () => {\n // const result = formatStringToHtml('[h1]Line 1\\n\\nLine 2[/h1]', {\n // parseBBCode: true,\n // });\n // expect(result.html).toEqual('<p><h1>Line 1\\nLine 2</h1></p>');\n // expect(result.tables).toEqual([]);\n // });\n\n test('should remove trailing and leading new lines within block level elements', () => {\n const result = formatStringToHtml('[h1]\\n\\n\\nLine 1\\n\\n\\n[/h1]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><h1>Line 1</h1></p>');\n expect(result.tables).toEqual([]);\n });\n });\n });\n\n test('should not format url in tag attributes', () => {\n const result = formatStringToHtml(\n '[link url=\"https://www.google.com\"]Google[/link]',\n {\n parseBBCode: true,\n customInlineLevelBBCodeTags: ['link'],\n },\n );\n expect(result.html).toEqual(\n '<p><bb-code-link url=\"https://www.google.com\">Google</bb-code-link></p>',\n );\n expect(result.tables).toEqual([]);\n });\n\n test('should apply style attribute correctly', () => {\n const result = formatStringToHtml('[span style=\"color: red;\"]red text[/span]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><span style=\"color: red;\">red text</span></p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should format nested elements correctly', () => {\n const result = formatStringToHtml('[b][i]bold italic[/i][/b]', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><b><i>bold italic</i></b></p>');\n expect(result.tables).toEqual([]);\n });\n });\n });\n\n describe('Combined Formatting (Markdown + BB-Code)', () => {\n test('should format bb-code within markdown correctly', () => {\n const result = formatStringToHtml('*[b]bold[/b]*', {\n parseBBCode: true,\n });\n expect(result.html).toEqual('<p><em><b>bold</b></em></p>');\n expect(result.tables).toEqual([]);\n });\n\n test('should format markdown within bb-code correctly', () => {\n const result = formatStringToHtml('[b]*bold*[/b]', {\n parseB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AW,EAAE;QACjB,CAAC,CAAC;QACFrC,MAAM,CAACM,MAAM,CAACC,IAAI,CAAC,CAACC,OAAO,CAAC,kCAAkC,CAAC;QAC/DR,MAAM,CAACM,MAAM,CAACG,MAAM,CAAC,CAACD,OAAO,CAAC,EAAE,CAAC;MACrC,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,CAAC;EAEFT,QAAQ,CAAC,0CAA0C,EAAE,MAAM;IACvDE,IAAI,CAAC,iDAAiD,EAAE,MAAM;MAC1D,MAAMK,MAAM,GAAGJ,kBAAkB,CAAC,eAAe,EAAE;QAC/CmC,WAAW,EAAE;MACjB,CAAC,CAAC;MACFrC,MAAM,CAACM,MAAM,CAACC,IAAI,CAAC,CAACC,OAAO,CAAC,6BAA6B,CAAC;MAC1DR,MAAM,CAACM,MAAM,CAACG,MAAM,CAAC,CAACD,OAAO,CAAC,EAAE,CAAC;IACrC,CAAC,CAAC;IAEFP,IAAI,CAAC,iDAAiD,EAAE,MAAM;MAC1D,MAAMK,MAAM,GAAGJ,kBAAkB,CAAC,eAAe,EAAE;QAC/CmC,WAAW,EAAE;MACjB,CAAC,CAAC;MACFrC,MAAM,CAACM,MAAM,CAACC,IAAI,CAAC,CAACC,OAAO,CAAC,6BAA6B,CAAC;MAC1DR,MAAM,CAACM,MAAM,CAACG,MAAM,CAAC,CAACD,OAAO,CAAC,EAAE,CAAC;IACrC,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
@@ -1,33 +1,147 @@
1
- import { Parser } from 'commonmark';
2
- import { escapeHtmlInText, MESSAGE_CONVERSION_LINE_BREAK, MESSAGE_CONVERSION_LINE_BREAK_ESCAPED } from '../../escape';
3
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4
- // @ts-ignore
5
- import InternalHTMLRenderer from './InternalHTMLRenderer';
6
- export const parseMarkdown = text => {
7
- let newText = text;
1
+ import { marked } from 'marked';
2
+ // eslint-disable-next-line import/extensions,import/no-unresolved
3
+ import { stringify } from 'csv-stringify/browser/esm/sync';
4
+ import { escapeBBCodeSquareBrackets } from '../bb-code/formatBBCode';
5
+ const inlineCodeRule = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
6
+ const inlineTextRule = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<![`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
7
+ const TABLE_ID_PREFIX = 'formatted-table-';
8
+
9
+ /*
10
+ The marked Pipeline, including tokenizer, renderer and hooks are explained here:
11
+ https://marked.js.org/using_pro
12
+ */
8
13
 
9
- // Markdown has its own line break handling. For that reason, we need to replace line breaks with a custom element.
10
- // In this case I chose a custom <br> Tag.
11
- // Since commonmark doesn't parse markdown in lines with html, the custom <br> Tag needs to be in its own line.
12
- // Since there are issues, when the <br> Tag + \n is followed by text, there needs to be a second line break.
13
- // Thus, we replace \n with \n<br>\n\n.
14
- newText = newText.replaceAll(/\n/gm, `\n${MESSAGE_CONVERSION_LINE_BREAK}\n\n`);
15
- const commonmarkParser = new Parser();
16
- // TODO Check if esc needs to be passed to InternalHTMLRenderer.
17
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
18
- // @ts-ignore
19
- const internalHTMLRenderer = new InternalHTMLRenderer({
20
- esc: escapeHtmlInText
14
+ const tokenizer = {
15
+ // Codespan Tokenizer is overwritten to prevent html escaping, since html is already escaped.
16
+ // The function is copied from marked.js and slightly modified: https://github.com/markedjs/marked/blob/42954aaba960b6f815b24ec0d39da464960e4ec9/src/Tokenizer.ts#L749
17
+ codespan(src) {
18
+ const cap = inlineCodeRule.exec(src);
19
+ if (cap) {
20
+ let text = cap[2].replace(/\n/g, ' ');
21
+ const hasNonSpaceChars = /[^ ]/.test(text);
22
+ const hasSpaceCharsOnBothEnds = /^ /.test(text) && / $/.test(text);
23
+ if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
24
+ text = text.substring(1, text.length - 1);
25
+ }
26
+ return {
27
+ type: 'codespan',
28
+ raw: cap[0],
29
+ text
30
+ };
31
+ }
32
+ return undefined;
33
+ },
34
+ lheading() {
35
+ return undefined;
36
+ },
37
+ url() {
38
+ return undefined;
39
+ },
40
+ // inlineText is overwritten to prevent html escaping, specifically since quote characters are escaped, which breaks the attributes of bb-code elements.
41
+ // The function is copied from marked.js and slightly modified: https://github.com/markedjs/marked/blob/42954aaba960b6f815b24ec0d39da464960e4ec9/src/Tokenizer.ts#L854
42
+ inlineText(src) {
43
+ const cap = inlineTextRule.exec(src);
44
+ if (cap) {
45
+ return {
46
+ type: 'text',
47
+ raw: cap[0],
48
+ text: cap[0]
49
+ };
50
+ }
51
+ return undefined;
52
+ }
53
+ };
54
+ const renderer = {
55
+ // Code Renderer is overwritten to prevent html escaping, since html is already escaped.
56
+ // The function is copied from marked.js and slightly modified: https://github.com/markedjs/marked/blob/42954aaba960b6f815b24ec0d39da464960e4ec9/src/Renderer.ts#L24
57
+ code(text, lang) {
58
+ const langString = (lang || '').match(/^\S*/)?.[0];
59
+ const code = `${text.replace(/\n$/, '')}`;
60
+ if (!langString) {
61
+ return `<pre><code>${code}</code></pre>\n`;
62
+ }
63
+ return `<pre><code class="language-${langString}">${code}</code></pre>\n`;
64
+ },
65
+ // Replaces the checkbox input elements with markdown checkboxes.
66
+ // This is the easiest way to prevent the formatting of markdown checkboxes in lists.
67
+ // This can modify the input string slightly, since the capitalization of the checkbox can be lost.
68
+ // If a user types '- [X]' it will be replaced with '- [x]' => the capitalization is lost.
69
+ checkbox(_ref) {
70
+ let {
71
+ checked
72
+ } = _ref;
73
+ return checked ? '[x]' : '[ ]';
74
+ }
75
+ };
76
+ const postprocess = html => {
77
+ let tableIndex = 0;
78
+ // Assigns ids to tables.
79
+ const modifiedString = html.replace(/(<table>)/g, () => {
80
+ const result = `<table id="${TABLE_ID_PREFIX}${tableIndex}">`;
81
+ tableIndex++;
82
+ return result;
21
83
  });
84
+ return modifiedString;
85
+ };
22
86
 
23
- // Converts markdown to HTML.
24
- const parsedText = commonmarkParser.parse(newText);
25
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
26
- newText = internalHTMLRenderer.render(parsedText);
87
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
88
+ // @ts-ignore
89
+ marked.use({
90
+ tokenizer,
91
+ renderer,
92
+ hooks: {
93
+ postprocess
94
+ }
95
+ });
96
+
97
+ // Parses markdown following the Github Flavored Markdown specification.
98
+ // The tokenizer and renderer are slightly modified to prevent html escaping in code block and inline code.
99
+ export const parseMarkdown = (text, parseBBCode) => marked.parse(text, {
100
+ walkTokens: token => {
101
+ if (parseBBCode && (token.type === 'codespan' || token.type === 'code')) {
102
+ // eslint-disable-next-line no-param-reassign
103
+ token.text = escapeBBCodeSquareBrackets(token.text);
104
+ }
105
+ }
106
+ });
27
107
 
28
- // The Linebreak handling of markdown is ignored, by removing \n. Then the custom <br> Tags are converted back to \n.
29
- newText = newText.replaceAll(/\n/gm, '');
30
- newText = newText.replaceAll(MESSAGE_CONVERSION_LINE_BREAK, '\n').replaceAll(MESSAGE_CONVERSION_LINE_BREAK_ESCAPED, '\n');
31
- return newText;
108
+ // It is important that, &amp; is replaced lastly to prevent double escaping.
109
+ const unescapeHtml = text => text.replaceAll('&lt;', '<').replaceAll('&gt;', '>').replaceAll('&amp;', '&');
110
+ export const getMarkdownTables = text => {
111
+ const tableTokens = [];
112
+ marked.parse(text, {
113
+ walkTokens: token => {
114
+ if (token.type === 'table') {
115
+ tableTokens.push(token);
116
+ }
117
+ }
118
+ });
119
+ const tables = [];
120
+ tableTokens.forEach((tableToken, index) => {
121
+ const tableArray = [];
122
+ if (tableToken.header?.length > 0) {
123
+ const rowArray = [];
124
+ tableToken.header.forEach(header => {
125
+ rowArray.push(unescapeHtml(header.text));
126
+ });
127
+ tableArray.push(rowArray);
128
+ }
129
+ if (tableToken.rows?.length > 0) {
130
+ tableToken.rows.forEach(row => {
131
+ const rowArray = [];
132
+ row.forEach(cell => {
133
+ rowArray.push(unescapeHtml(cell.text));
134
+ });
135
+ tableArray.push(rowArray);
136
+ });
137
+ }
138
+ const csv = stringify(tableArray || []);
139
+ tables.push({
140
+ raw: unescapeHtml(tableToken.raw),
141
+ csv,
142
+ id: `${TABLE_ID_PREFIX}${index}`
143
+ });
144
+ });
145
+ return tables;
32
146
  };
33
147
  //# sourceMappingURL=formatMarkdown.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"formatMarkdown.js","names":["Parser","escapeHtmlInText","MESSAGE_CONVERSION_LINE_BREAK","MESSAGE_CONVERSION_LINE_BREAK_ESCAPED","InternalHTMLRenderer","parseMarkdown","text","newText","replaceAll","commonmarkParser","internalHTMLRenderer","esc","parsedText","parse","render"],"sources":["../../../../../src/utils/formatString/markdown/formatMarkdown.ts"],"sourcesContent":["import { Parser } from 'commonmark';\nimport {\n escapeHtmlInText,\n MESSAGE_CONVERSION_LINE_BREAK,\n MESSAGE_CONVERSION_LINE_BREAK_ESCAPED,\n} from '../../escape';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport InternalHTMLRenderer from './InternalHTMLRenderer';\n\nexport const parseMarkdown = (text: string) => {\n let newText = text;\n\n // Markdown has its own line break handling. For that reason, we need to replace line breaks with a custom element.\n // In this case I chose a custom <br> Tag.\n // Since commonmark doesn't parse markdown in lines with html, the custom <br> Tag needs to be in its own line.\n // Since there are issues, when the <br> Tag + \\n is followed by text, there needs to be a second line break.\n // Thus, we replace \\n with \\n<br>\\n\\n.\n newText = newText.replaceAll(/\\n/gm, `\\n${MESSAGE_CONVERSION_LINE_BREAK}\\n\\n`);\n\n const commonmarkParser = new Parser();\n // TODO Check if esc needs to be passed to InternalHTMLRenderer.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call\n // @ts-ignore\n const internalHTMLRenderer = new InternalHTMLRenderer({ esc: escapeHtmlInText });\n\n // Converts markdown to HTML.\n const parsedText = commonmarkParser.parse(newText);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n newText = internalHTMLRenderer.render(parsedText) as string;\n\n // The Linebreak handling of markdown is ignored, by removing \\n. Then the custom <br> Tags are converted back to \\n.\n newText = newText.replaceAll(/\\n/gm, '');\n newText = newText\n .replaceAll(MESSAGE_CONVERSION_LINE_BREAK, '\\n')\n .replaceAll(MESSAGE_CONVERSION_LINE_BREAK_ESCAPED, '\\n');\n\n return newText;\n};\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,YAAY;AACnC,SACIC,gBAAgB,EAChBC,6BAA6B,EAC7BC,qCAAqC,QAClC,cAAc;AACrB;AACA;AACA,OAAOC,oBAAoB,MAAM,wBAAwB;AAEzD,OAAO,MAAMC,aAAa,GAAIC,IAAY,IAAK;EAC3C,IAAIC,OAAO,GAAGD,IAAI;;EAElB;EACA;EACA;EACA;EACA;EACAC,OAAO,GAAGA,OAAO,CAACC,UAAU,CAAC,MAAM,EAAE,KAAKN,6BAA6B,MAAM,CAAC;EAE9E,MAAMO,gBAAgB,GAAG,IAAIT,MAAM,CAAC,CAAC;EACrC;EACA;EACA;EACA,MAAMU,oBAAoB,GAAG,IAAIN,oBAAoB,CAAC;IAAEO,GAAG,EAAEV;EAAiB,CAAC,CAAC;;EAEhF;EACA,MAAMW,UAAU,GAAGH,gBAAgB,CAACI,KAAK,CAACN,OAAO,CAAC;EAClD;EACAA,OAAO,GAAGG,oBAAoB,CAACI,MAAM,CAACF,UAAU,CAAW;;EAE3D;EACAL,OAAO,GAAGA,OAAO,CAACC,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC;EACxCD,OAAO,GAAGA,OAAO,CACZC,UAAU,CAACN,6BAA6B,EAAE,IAAI,CAAC,CAC/CM,UAAU,CAACL,qCAAqC,EAAE,IAAI,CAAC;EAE5D,OAAOI,OAAO;AAClB,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"formatMarkdown.js","names":["marked","stringify","escapeBBCodeSquareBrackets","inlineCodeRule","inlineTextRule","TABLE_ID_PREFIX","tokenizer","codespan","src","cap","exec","text","replace","hasNonSpaceChars","test","hasSpaceCharsOnBothEnds","substring","length","type","raw","undefined","lheading","url","inlineText","renderer","code","lang","langString","match","checkbox","_ref","checked","postprocess","html","tableIndex","modifiedString","result","use","hooks","parseMarkdown","parseBBCode","parse","walkTokens","token","unescapeHtml","replaceAll","getMarkdownTables","tableTokens","push","tables","forEach","tableToken","index","tableArray","header","rowArray","rows","row","cell","csv","id"],"sources":["../../../../../src/utils/formatString/markdown/formatMarkdown.ts"],"sourcesContent":["import { marked, Tokens } from 'marked';\nimport type { TableObject } from '../../../types/format';\n// eslint-disable-next-line import/extensions,import/no-unresolved\nimport { stringify } from 'csv-stringify/browser/esm/sync';\nimport { escapeBBCodeSquareBrackets } from '../bb-code/formatBBCode';\n\nconst inlineCodeRule = /^(`+)([^`]|[^`][\\s\\S]*?[^`])\\1(?!`)/;\nconst inlineTextRule = /^(`+|[^`])(?:(?= {2,}\\n)|[\\s\\S]*?(?:(?=[\\\\<![`*_]|\\b_|$)|[^ ](?= {2,}\\n)))/;\n\nconst TABLE_ID_PREFIX = 'formatted-table-';\n\n/*\n The marked Pipeline, including tokenizer, renderer and hooks are explained here:\n https://marked.js.org/using_pro\n*/\n\nconst tokenizer = {\n // Codespan Tokenizer is overwritten to prevent html escaping, since html is already escaped.\n // The function is copied from marked.js and slightly modified: https://github.com/markedjs/marked/blob/42954aaba960b6f815b24ec0d39da464960e4ec9/src/Tokenizer.ts#L749\n codespan(src: string): Tokens.Codespan | undefined {\n const cap = inlineCodeRule.exec(src);\n if (cap) {\n let text = (cap[2] as string).replace(/\\n/g, ' ');\n const hasNonSpaceChars = /[^ ]/.test(text);\n const hasSpaceCharsOnBothEnds = /^ /.test(text) && / $/.test(text);\n if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {\n text = text.substring(1, text.length - 1);\n }\n\n return {\n type: 'codespan',\n raw: cap[0],\n text,\n };\n }\n\n return undefined;\n },\n lheading(): Tokens.Heading | undefined {\n return undefined;\n },\n url() {\n return undefined;\n },\n // inlineText is overwritten to prevent html escaping, specifically since quote characters are escaped, which breaks the attributes of bb-code elements.\n // The function is copied from marked.js and slightly modified: https://github.com/markedjs/marked/blob/42954aaba960b6f815b24ec0d39da464960e4ec9/src/Tokenizer.ts#L854\n inlineText(src: string) {\n const cap = inlineTextRule.exec(src);\n if (cap) {\n return {\n type: 'text',\n raw: cap[0],\n text: cap[0],\n };\n }\n return undefined;\n },\n};\n\nconst renderer = {\n // Code Renderer is overwritten to prevent html escaping, since html is already escaped.\n // The function is copied from marked.js and slightly modified: https://github.com/markedjs/marked/blob/42954aaba960b6f815b24ec0d39da464960e4ec9/src/Renderer.ts#L24\n code(text: string, lang: string): string {\n const langString = (lang || '').match(/^\\S*/)?.[0];\n\n const code = `${text.replace(/\\n$/, '')}`;\n\n if (!langString) {\n return `<pre><code>${code}</code></pre>\\n`;\n }\n\n return `<pre><code class=\"language-${langString}\">${code}</code></pre>\\n`;\n },\n // Replaces the checkbox input elements with markdown checkboxes.\n // This is the easiest way to prevent the formatting of markdown checkboxes in lists.\n // This can modify the input string slightly, since the capitalization of the checkbox can be lost.\n // If a user types '- [X]' it will be replaced with '- [x]' => the capitalization is lost.\n checkbox({ checked }: Tokens.Checkbox) {\n return checked ? '[x]' : '[ ]';\n },\n};\n\nconst postprocess = (html: string): string => {\n let tableIndex = 0;\n // Assigns ids to tables.\n const modifiedString = html.replace(/(<table>)/g, () => {\n const result = `<table id=\"${TABLE_ID_PREFIX}${tableIndex}\">`;\n tableIndex++;\n return result;\n });\n\n return modifiedString;\n};\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nmarked.use({ tokenizer, renderer, hooks: { postprocess } });\n\n// Parses markdown following the Github Flavored Markdown specification.\n// The tokenizer and renderer are slightly modified to prevent html escaping in code block and inline code.\nexport const parseMarkdown = (text: string, parseBBCode: boolean) =>\n marked.parse(text, {\n walkTokens: (token) => {\n if (parseBBCode && (token.type === 'codespan' || token.type === 'code')) {\n // eslint-disable-next-line no-param-reassign\n (token as Tokens.Codespan).text = escapeBBCodeSquareBrackets(\n (token as Tokens.Codespan).text,\n );\n }\n },\n }) as string;\n\n// It is important that, &amp; is replaced lastly to prevent double escaping.\nconst unescapeHtml = (text: string) =>\n text.replaceAll('&lt;', '<').replaceAll('&gt;', '>').replaceAll('&amp;', '&');\n\nexport const getMarkdownTables = (text: string): TableObject[] => {\n const tableTokens: Tokens.Table[] = [];\n\n marked.parse(text, {\n walkTokens: (token) => {\n if (token.type === 'table') {\n tableTokens.push(token as Tokens.Table);\n }\n },\n }) as string;\n\n const tables: TableObject[] = [];\n\n tableTokens.forEach((tableToken, index) => {\n const tableArray: string[][] = [];\n\n if (tableToken.header?.length > 0) {\n const rowArray: string[] = [];\n\n tableToken.header.forEach((header) => {\n rowArray.push(unescapeHtml(header.text));\n });\n\n tableArray.push(rowArray);\n }\n if (tableToken.rows?.length > 0) {\n tableToken.rows.forEach((row) => {\n const rowArray: string[] = [];\n\n row.forEach((cell) => {\n rowArray.push(unescapeHtml(cell.text));\n });\n\n tableArray.push(rowArray);\n });\n }\n\n const csv = stringify(tableArray || []);\n\n tables.push({\n raw: unescapeHtml(tableToken.raw),\n csv,\n id: `${TABLE_ID_PREFIX}${index}`,\n });\n });\n\n return tables;\n};\n"],"mappings":"AAAA,SAASA,MAAM,QAAgB,QAAQ;AAEvC;AACA,SAASC,SAAS,QAAQ,gCAAgC;AAC1D,SAASC,0BAA0B,QAAQ,yBAAyB;AAEpE,MAAMC,cAAc,GAAG,qCAAqC;AAC5D,MAAMC,cAAc,GAAG,4EAA4E;AAEnG,MAAMC,eAAe,GAAG,kBAAkB;;AAE1C;AACA;AACA;AACA;;AAEA,MAAMC,SAAS,GAAG;EACd;EACA;EACAC,QAAQA,CAACC,GAAW,EAA+B;IAC/C,MAAMC,GAAG,GAAGN,cAAc,CAACO,IAAI,CAACF,GAA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AC;IAEvCJ,MAAM,CAACD,IAAI,CAAC;MACR7B,GAAG,EAAEyB,YAAY,CAACO,UAAU,CAAChC,GAAG,CAAC;MACjCwC,GAAG;MACHC,EAAE,EAAE,GAAGvD,eAAe,GAAG+C,KAAK;IAClC,CAAC,CAAC;EACN,CAAC,CAAC;EAEF,OAAOH,MAAM;AACjB,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export declare const BB_CODE_HTML_TAG_PREFIX = "bb-code-";
@@ -1 +1,3 @@
1
+ export { BB_CODE_HTML_TAG_PREFIX } from './constants/format';
2
+ export type { TableObject } from './types/format';
1
3
  export { formatStringToHtml } from './utils/formatString/formatString';
@@ -0,0 +1,5 @@
1
+ export type TableObject = {
2
+ raw: string;
3
+ csv: string;
4
+ id: string;
5
+ };
@@ -1,4 +1 @@
1
1
  export declare const escapeHtmlInText: (text: string) => string;
2
- export declare const unescapeSquareBrackets: (text: string) => string;
3
- export declare const MESSAGE_CONVERSION_LINE_BREAK = "<br is-replaced-linebreak>";
4
- export declare const MESSAGE_CONVERSION_LINE_BREAK_ESCAPED: string;
@@ -4,5 +4,7 @@ export interface BBCodeMatch {
4
4
  parameters: Record<string, string>;
5
5
  content: string;
6
6
  index: number;
7
+ openingTag: string;
8
+ closingTag: string;
7
9
  }
8
10
  export declare function findFirstBBCode(inputString: string): BBCodeMatch | null;
@@ -2,8 +2,10 @@ export interface ParseBBCodesOptions {
2
2
  customBlockLevelBBCodeTags?: string[];
3
3
  customInlineLevelBBCodeTags?: string[];
4
4
  }
5
- interface PrivateParseBBCodesOptions extends ParseBBCodesOptions {
5
+ interface ParseBBCodePrivateOptions extends ParseBBCodesOptions {
6
6
  justEscapeSquareBrackets?: boolean;
7
7
  }
8
- export declare const parseBBCode: (text: string, options?: PrivateParseBBCodesOptions) => string;
8
+ export declare const parseBBCode: (text: string, options?: ParseBBCodePrivateOptions) => string;
9
+ export declare const escapeBBCodeSquareBrackets: (text: string) => string;
10
+ export declare const unescapeBBCodeSquareBrackets: (text: string) => string;
9
11
  export {};
@@ -1,9 +1,7 @@
1
+ import type { TableObject } from '../../types/format';
1
2
  import { ParseBBCodesOptions } from './bb-code/formatBBCode';
2
- import { TableObject } from './markdown/formatMarkdownTable';
3
3
  interface FormatStringOptions extends ParseBBCodesOptions {
4
- escapeHtml?: boolean;
5
4
  parseMarkdown?: boolean;
6
- parseMarkdownTables?: boolean;
7
5
  parseBBCode?: boolean;
8
6
  }
9
7
  interface FormatStringResult {
@@ -1 +1,3 @@
1
- export declare const parseMarkdown: (text: string) => string;
1
+ import type { TableObject } from '../../../types/format';
2
+ export declare const parseMarkdown: (text: string, parseBBCode: boolean) => string;
3
+ export declare const getMarkdownTables: (text: string) => TableObject[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chayns-components/format",
3
- "version": "5.0.0-beta.651",
3
+ "version": "5.0.0-beta.682",
4
4
  "description": "A set of beautiful React components for developing your own applications with chayns.",
5
5
  "sideEffects": false,
6
6
  "browserslist": [
@@ -43,7 +43,8 @@
43
43
  "build:types": "tsc",
44
44
  "build:cjs": "cross-env NODE_ENV=cjs babel src --out-dir lib/cjs --extensions=.ts,.tsx --source-maps --ignore=src/stories",
45
45
  "build:esm": "cross-env NODE_ENV=esm babel src --out-dir lib/esm --extensions=.ts,.tsx --source-maps --ignore=src/stories",
46
- "prepublishOnly": "npm run build"
46
+ "prepublishOnly": "npm run build",
47
+ "test": "vitest"
47
48
  },
48
49
  "bugs": {
49
50
  "url": "https://github.com/TobitSoftware/chayns-components/issues"
@@ -59,7 +60,8 @@
59
60
  "babel-loader": "^9.1.3",
60
61
  "cross-env": "^7.0.3",
61
62
  "lerna": "^8.1.3",
62
- "typescript": "^5.4.5"
63
+ "typescript": "^5.4.5",
64
+ "vitest": "^1.6.0"
63
65
  },
64
66
  "dependencies": {
65
67
  "commonmark": "^0.31.0",
@@ -69,5 +71,5 @@
69
71
  "publishConfig": {
70
72
  "access": "public"
71
73
  },
72
- "gitHead": "4ed5eefd210a5a9caded6f2f9a08a24b3428251a"
74
+ "gitHead": "f70fcf3c45699b8c5ad2c439112cc1aada012553"
73
75
  }