@ai-matrx/print 0.6.1 → 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
@@ -1027,7 +1027,17 @@ var COMMENT_FORM = /^<!--\s*(?:page[\s_-]?break|new[\s_-]?page)\s*-->$/i;
1027
1027
  var LATEX_FORM = /^\\(?:pagebreak|newpage|clearpage)\s*(?:\{\s*\})?$/i;
1028
1028
  var DIV_FORM = /^<div\b([^>]*)>\s*<\/div>$|^<div\b([^>]*)\/>$/i;
1029
1029
  var DIV_BREAK_ATTR = /(?:page-break-(?:after|before)\s*:\s*always|break-(?:after|before)\s*:\s*page|class\s*=\s*["'](?:[^"']*\s)?page-?break(?:\s[^"']*)?["'])/i;
1030
+ function indentColumns(line) {
1031
+ let cols = 0;
1032
+ for (const ch of line) {
1033
+ if (ch === " " || ch === "\xA0") cols += 1;
1034
+ else if (ch === " ") cols += 4;
1035
+ else break;
1036
+ }
1037
+ return cols;
1038
+ }
1030
1039
  function isPageBreakLine(line) {
1040
+ if (indentColumns(line) >= 4) return false;
1031
1041
  const t = line.trim();
1032
1042
  if (t.length < 8 || t.length > 200) return false;
1033
1043
  if (COMMENT_FORM.test(t) || LATEX_FORM.test(t)) return true;
@@ -1035,6 +1045,33 @@ function isPageBreakLine(line) {
1035
1045
  if (!div) return false;
1036
1046
  return DIV_BREAK_ATTR.test(div[1] ?? div[2] ?? "");
1037
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
+ }
1038
1075
  function splitAtPageBreaks(markdown) {
1039
1076
  const lines = markdown.split(/\r?\n/);
1040
1077
  const pieces = [];
@@ -1046,7 +1083,7 @@ function splitAtPageBreaks(markdown) {
1046
1083
  const marker = fenceMatch[1];
1047
1084
  if (fence === null) fence = marker;
1048
1085
  else if (marker[0] === fence[0] && marker.length >= fence.length) fence = null;
1049
- } else if (fence === null && isPageBreakLine(line)) {
1086
+ } else if (fence === null && isBreakLine(line)) {
1050
1087
  if (current.join("\n").trim()) pieces.push(current.join("\n"));
1051
1088
  current = [];
1052
1089
  continue;
@@ -1273,10 +1310,11 @@ function protectRegions(markdown, g, stash, ctx) {
1273
1310
  i = j;
1274
1311
  continue;
1275
1312
  }
1276
- if (isPageBreakLine(line)) {
1313
+ if (isBreakLine(line)) {
1277
1314
  out.push(stash.block(PAGE_BREAK_HTML));
1278
1315
  continue;
1279
1316
  }
1317
+ if (isTocLine(line) || isBibliographyLine(line)) continue;
1280
1318
  const open = /^\s*<artifact\b((?:[^>"']|"[^"]*"|'[^']*')*?)(\/?)>(.*)$/i.exec(line);
1281
1319
  if (open) {
1282
1320
  const attrs = parseTagAttributes(open[1] ?? "");