@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/dist/markdown.cjs CHANGED
@@ -67,6 +67,7 @@ function openPrintWindow(htmlDocument, filename = "print", windowFeatures = "wid
67
67
 
68
68
  // src/markdown.ts
69
69
  var import_html_escape2 = require("@ai-matrx/kit/html-escape");
70
+ var import_source = require("@ai-matrx/content-ir/source");
70
71
 
71
72
  // src/safe-html.ts
72
73
  var import_hast_util_from_html = require("hast-util-from-html");
@@ -1576,12 +1577,6 @@ var LINK_RE = new RegExp(String.raw`\[([^\]]+)\]\(` + LINK_URL + String.raw`\)`,
1576
1577
  function convertRules(html, g) {
1577
1578
  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)}>`);
1578
1579
  }
1579
- function splitTableRow(row) {
1580
- let r = row.trim();
1581
- if (r.startsWith("|")) r = r.slice(1);
1582
- if (r.endsWith("|") && !r.endsWith("\\|")) r = r.slice(0, -1);
1583
- return r.split(/(?<!\\)\|/).map((c) => c.trim().replace(/\\\|/g, "|"));
1584
- }
1585
1580
  function cellAlign2(separator) {
1586
1581
  const s = separator.trim();
1587
1582
  const left = s.startsWith(":");
@@ -1591,40 +1586,48 @@ function cellAlign2(separator) {
1591
1586
  return "";
1592
1587
  }
1593
1588
  function convertTables(html, g) {
1594
- const tableRegex = /^(\|.*\|)\s*\n(\|[-\s:|]*\|)\s*\n((?:\|.*\|\s*\n?)*)/gm;
1595
- return html.replace(
1596
- tableRegex,
1597
- (_m, headerRow, separatorRow, bodyRows) => {
1598
- const headers = splitTableRow(headerRow);
1599
- const aligns = splitTableRow(separatorRow).map(cellAlign2);
1600
- const rows = bodyRows.trim().split("\n").filter((r) => r.trim()).map(splitTableRow);
1601
- let t = `<table${cls(g.table)}>
1589
+ const lines = html.split("\n");
1590
+ const out = [];
1591
+ for (let i = 0; i < lines.length; i += 1) {
1592
+ if (!(0, import_source.tableStartsAt)(lines, i)) {
1593
+ out.push(lines[i] ?? "");
1594
+ continue;
1595
+ }
1596
+ const end = (0, import_source.findTableEnd)(lines, i);
1597
+ const cellsOf = (line) => (0, import_source.rowCells)(line).map(import_source.unescapeCellPipes);
1598
+ const headers = cellsOf(lines[i] ?? "");
1599
+ const aligns = (0, import_source.rowCells)(lines[i + 1] ?? "").map(cellAlign2);
1600
+ const rows = lines.slice(i + 2, end).map((line) => {
1601
+ const cells = cellsOf(line);
1602
+ return headers.map((_h, k) => cells[k] ?? "");
1603
+ });
1604
+ let t = `<table${cls(g.table)}>
1602
1605
  <thead${cls(g.thead)}>
1603
1606
  <tr${cls(g.tr)}>
1604
1607
  `;
1605
- headers.forEach((h, i) => {
1606
- t += `<th${cls(g.th)}${aligns[i] ?? ""}>${h}</th>
1608
+ headers.forEach((h, k) => {
1609
+ t += `<th${cls(g.th)}${aligns[k] ?? ""}>${h}</th>
1607
1610
  `;
1608
- });
1609
- t += "</tr>\n</thead>\n";
1610
- if (rows.length > 0) {
1611
- t += `<tbody${cls(g.tbody)}>
1611
+ });
1612
+ t += "</tr>\n</thead>\n";
1613
+ if (rows.length > 0) {
1614
+ t += `<tbody${cls(g.tbody)}>
1612
1615
  `;
1613
- for (const row of rows) {
1614
- t += `<tr${cls(g.tr)}>
1616
+ for (const row of rows) {
1617
+ t += `<tr${cls(g.tr)}>
1615
1618
  `;
1616
- row.forEach((c, i) => {
1617
- t += `<td${cls(g.td)}${aligns[i] ?? ""}>${c}</td>
1619
+ row.forEach((c, k) => {
1620
+ t += `<td${cls(g.td)}${aligns[k] ?? ""}>${c}</td>
1618
1621
  `;
1619
- });
1620
- t += "</tr>\n";
1621
- }
1622
- t += "</tbody>\n";
1622
+ });
1623
+ t += "</tr>\n";
1623
1624
  }
1624
- return `${t}</table>
1625
- `;
1625
+ t += "</tbody>\n";
1626
1626
  }
1627
- );
1627
+ out.push(`${t}</table>`);
1628
+ i = end - 1;
1629
+ }
1630
+ return out.join("\n");
1628
1631
  }
1629
1632
  function convertLists(html, g) {
1630
1633
  const lines = html.split("\n");