@ai-matrx/print 0.8.9 → 0.8.10
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 +14 -0
- package/dist/document.cjs.map +1 -1
- package/dist/document.js +1 -1
- package/dist/document.js.map +1 -1
- package/dist/markdown-html.cjs.map +1 -1
- package/dist/markdown-html.js +1 -1
- package/dist/markdown-html.js.map +1 -1
- package/dist/markdown.cjs +50 -36
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.js +51 -37
- package/dist/markdown.js.map +1 -1
- package/package.json +1 -1
package/dist/markdown.js
CHANGED
|
@@ -22,7 +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
|
+
import { codeSpanText, findTableEnd, mapCodeRanges, rowCells, tableStartsAt, unescapeCellPipes } from "@ai-matrx/content-ir/source";
|
|
26
26
|
|
|
27
27
|
// src/safe-html.ts
|
|
28
28
|
import { fromHtml } from "hast-util-from-html";
|
|
@@ -1445,6 +1445,12 @@ function protectRegions(markdown, g, stash, ctx) {
|
|
|
1445
1445
|
i = j;
|
|
1446
1446
|
continue;
|
|
1447
1447
|
}
|
|
1448
|
+
if (tableStartsAt(lines, i)) {
|
|
1449
|
+
const end = findTableEnd(lines, i);
|
|
1450
|
+
out.push(stash.block(tableHtml(lines.slice(i, end), g, stash)));
|
|
1451
|
+
i = end - 1;
|
|
1452
|
+
continue;
|
|
1453
|
+
}
|
|
1448
1454
|
out.push(line);
|
|
1449
1455
|
}
|
|
1450
1456
|
let text = out.join("\n");
|
|
@@ -1452,6 +1458,7 @@ function protectRegions(markdown, g, stash, ctx) {
|
|
|
1452
1458
|
/`([^`\n]+)`/g,
|
|
1453
1459
|
(_m, code) => stash.inline(`<code${cls(g.inlineCode)}>${escapeHtml2(code)}</code>`)
|
|
1454
1460
|
);
|
|
1461
|
+
text = resolveEscapes(text, stash);
|
|
1455
1462
|
text = text.replace(/<!--[\s\S]*?-->/g, "");
|
|
1456
1463
|
const before = text;
|
|
1457
1464
|
for (let pass = 0; pass < 8; pass++) {
|
|
@@ -1540,49 +1547,58 @@ function cellAlign2(separator) {
|
|
|
1540
1547
|
if (right) return ' style="text-align:right"';
|
|
1541
1548
|
return "";
|
|
1542
1549
|
}
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
}
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1550
|
+
var ESCAPE_RE = /\\([!-\/:-@[-`{-~])/g;
|
|
1551
|
+
function resolveEscapes(text, stash) {
|
|
1552
|
+
return text.replace(ESCAPE_RE, (_m, ch) => stash.inline(escapeHtml2(ch)));
|
|
1553
|
+
}
|
|
1554
|
+
function cellInlineHtml(cell, g, stash) {
|
|
1555
|
+
let t = mapCodeRanges(
|
|
1556
|
+
unescapeCellPipes(cell),
|
|
1557
|
+
(range, raw) => range.kind === "span" ? stash.inline(`<code${cls(g.inlineCode)}>${escapeHtml2(codeSpanText(raw))}</code>`) : raw
|
|
1558
|
+
);
|
|
1559
|
+
t = resolveEscapes(t, stash);
|
|
1560
|
+
t = t.replace(
|
|
1561
|
+
IMAGE_RE,
|
|
1562
|
+
(_m, alt, url) => stash.inline(`<img class="${g.skin === "document" ? "matrx-image" : "print-image"}" src="${safeUrl(url)}" alt="${escapeHtml2(alt)}" />`)
|
|
1563
|
+
);
|
|
1564
|
+
t = t.replace(
|
|
1565
|
+
LINK_RE,
|
|
1566
|
+
(_m, text, url) => stash.inline(`<a${g.skin === "document" ? ' class="matrx-link"' : ""} href="${safeUrl(url)}">${convertEmphasis(text, g)}</a>`)
|
|
1567
|
+
);
|
|
1568
|
+
return convertEmphasis(t, g);
|
|
1569
|
+
}
|
|
1570
|
+
function tableHtml(lines, g, stash) {
|
|
1571
|
+
const cellsOf = (line) => rowCells(line).map((cell) => cellInlineHtml(cell, g, stash));
|
|
1572
|
+
const headers = cellsOf(lines[0] ?? "");
|
|
1573
|
+
const aligns = rowCells(lines[1] ?? "").map(cellAlign2);
|
|
1574
|
+
const rows = lines.slice(2).map((line) => {
|
|
1575
|
+
const cells = cellsOf(line);
|
|
1576
|
+
return headers.map((_h, k) => cells[k] ?? "");
|
|
1577
|
+
});
|
|
1578
|
+
let t = `<table${cls(g.table)}>
|
|
1560
1579
|
<thead${cls(g.thead)}>
|
|
1561
1580
|
<tr${cls(g.tr)}>
|
|
1562
1581
|
`;
|
|
1563
|
-
|
|
1564
|
-
|
|
1582
|
+
headers.forEach((h, k) => {
|
|
1583
|
+
t += `<th${cls(g.th)}${aligns[k] ?? ""}>${h}</th>
|
|
1565
1584
|
`;
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1585
|
+
});
|
|
1586
|
+
t += "</tr>\n</thead>\n";
|
|
1587
|
+
if (rows.length > 0) {
|
|
1588
|
+
t += `<tbody${cls(g.tbody)}>
|
|
1570
1589
|
`;
|
|
1571
|
-
|
|
1572
|
-
|
|
1590
|
+
for (const row of rows) {
|
|
1591
|
+
t += `<tr${cls(g.tr)}>
|
|
1573
1592
|
`;
|
|
1574
|
-
|
|
1575
|
-
|
|
1593
|
+
row.forEach((c, k) => {
|
|
1594
|
+
t += `<td${cls(g.td)}${aligns[k] ?? ""}>${c}</td>
|
|
1576
1595
|
`;
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
}
|
|
1580
|
-
t += "</tbody>\n";
|
|
1596
|
+
});
|
|
1597
|
+
t += "</tr>\n";
|
|
1581
1598
|
}
|
|
1582
|
-
|
|
1583
|
-
i = end - 1;
|
|
1599
|
+
t += "</tbody>\n";
|
|
1584
1600
|
}
|
|
1585
|
-
return
|
|
1601
|
+
return `${t}</table>`;
|
|
1586
1602
|
}
|
|
1587
1603
|
function convertLists(html, g) {
|
|
1588
1604
|
const lines = html.split("\n");
|
|
@@ -1689,7 +1705,6 @@ function documentBody(markdown, ctx) {
|
|
|
1689
1705
|
html = convertLists(html, g);
|
|
1690
1706
|
html = convertEmphasis(html, g);
|
|
1691
1707
|
html = html.replace(/^> ?(.+)$/gm, '<blockquote class="matrx-blockquote">$1</blockquote>');
|
|
1692
|
-
html = convertTables(html, g);
|
|
1693
1708
|
html = html.replace(/<table>/g, '<table class="matrx-table">').replace(/<thead>/g, '<thead class="matrx-table-head">').replace(/<tbody>/g, '<tbody class="matrx-table-body">').replace(/<tr>/g, '<tr class="matrx-table-row">').replace(/<th>/g, '<th class="matrx-table-header">').replace(/<td>/g, '<td class="matrx-table-cell">');
|
|
1694
1709
|
html = html.replace(/<img(?![^>]*class=)([^>]*)>/g, '<img class="matrx-image"$1>');
|
|
1695
1710
|
html = html.replace(/<div\b([^>]*)>/g, (m, attrs) => {
|
|
@@ -1746,7 +1761,6 @@ function articleBody(markdown, ctx) {
|
|
|
1746
1761
|
const g = ARTICLE_GRAMMAR;
|
|
1747
1762
|
const stash = new Stash();
|
|
1748
1763
|
let html = protectRegions(markdown, g, stash, ctx);
|
|
1749
|
-
html = convertTables(html, g);
|
|
1750
1764
|
html = convertRules(html, g);
|
|
1751
1765
|
html = html.replace(
|
|
1752
1766
|
IMAGE_RE,
|