@ai-matrx/print 0.8.2 → 0.8.3
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 +12 -0
- package/dist/document.cjs +76 -7
- package/dist/document.cjs.map +1 -1
- package/dist/document.js +76 -7
- package/dist/document.js.map +1 -1
- package/dist/markdown.cjs +40 -1
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.d.cts +9 -1
- package/dist/markdown.d.ts +9 -1
- package/dist/markdown.js +40 -1
- package/dist/markdown.js.map +1 -1
- package/package.json +1 -1
package/dist/document.js
CHANGED
|
@@ -3027,7 +3027,11 @@ async function documentToDocx(tree, options = {}) {
|
|
|
3027
3027
|
numbering: { config: [...c.numbering.entries()].map(([reference, levels2]) => ({ reference, levels: levels2 })) },
|
|
3028
3028
|
styles: {
|
|
3029
3029
|
default: {
|
|
3030
|
-
|
|
3030
|
+
// East-Asian text gets a CJK face (Word and LibreOffice substitute an installed one).
|
|
3031
|
+
document: {
|
|
3032
|
+
run: { font: { ascii: "Cambria", hAnsi: "Cambria", cs: "Cambria", eastAsia: "Yu Gothic" }, size, color: HEX.text },
|
|
3033
|
+
paragraph: { spacing: { after: 140, line: 300 } }
|
|
3034
|
+
}
|
|
3031
3035
|
},
|
|
3032
3036
|
paragraphStyles: [
|
|
3033
3037
|
heading("Heading1", "Heading 1", s.fontSize * 1.8, 0),
|
|
@@ -3170,7 +3174,7 @@ function renderInlineHtml(nodes, x) {
|
|
|
3170
3174
|
case "cite":
|
|
3171
3175
|
return n.resolved ? `<a class="doc-cite" href="${escapeHtml(href("ref-" + (n.keys[0] ?? ""), x))}">${escapeHtml(n.label)}</a>` : `<span class="doc-cite doc-cite-missing">${escapeHtml(n.label)}</span>`;
|
|
3172
3176
|
case "math":
|
|
3173
|
-
return mathHtml(n.tex, n.display, x);
|
|
3177
|
+
return mathHtml(n.tex, n.display, x, true);
|
|
3174
3178
|
case "noteRef":
|
|
3175
3179
|
return `<sup class="doc-note-ref"><a href="${escapeHtml(href(`note-${n.n}`, x))}" id="noteref-${n.n}">${n.n}</a></sup>`;
|
|
3176
3180
|
default:
|
|
@@ -3178,10 +3182,11 @@ function renderInlineHtml(nodes, x) {
|
|
|
3178
3182
|
}
|
|
3179
3183
|
}).join("");
|
|
3180
3184
|
}
|
|
3181
|
-
function mathHtml(tex, display, x) {
|
|
3185
|
+
function mathHtml(tex, display, x, inText = false) {
|
|
3182
3186
|
const m = x.tree.math.get(mathKey(tex, display));
|
|
3183
3187
|
if (m?.mathml && !m.error) {
|
|
3184
|
-
|
|
3188
|
+
if (!display) return `<span class="doc-math">${m.mathml}</span>`;
|
|
3189
|
+
return inText ? `<span class="doc-math-display">${m.mathml}</span>` : `<div class="doc-math-display">${m.mathml}</div>`;
|
|
3185
3190
|
}
|
|
3186
3191
|
return `<code class="doc-math-tex">${escapeHtml(display ? `$$${tex}$$` : `$${tex}$`)}</code>`;
|
|
3187
3192
|
}
|
|
@@ -3343,7 +3348,7 @@ table caption{caption-side:top;text-align:left;margin-bottom:4pt;}
|
|
|
3343
3348
|
.doc-figure figcaption{margin-top:4pt;}
|
|
3344
3349
|
.doc-image-missing{border:1px dashed var(--matrx-print-rule,#d1d5db);padding:16pt;color:var(--matrx-print-muted,#6b7280);}
|
|
3345
3350
|
.doc-inline-img{max-height:1.2em;vertical-align:middle;}
|
|
3346
|
-
.doc-math-display{margin:0.6em 0 0.9em;text-align:center;break-inside:avoid;overflow-x:auto;}
|
|
3351
|
+
.doc-math-display{display:block;margin:0.6em 0 0.9em;text-align:center;break-inside:avoid;overflow-x:auto;}
|
|
3347
3352
|
.doc-math-display math{font-size:1.15em;}
|
|
3348
3353
|
.doc-math-tex{color:var(--matrx-print-danger,#b91c1c);}
|
|
3349
3354
|
.doc-task-list{list-style:none;padding-left:0.2em;}
|
|
@@ -3422,7 +3427,7 @@ blockquote{margin:0 0 0.8em;padding-left:1em;border-left:3px solid #d1d5db;color
|
|
|
3422
3427
|
.doc-cover-logo{max-height:5em;}
|
|
3423
3428
|
.doc-cover-title{font-size:2em;}
|
|
3424
3429
|
.matrx-page-break{page-break-after:always;break-after:page;}
|
|
3425
|
-
.doc-math-display{margin:0.6em 0;text-align:center;}
|
|
3430
|
+
.doc-math-display{display:block;margin:0.6em 0;text-align:center;}
|
|
3426
3431
|
`.trim();
|
|
3427
3432
|
function extOf(mime) {
|
|
3428
3433
|
return mime === "image/png" ? "png" : mime === "image/gif" ? "gif" : "jpg";
|
|
@@ -4712,6 +4717,70 @@ function removeThinkingContent(content) {
|
|
|
4712
4717
|
return result.trim();
|
|
4713
4718
|
}
|
|
4714
4719
|
var PAGE_BREAK_HTML = `<div class="${PAGE_BREAK_CLASS}" role="separator" aria-label="${PAGE_BREAK_LABEL}" data-label="${PAGE_BREAK_LABEL}"></div>`;
|
|
4720
|
+
var CODE_ARTIFACT_LANGUAGE = {
|
|
4721
|
+
html: "html",
|
|
4722
|
+
react: "tsx",
|
|
4723
|
+
svg: "svg",
|
|
4724
|
+
mermaid: "mermaid",
|
|
4725
|
+
diff: "diff",
|
|
4726
|
+
iframe: "html",
|
|
4727
|
+
code: ""
|
|
4728
|
+
};
|
|
4729
|
+
function parseTagAttributes(tag) {
|
|
4730
|
+
const attrs = {};
|
|
4731
|
+
for (const m of tag.matchAll(/([a-zA-Z_][\w-]*)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)) {
|
|
4732
|
+
attrs[m[1].toLowerCase()] = m[2] ?? m[3] ?? "";
|
|
4733
|
+
}
|
|
4734
|
+
return attrs;
|
|
4735
|
+
}
|
|
4736
|
+
function unwrapArtifactsToMarkdown(markdown) {
|
|
4737
|
+
if (!/<artifact\b/i.test(markdown)) return markdown;
|
|
4738
|
+
return markdown.split(/(^[ \t]*(?:`{3,}|~{3,})[\s\S]*?^[ \t]*(?:`{3,}|~{3,})[ \t]*$)/m).map(
|
|
4739
|
+
(part, i) => i % 2 === 1 ? part : part.replace(/<artifact\b((?:[^>"']|"[^"]*"|'[^']*')*?)>([\s\S]*?)<\/artifact>/gi, (_m, tag, body) => {
|
|
4740
|
+
const attrs = parseTagAttributes(tag);
|
|
4741
|
+
const type = (attrs.type ?? "").toLowerCase();
|
|
4742
|
+
const trimmed = body.replace(/^\n+|\n+$/g, "");
|
|
4743
|
+
if (!trimmed.trim()) return "";
|
|
4744
|
+
if (/^\s*(`{3,}|~{3,})/.test(trimmed)) return `
|
|
4745
|
+
|
|
4746
|
+
${trimmed}
|
|
4747
|
+
|
|
4748
|
+
`;
|
|
4749
|
+
if (type in CODE_ARTIFACT_LANGUAGE) {
|
|
4750
|
+
const lang = CODE_ARTIFACT_LANGUAGE[type] || attrs.language || attrs.lang || "";
|
|
4751
|
+
return `
|
|
4752
|
+
|
|
4753
|
+
\`\`\`\`${lang}
|
|
4754
|
+
${trimmed}
|
|
4755
|
+
\`\`\`\`
|
|
4756
|
+
|
|
4757
|
+
`;
|
|
4758
|
+
}
|
|
4759
|
+
if (looksLikeJson(trimmed)) return `
|
|
4760
|
+
|
|
4761
|
+
\`\`\`\`json
|
|
4762
|
+
${JSON.stringify(JSON.parse(trimmed), null, 2)}
|
|
4763
|
+
\`\`\`\`
|
|
4764
|
+
|
|
4765
|
+
`;
|
|
4766
|
+
return `
|
|
4767
|
+
|
|
4768
|
+
${trimmed}
|
|
4769
|
+
|
|
4770
|
+
`;
|
|
4771
|
+
})
|
|
4772
|
+
).join("");
|
|
4773
|
+
}
|
|
4774
|
+
function looksLikeJson(body) {
|
|
4775
|
+
const t = body.trim();
|
|
4776
|
+
if (!/^[[{]/.test(t)) return false;
|
|
4777
|
+
try {
|
|
4778
|
+
JSON.parse(t);
|
|
4779
|
+
return true;
|
|
4780
|
+
} catch {
|
|
4781
|
+
return false;
|
|
4782
|
+
}
|
|
4783
|
+
}
|
|
4715
4784
|
var LINK_URL = String.raw`((?:[^()\s]|\([^()\s]*\))+)(?:\s+"[^"]*")?`;
|
|
4716
4785
|
var IMAGE_RE = new RegExp(String.raw`!\[([^\]]*)\]\(` + LINK_URL + String.raw`\)`, "g");
|
|
4717
4786
|
var LINK_RE = new RegExp(String.raw`\[([^\]]+)\]\(` + LINK_URL + String.raw`\)`, "g");
|
|
@@ -5166,7 +5235,7 @@ function parseDocument(source, options = {}) {
|
|
|
5166
5235
|
const settings = resolveSettings(fm.data, sink, options);
|
|
5167
5236
|
for (const n of sink) notify(n);
|
|
5168
5237
|
const body = removeThinkingContent(fm.body);
|
|
5169
|
-
const lifted = extractMath(body);
|
|
5238
|
+
const lifted = extractMath(unwrapArtifactsToMarkdown(body));
|
|
5170
5239
|
const root = fromMarkdown(prepass(lifted.text), {
|
|
5171
5240
|
extensions: [gfm()],
|
|
5172
5241
|
mdastExtensions: [gfmFromMarkdown()]
|