@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
@@ -1,78 +0,0 @@
1
- import { stringify } from 'csv-stringify/browser/esm/sync';
2
- import { marked } from 'marked';
3
- // TODO Implement all markdown parsing this way.
4
- // This parses tables, that follow the Github-Flavored-Markdown specification.
5
- export const parseMarkdownTables = text => {
6
- let newText = text;
7
- const tableTokens = [];
8
-
9
- // marked.parse parses all markdown in the provided text and returns the result.
10
- // The parsed result isn't needed. Instead, the parsed table tokens are collected.
11
- marked.parse(newText, {
12
- walkTokens: token => {
13
- if (token.type === 'table') {
14
- tableTokens.push(token);
15
- }
16
- }
17
- });
18
- const tables = [];
19
-
20
- // The collected table tokens are used to replace the raw Markdown table with the corresponding bb-code table.
21
- // If the table was directly parsed to html, other markdown replacements within the table wouldn't work.
22
- tableTokens.forEach((tableToken, index) => {
23
- let tableHtml = '';
24
- const tableArray = [];
25
- const id = `message-table-${index}`;
26
- tableHtml += `<table id="${id}">`;
27
- if (tableToken.header?.length > 0) {
28
- const rowArray = [];
29
- tableHtml += '<thead>';
30
- tableToken.header.forEach(header => {
31
- rowArray.push(header.text);
32
- tableHtml += '<th>';
33
- tableHtml += header.text;
34
- tableHtml += '</th>';
35
- });
36
- tableHtml += '</thead>';
37
- tableArray.push(rowArray);
38
- }
39
- if (tableToken.rows?.length > 0) {
40
- tableHtml += '<tbody>';
41
- tableToken.rows.forEach(row => {
42
- const rowArray = [];
43
- tableHtml += '<tr>';
44
- row.forEach(cell => {
45
- rowArray.push(cell.text);
46
- tableHtml += '<td>';
47
- tableHtml += cell.text;
48
- tableHtml += '</td>';
49
- });
50
- tableHtml += '</tr>';
51
- tableArray.push(rowArray);
52
- });
53
- tableHtml += '</tbody>';
54
- }
55
- tableHtml += '</table>';
56
- const csv = stringify(tableArray || []);
57
- tables.push({
58
- id,
59
- raw: tableToken.raw,
60
- csv
61
- });
62
-
63
- // This removes all trailing line breaks from the raw table Markdown, except for one.
64
- // This is done to ensure that the table HTML is followed by the correct number of line breaks.
65
- const trailingLineBreaksIndex = tableToken.raw.search(/\n+$/);
66
- const rawTableMarkdown = trailingLineBreaksIndex === -1 ? tableToken.raw : tableToken.raw.slice(0, trailingLineBreaksIndex + 1);
67
-
68
- // Replaces the raw table + a leading line break with the table HTML.
69
- // The line break is removed to ensure, that the table context menu is displayed in the same line as the text before the table.
70
- const hasLeadingLineBreak = newText.includes(`\n${rawTableMarkdown}`);
71
- newText = newText.replace(`${hasLeadingLineBreak ? '\n' : ''}${rawTableMarkdown}`, tableHtml);
72
- });
73
- return {
74
- html: newText,
75
- tables
76
- };
77
- };
78
- //# sourceMappingURL=formatMarkdownTable.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatMarkdownTable.js","names":["stringify","marked","parseMarkdownTables","text","newText","tableTokens","parse","walkTokens","token","type","push","tables","forEach","tableToken","index","tableHtml","tableArray","id","header","length","rowArray","rows","row","cell","csv","raw","trailingLineBreaksIndex","search","rawTableMarkdown","slice","hasLeadingLineBreak","includes","replace","html"],"sources":["../../../../../src/utils/formatString/markdown/formatMarkdownTable.ts"],"sourcesContent":["import { stringify } from 'csv-stringify/browser/esm/sync';\nimport { marked, Tokens } from 'marked';\n\nexport type TableObject = {\n id: string;\n raw: string;\n csv: string;\n};\n\n// TODO Implement all markdown parsing this way.\n// This parses tables, that follow the Github-Flavored-Markdown specification.\nexport const parseMarkdownTables = (text: string) => {\n let newText = text;\n const tableTokens: Tokens.Table[] = [];\n\n // marked.parse parses all markdown in the provided text and returns the result.\n // The parsed result isn't needed. Instead, the parsed table tokens are collected.\n marked.parse(newText, {\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 // The collected table tokens are used to replace the raw Markdown table with the corresponding bb-code table.\n // If the table was directly parsed to html, other markdown replacements within the table wouldn't work.\n tableTokens.forEach((tableToken, index) => {\n let tableHtml = '';\n const tableArray: string[][] = [];\n\n const id = `message-table-${index}`;\n\n tableHtml += `<table id=\"${id}\">`;\n if (tableToken.header?.length > 0) {\n const rowArray: string[] = [];\n\n tableHtml += '<thead>';\n tableToken.header.forEach((header) => {\n rowArray.push(header.text);\n\n tableHtml += '<th>';\n tableHtml += header.text;\n tableHtml += '</th>';\n });\n tableHtml += '</thead>';\n\n tableArray.push(rowArray);\n }\n if (tableToken.rows?.length > 0) {\n tableHtml += '<tbody>';\n tableToken.rows.forEach((row) => {\n const rowArray: string[] = [];\n\n tableHtml += '<tr>';\n row.forEach((cell) => {\n rowArray.push(cell.text);\n\n tableHtml += '<td>';\n tableHtml += cell.text;\n tableHtml += '</td>';\n });\n tableHtml += '</tr>';\n\n tableArray.push(rowArray);\n });\n tableHtml += '</tbody>';\n }\n tableHtml += '</table>';\n\n const csv = stringify(tableArray || []);\n\n tables.push({\n id,\n raw: tableToken.raw,\n csv,\n });\n\n // This removes all trailing line breaks from the raw table Markdown, except for one.\n // This is done to ensure that the table HTML is followed by the correct number of line breaks.\n const trailingLineBreaksIndex = tableToken.raw.search(/\\n+$/);\n const rawTableMarkdown =\n trailingLineBreaksIndex === -1\n ? tableToken.raw\n : tableToken.raw.slice(0, trailingLineBreaksIndex + 1);\n\n // Replaces the raw table + a leading line break with the table HTML.\n // The line break is removed to ensure, that the table context menu is displayed in the same line as the text before the table.\n const hasLeadingLineBreak = newText.includes(`\\n${rawTableMarkdown}`);\n newText = newText.replace(\n `${hasLeadingLineBreak ? '\\n' : ''}${rawTableMarkdown}`,\n tableHtml,\n );\n });\n\n return {\n html: newText,\n tables,\n };\n};\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,gCAAgC;AAC1D,SAASC,MAAM,QAAgB,QAAQ;AAQvC;AACA;AACA,OAAO,MAAMC,mBAAmB,GAAIC,IAAY,IAAK;EACjD,IAAIC,OAAO,GAAGD,IAAI;EAClB,MAAME,WAA2B,GAAG,EAAE;;EAEtC;EACA;EACAJ,MAAM,CAACK,KAAK,CAACF,OAAO,EAAE;IAClBG,UAAU,EAAGC,KAAK,IAAK;MACnB,IAAIA,KAAK,CAACC,IAAI,KAAK,OAAO,EAAE;QACxBJ,WAAW,CAACK,IAAI,CAACF,KAAqB,CAAC;MAC3C;IACJ;EACJ,CAAC,CAAC;EAEF,MAAMG,MAAqB,GAAG,EAAE;;EAEhC;EACA;EACAN,WAAW,CAACO,OAAO,CAAC,CAACC,UAAU,EAAEC,KAAK,KAAK;IACvC,IAAIC,SAAS,GAAG,EAAE;IAClB,MAAMC,UAAsB,GAAG,EAAE;IAEjC,MAAMC,EAAE,GAAG,iBAAiBH,KAAK,EAAE;IAEnCC,SAAS,IAAI,cAAcE,EAAE,IAAI;IACjC,IAAIJ,UAAU,CAACK,MAAM,EAAEC,MAAM,GAAG,CAAC,EAAE;MAC/B,MAAMC,QAAkB,GAAG,EAAE;MAE7BL,SAAS,IAAI,SAAS;MACtBF,UAAU,CAACK,MAAM,CAACN,OAAO,CAAEM,MAAM,IAAK;QAClCE,QAAQ,CAACV,IAAI,CAACQ,MAAM,CAACf,IAAI,CAAC;QAE1BY,SAAS,IAAI,MAAM;QACnBA,SAAS,IAAIG,MAAM,CAACf,IAAI;QACxBY,SAAS,IAAI,OAAO;MACxB,CAAC,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B,GAAG,IAAI,GAAG,EAAE,GAAGF,gBAAgB,EAAE,EACvDb,SACJ,CAAC;EACL,CAAC,CAAC;EAEF,OAAO;IACHkB,IAAI,EAAE7B,OAAO;IACbO;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
@@ -1,9 +0,0 @@
1
- export type TableObject = {
2
- id: string;
3
- raw: string;
4
- csv: string;
5
- };
6
- export declare const parseMarkdownTables: (text: string) => {
7
- html: string;
8
- tables: TableObject[];
9
- };