ag-common 0.0.634 → 0.0.636
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.
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Markdown = void 0;
|
|
7
|
+
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const trim_1 = require("../../../common/helpers/string/trim");
|
|
10
|
+
const renderMarkdownTable = (rows) => {
|
|
11
|
+
const headers = rows[0].split('|').map((header) => header.trim());
|
|
12
|
+
const tableBody = rows.slice(2).map((row) => {
|
|
13
|
+
const cells = row.split('|').map((cell) => cell.trim());
|
|
14
|
+
return `<tr>${cells.map((cell) => `<td>${cell}</td>`).join('')}</tr>`;
|
|
15
|
+
});
|
|
16
|
+
return `<table><thead><tr>${headers.map((header) => `<th>${header}</th>`).join('')}</tr></thead><tbody>${tableBody.join('')}</tbody></table>`;
|
|
17
|
+
};
|
|
18
|
+
function renderMarkdown(markdown) {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const lines = markdown.split('\n');
|
|
21
|
+
let output = '';
|
|
22
|
+
let ol = false;
|
|
23
|
+
let tableRows = [];
|
|
24
|
+
for (let line of lines) {
|
|
25
|
+
//handle inline **s
|
|
26
|
+
line = line.replace(/\*\*(.*?)\*\*/gim, `<b>$1</b>`);
|
|
27
|
+
if (line.startsWith('|')) {
|
|
28
|
+
tableRows.push(line);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
if (tableRows.length > 0) {
|
|
33
|
+
output += renderMarkdownTable(tableRows);
|
|
34
|
+
tableRows = [];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (line.match(/^[0-9]+\./gim)) {
|
|
38
|
+
if (!ol) {
|
|
39
|
+
output += '<ol>';
|
|
40
|
+
}
|
|
41
|
+
ol = true;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
if (ol) {
|
|
45
|
+
ol = false;
|
|
46
|
+
output += '</ol>';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Handle headings
|
|
50
|
+
if (line.startsWith('#')) {
|
|
51
|
+
const level = (_b = (_a = line.match(/^#+/)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
52
|
+
const t = (0, trim_1.trimSide)(line, true, '#');
|
|
53
|
+
output += `<h${level}>${t}</h${level}>\n`;
|
|
54
|
+
}
|
|
55
|
+
else if (line.startsWith('*')) {
|
|
56
|
+
// Handle unordered lists
|
|
57
|
+
output += `<ul>\n<li>${line.slice(2).trim()}</li>\n</ul>\n`;
|
|
58
|
+
}
|
|
59
|
+
else if (line.startsWith('-')) {
|
|
60
|
+
// Handle unordered lists (alternative syntax)
|
|
61
|
+
output += `<ul>\n<li>${line.slice(2).trim()}</li>\n</ul>\n`;
|
|
62
|
+
}
|
|
63
|
+
else if (line.match(/^[0-9]+\./gim)) {
|
|
64
|
+
// Handle ordered lists
|
|
65
|
+
output += `\n<li>${line.slice(3).trim()}</li>\n`;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// Handle paragraphs
|
|
69
|
+
output += `<p>${line.trim()}</p>\n`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return output;
|
|
73
|
+
}
|
|
74
|
+
const Base = styled_1.default.div `
|
|
75
|
+
p,
|
|
76
|
+
li {
|
|
77
|
+
white-space: pre-wrap;
|
|
78
|
+
}
|
|
79
|
+
ol {
|
|
80
|
+
padding-inline-start: 1rem;
|
|
81
|
+
}
|
|
82
|
+
`;
|
|
83
|
+
const Markdown = (p) => {
|
|
84
|
+
return (react_1.default.createElement(Base, { dangerouslySetInnerHTML: { __html: renderMarkdown(p.content) } }));
|
|
85
|
+
};
|
|
86
|
+
exports.Markdown = Markdown;
|
|
@@ -31,6 +31,7 @@ __exportStar(require("./Image"), exports);
|
|
|
31
31
|
__exportStar(require("./InfiniteScroll"), exports);
|
|
32
32
|
__exportStar(require("./KebabDots"), exports);
|
|
33
33
|
__exportStar(require("./Loader"), exports);
|
|
34
|
+
__exportStar(require("./Markdown"), exports);
|
|
34
35
|
__exportStar(require("./MinSidebar"), exports);
|
|
35
36
|
__exportStar(require("./Modal"), exports);
|
|
36
37
|
__exportStar(require("./OpenApiCodeBlock"), exports);
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.636",
|
|
3
3
|
"name": "ag-common",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"@storybook/theming": "7.6.16",
|
|
55
55
|
"@types/jsonwebtoken": "9.0.5",
|
|
56
56
|
"@types/node": "20.11.19",
|
|
57
|
-
"@types/react": "18.2.
|
|
57
|
+
"@types/react": "18.2.57",
|
|
58
58
|
"@types/react-dom": "18.2.19",
|
|
59
59
|
"cross-env": "7.0.3",
|
|
60
|
-
"eslint-config-e7npm": "0.0.
|
|
60
|
+
"eslint-config-e7npm": "0.0.86",
|
|
61
61
|
"globstar": "^1.0.0",
|
|
62
62
|
"rimraf": "5.0.5",
|
|
63
63
|
"storybook": "7.6.16",
|