@ai-matrx/print 0.8.8 → 0.8.9
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.
- package/CHANGELOG.md +26 -0
- package/dist/document.cjs +52 -5
- package/dist/document.cjs.map +1 -1
- package/dist/document.d.cts +10 -2
- package/dist/document.d.ts +10 -2
- package/dist/document.js +52 -5
- package/dist/document.js.map +1 -1
- package/dist/markdown-html.cjs +4207 -0
- package/dist/markdown-html.cjs.map +1 -0
- package/dist/markdown-html.d.cts +87 -0
- package/dist/markdown-html.d.ts +87 -0
- package/dist/markdown-html.js +4176 -0
- package/dist/markdown-html.js.map +1 -0
- package/dist/markdown.cjs +34 -31
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.js +34 -31
- package/dist/markdown.js.map +1 -1
- package/dist/safe-html.cjs +68 -0
- package/dist/safe-html.cjs.map +1 -1
- package/dist/safe-html.d.cts +14 -1
- package/dist/safe-html.d.ts +14 -1
- package/dist/safe-html.js +68 -0
- package/dist/safe-html.js.map +1 -1
- package/package.json +11 -1
package/dist/markdown.js
CHANGED
|
@@ -22,6 +22,7 @@ function openPrintWindow(htmlDocument, filename = "print", windowFeatures = "wid
|
|
|
22
22
|
|
|
23
23
|
// src/markdown.ts
|
|
24
24
|
import { escapeHtml as escapeHtml2 } from "@ai-matrx/kit/html-escape";
|
|
25
|
+
import { findTableEnd, rowCells, tableStartsAt, unescapeCellPipes } from "@ai-matrx/content-ir/source";
|
|
25
26
|
|
|
26
27
|
// src/safe-html.ts
|
|
27
28
|
import { fromHtml } from "hast-util-from-html";
|
|
@@ -1531,12 +1532,6 @@ var LINK_RE = new RegExp(String.raw`\[([^\]]+)\]\(` + LINK_URL + String.raw`\)`,
|
|
|
1531
1532
|
function convertRules(html, g) {
|
|
1532
1533
|
return html.replace(/^\s{0,3}#\s*={3,}\s*$/gm, `<hr${cls(g.hr, "matrx-hr-heavy")}>`).replace(/^\s{0,3}\*(?:\s*\*){2,}\s*$/gm, `<hr${cls(g.hr, "matrx-hr-accent")}>`).replace(/^\s{0,3}(?:-\s*){3,}$/gm, `<hr${cls(g.hr)}>`).replace(/^\s{0,3}(?:_\s*){3,}$/gm, `<hr${cls(g.hr)}>`);
|
|
1533
1534
|
}
|
|
1534
|
-
function splitTableRow(row) {
|
|
1535
|
-
let r = row.trim();
|
|
1536
|
-
if (r.startsWith("|")) r = r.slice(1);
|
|
1537
|
-
if (r.endsWith("|") && !r.endsWith("\\|")) r = r.slice(0, -1);
|
|
1538
|
-
return r.split(/(?<!\\)\|/).map((c) => c.trim().replace(/\\\|/g, "|"));
|
|
1539
|
-
}
|
|
1540
1535
|
function cellAlign2(separator) {
|
|
1541
1536
|
const s = separator.trim();
|
|
1542
1537
|
const left = s.startsWith(":");
|
|
@@ -1546,40 +1541,48 @@ function cellAlign2(separator) {
|
|
|
1546
1541
|
return "";
|
|
1547
1542
|
}
|
|
1548
1543
|
function convertTables(html, g) {
|
|
1549
|
-
const
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
(
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1544
|
+
const lines = html.split("\n");
|
|
1545
|
+
const out = [];
|
|
1546
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
1547
|
+
if (!tableStartsAt(lines, i)) {
|
|
1548
|
+
out.push(lines[i] ?? "");
|
|
1549
|
+
continue;
|
|
1550
|
+
}
|
|
1551
|
+
const end = findTableEnd(lines, i);
|
|
1552
|
+
const cellsOf = (line) => rowCells(line).map(unescapeCellPipes);
|
|
1553
|
+
const headers = cellsOf(lines[i] ?? "");
|
|
1554
|
+
const aligns = rowCells(lines[i + 1] ?? "").map(cellAlign2);
|
|
1555
|
+
const rows = lines.slice(i + 2, end).map((line) => {
|
|
1556
|
+
const cells = cellsOf(line);
|
|
1557
|
+
return headers.map((_h, k) => cells[k] ?? "");
|
|
1558
|
+
});
|
|
1559
|
+
let t = `<table${cls(g.table)}>
|
|
1557
1560
|
<thead${cls(g.thead)}>
|
|
1558
1561
|
<tr${cls(g.tr)}>
|
|
1559
1562
|
`;
|
|
1560
|
-
|
|
1561
|
-
|
|
1563
|
+
headers.forEach((h, k) => {
|
|
1564
|
+
t += `<th${cls(g.th)}${aligns[k] ?? ""}>${h}</th>
|
|
1562
1565
|
`;
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1566
|
+
});
|
|
1567
|
+
t += "</tr>\n</thead>\n";
|
|
1568
|
+
if (rows.length > 0) {
|
|
1569
|
+
t += `<tbody${cls(g.tbody)}>
|
|
1567
1570
|
`;
|
|
1568
|
-
|
|
1569
|
-
|
|
1571
|
+
for (const row of rows) {
|
|
1572
|
+
t += `<tr${cls(g.tr)}>
|
|
1570
1573
|
`;
|
|
1571
|
-
|
|
1572
|
-
|
|
1574
|
+
row.forEach((c, k) => {
|
|
1575
|
+
t += `<td${cls(g.td)}${aligns[k] ?? ""}>${c}</td>
|
|
1573
1576
|
`;
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
}
|
|
1577
|
-
t += "</tbody>\n";
|
|
1577
|
+
});
|
|
1578
|
+
t += "</tr>\n";
|
|
1578
1579
|
}
|
|
1579
|
-
|
|
1580
|
-
`;
|
|
1580
|
+
t += "</tbody>\n";
|
|
1581
1581
|
}
|
|
1582
|
-
|
|
1582
|
+
out.push(`${t}</table>`);
|
|
1583
|
+
i = end - 1;
|
|
1584
|
+
}
|
|
1585
|
+
return out.join("\n");
|
|
1583
1586
|
}
|
|
1584
1587
|
function convertLists(html, g) {
|
|
1585
1588
|
const lines = html.split("\n");
|