@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/dist/markdown.cjs CHANGED
@@ -1490,6 +1490,12 @@ function protectRegions(markdown, g, stash, ctx) {
1490
1490
  i = j;
1491
1491
  continue;
1492
1492
  }
1493
+ if ((0, import_source.tableStartsAt)(lines, i)) {
1494
+ const end = (0, import_source.findTableEnd)(lines, i);
1495
+ out.push(stash.block(tableHtml(lines.slice(i, end), g, stash)));
1496
+ i = end - 1;
1497
+ continue;
1498
+ }
1493
1499
  out.push(line);
1494
1500
  }
1495
1501
  let text = out.join("\n");
@@ -1497,6 +1503,7 @@ function protectRegions(markdown, g, stash, ctx) {
1497
1503
  /`([^`\n]+)`/g,
1498
1504
  (_m, code) => stash.inline(`<code${cls(g.inlineCode)}>${(0, import_html_escape2.escapeHtml)(code)}</code>`)
1499
1505
  );
1506
+ text = resolveEscapes(text, stash);
1500
1507
  text = text.replace(/<!--[\s\S]*?-->/g, "");
1501
1508
  const before = text;
1502
1509
  for (let pass = 0; pass < 8; pass++) {
@@ -1585,49 +1592,58 @@ function cellAlign2(separator) {
1585
1592
  if (right) return ' style="text-align:right"';
1586
1593
  return "";
1587
1594
  }
1588
- function convertTables(html, g) {
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)}>
1595
+ var ESCAPE_RE = /\\([!-\/:-@[-`{-~])/g;
1596
+ function resolveEscapes(text, stash) {
1597
+ return text.replace(ESCAPE_RE, (_m, ch) => stash.inline((0, import_html_escape2.escapeHtml)(ch)));
1598
+ }
1599
+ function cellInlineHtml(cell, g, stash) {
1600
+ let t = (0, import_source.mapCodeRanges)(
1601
+ (0, import_source.unescapeCellPipes)(cell),
1602
+ (range, raw) => range.kind === "span" ? stash.inline(`<code${cls(g.inlineCode)}>${(0, import_html_escape2.escapeHtml)((0, import_source.codeSpanText)(raw))}</code>`) : raw
1603
+ );
1604
+ t = resolveEscapes(t, stash);
1605
+ t = t.replace(
1606
+ IMAGE_RE,
1607
+ (_m, alt, url) => stash.inline(`<img class="${g.skin === "document" ? "matrx-image" : "print-image"}" src="${safeUrl(url)}" alt="${(0, import_html_escape2.escapeHtml)(alt)}" />`)
1608
+ );
1609
+ t = t.replace(
1610
+ LINK_RE,
1611
+ (_m, text, url) => stash.inline(`<a${g.skin === "document" ? ' class="matrx-link"' : ""} href="${safeUrl(url)}">${convertEmphasis(text, g)}</a>`)
1612
+ );
1613
+ return convertEmphasis(t, g);
1614
+ }
1615
+ function tableHtml(lines, g, stash) {
1616
+ const cellsOf = (line) => (0, import_source.rowCells)(line).map((cell) => cellInlineHtml(cell, g, stash));
1617
+ const headers = cellsOf(lines[0] ?? "");
1618
+ const aligns = (0, import_source.rowCells)(lines[1] ?? "").map(cellAlign2);
1619
+ const rows = lines.slice(2).map((line) => {
1620
+ const cells = cellsOf(line);
1621
+ return headers.map((_h, k) => cells[k] ?? "");
1622
+ });
1623
+ let t = `<table${cls(g.table)}>
1605
1624
  <thead${cls(g.thead)}>
1606
1625
  <tr${cls(g.tr)}>
1607
1626
  `;
1608
- headers.forEach((h, k) => {
1609
- t += `<th${cls(g.th)}${aligns[k] ?? ""}>${h}</th>
1627
+ headers.forEach((h, k) => {
1628
+ t += `<th${cls(g.th)}${aligns[k] ?? ""}>${h}</th>
1610
1629
  `;
1611
- });
1612
- t += "</tr>\n</thead>\n";
1613
- if (rows.length > 0) {
1614
- t += `<tbody${cls(g.tbody)}>
1630
+ });
1631
+ t += "</tr>\n</thead>\n";
1632
+ if (rows.length > 0) {
1633
+ t += `<tbody${cls(g.tbody)}>
1615
1634
  `;
1616
- for (const row of rows) {
1617
- t += `<tr${cls(g.tr)}>
1635
+ for (const row of rows) {
1636
+ t += `<tr${cls(g.tr)}>
1618
1637
  `;
1619
- row.forEach((c, k) => {
1620
- t += `<td${cls(g.td)}${aligns[k] ?? ""}>${c}</td>
1638
+ row.forEach((c, k) => {
1639
+ t += `<td${cls(g.td)}${aligns[k] ?? ""}>${c}</td>
1621
1640
  `;
1622
- });
1623
- t += "</tr>\n";
1624
- }
1625
- t += "</tbody>\n";
1641
+ });
1642
+ t += "</tr>\n";
1626
1643
  }
1627
- out.push(`${t}</table>`);
1628
- i = end - 1;
1644
+ t += "</tbody>\n";
1629
1645
  }
1630
- return out.join("\n");
1646
+ return `${t}</table>`;
1631
1647
  }
1632
1648
  function convertLists(html, g) {
1633
1649
  const lines = html.split("\n");
@@ -1734,7 +1750,6 @@ function documentBody(markdown, ctx) {
1734
1750
  html = convertLists(html, g);
1735
1751
  html = convertEmphasis(html, g);
1736
1752
  html = html.replace(/^> ?(.+)$/gm, '<blockquote class="matrx-blockquote">$1</blockquote>');
1737
- html = convertTables(html, g);
1738
1753
  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">');
1739
1754
  html = html.replace(/<img(?![^>]*class=)([^>]*)>/g, '<img class="matrx-image"$1>');
1740
1755
  html = html.replace(/<div\b([^>]*)>/g, (m, attrs) => {
@@ -1791,7 +1806,6 @@ function articleBody(markdown, ctx) {
1791
1806
  const g = ARTICLE_GRAMMAR;
1792
1807
  const stash = new Stash();
1793
1808
  let html = protectRegions(markdown, g, stash, ctx);
1794
- html = convertTables(html, g);
1795
1809
  html = convertRules(html, g);
1796
1810
  html = html.replace(
1797
1811
  IMAGE_RE,