@ai-matrx/print 0.6.2 → 0.7.0

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
@@ -1045,6 +1045,33 @@ function isPageBreakLine(line) {
1045
1045
  if (!div) return false;
1046
1046
  return DIV_BREAK_ATTR.test(div[1] ?? div[2] ?? "");
1047
1047
  }
1048
+ var SECTION_FORM = /^<!--\s*section(?:[\s_-]?break)?\b\s*:?\s*([^>]*?)\s*-->$/i;
1049
+ function parseSectionBreakLine(line) {
1050
+ if (indentColumns(line) >= 4) return null;
1051
+ const m = SECTION_FORM.exec(line.trim());
1052
+ if (!m) return null;
1053
+ const words = (m[1] ?? "").toLowerCase();
1054
+ const out = {};
1055
+ if (/\blandscape\b/.test(words)) out.orientation = "landscape";
1056
+ else if (/\bportrait\b/.test(words)) out.orientation = "portrait";
1057
+ const cols = /\b(?:columns?|cols?)\s*[=:]\s*(\d)\b/.exec(words) ?? /\b(\d)\s*[-\s]?columns?\b/.exec(words);
1058
+ if (cols) {
1059
+ const n = Math.min(3, Math.max(1, Number(cols[1])));
1060
+ out.columns = n;
1061
+ }
1062
+ return out;
1063
+ }
1064
+ var TOC_FORM = /^(?:\[\[\s*toc\s*\]\]|\[toc\]|\$\{toc\}|<!--\s*toc\s*-->|\\tableofcontents)$/i;
1065
+ var BIBLIOGRAPHY_FORM = /^(?:\[\[\s*(?:bibliography|references)\s*\]\]|<!--\s*(?:bibliography|references)\s*-->|\\printbibliography|\\bibliography\{[^}]*\})$/i;
1066
+ function isTocLine(line) {
1067
+ return indentColumns(line) < 4 && TOC_FORM.test(line.trim());
1068
+ }
1069
+ function isBibliographyLine(line) {
1070
+ return indentColumns(line) < 4 && BIBLIOGRAPHY_FORM.test(line.trim());
1071
+ }
1072
+ function isBreakLine(line) {
1073
+ return isPageBreakLine(line) || parseSectionBreakLine(line) !== null;
1074
+ }
1048
1075
  function splitAtPageBreaks(markdown) {
1049
1076
  const lines = markdown.split(/\r?\n/);
1050
1077
  const pieces = [];
@@ -1056,7 +1083,7 @@ function splitAtPageBreaks(markdown) {
1056
1083
  const marker = fenceMatch[1];
1057
1084
  if (fence === null) fence = marker;
1058
1085
  else if (marker[0] === fence[0] && marker.length >= fence.length) fence = null;
1059
- } else if (fence === null && isPageBreakLine(line)) {
1086
+ } else if (fence === null && isBreakLine(line)) {
1060
1087
  if (current.join("\n").trim()) pieces.push(current.join("\n"));
1061
1088
  current = [];
1062
1089
  continue;
@@ -1283,10 +1310,11 @@ function protectRegions(markdown, g, stash, ctx) {
1283
1310
  i = j;
1284
1311
  continue;
1285
1312
  }
1286
- if (isPageBreakLine(line)) {
1313
+ if (isBreakLine(line)) {
1287
1314
  out.push(stash.block(PAGE_BREAK_HTML));
1288
1315
  continue;
1289
1316
  }
1317
+ if (isTocLine(line) || isBibliographyLine(line)) continue;
1290
1318
  const open = /^\s*<artifact\b((?:[^>"']|"[^"]*"|'[^']*')*?)(\/?)>(.*)$/i.exec(line);
1291
1319
  if (open) {
1292
1320
  const attrs = parseTagAttributes(open[1] ?? "");