markdown2typst 0.1.6 → 0.1.7
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/markdown2typst.browser.js +37 -10
- package/dist/markdown2typst.browser.js.map +4 -4
- package/dist/markdown2typst.browser.min.js +47 -47
- package/dist/markdown2typst.js +37 -10
- package/dist/markdown2typst.js.map +4 -4
- package/dist/markdown2typst.min.js +47 -47
- package/package.json +1 -1
- package/src/block-renderer.ts +1 -15
- package/src/parser.ts +3 -1
- package/src/remark-fix-math.ts +59 -0
package/dist/markdown2typst.js
CHANGED
|
@@ -13415,10 +13415,45 @@ function remarkParse(options) {
|
|
|
13415
13415
|
}
|
|
13416
13416
|
}
|
|
13417
13417
|
|
|
13418
|
+
// src/remark-fix-math.ts
|
|
13419
|
+
function remarkFixAdjacentMath() {
|
|
13420
|
+
return (tree) => {
|
|
13421
|
+
visit(tree, "math", (node2) => {
|
|
13422
|
+
let value2 = node2.value || "";
|
|
13423
|
+
const meta = node2.meta;
|
|
13424
|
+
if (meta) {
|
|
13425
|
+
value2 = meta + (value2 ? "\n" + value2 : "");
|
|
13426
|
+
node2.meta = null;
|
|
13427
|
+
}
|
|
13428
|
+
const match = value2.match(/\$\$/);
|
|
13429
|
+
if (match) {
|
|
13430
|
+
const splitIndex = match.index;
|
|
13431
|
+
const mathContent = value2.substring(0, splitIndex);
|
|
13432
|
+
const remainder = value2.substring(splitIndex + 2);
|
|
13433
|
+
node2.value = mathContent.trim();
|
|
13434
|
+
if (remainder.trim().length > 0) {
|
|
13435
|
+
const processor = unified().use(remarkParse);
|
|
13436
|
+
const remainderAst = processor.parse(remainder.trim());
|
|
13437
|
+
node2.data = node2.data || {};
|
|
13438
|
+
node2.data.insertAfter = remainderAst.children;
|
|
13439
|
+
}
|
|
13440
|
+
} else {
|
|
13441
|
+
node2.value = value2.trim();
|
|
13442
|
+
}
|
|
13443
|
+
});
|
|
13444
|
+
visit(tree, (node2, index2, parent) => {
|
|
13445
|
+
if (node2.data && node2.data.insertAfter && parent && index2 !== void 0) {
|
|
13446
|
+
parent.children.splice(index2 + 1, 0, ...node2.data.insertAfter);
|
|
13447
|
+
delete node2.data.insertAfter;
|
|
13448
|
+
}
|
|
13449
|
+
});
|
|
13450
|
+
};
|
|
13451
|
+
}
|
|
13452
|
+
|
|
13418
13453
|
// src/parser.ts
|
|
13419
13454
|
function parseMarkdown(markdown, onError) {
|
|
13420
13455
|
try {
|
|
13421
|
-
const processor = unified().use(remarkParse).use(remarkFrontmatter, ["yaml"]).use(remarkGfm, { singleTilde: false }).use(remarkMath);
|
|
13456
|
+
const processor = unified().use(remarkParse).use(remarkFrontmatter, ["yaml"]).use(remarkGfm, { singleTilde: false }).use(remarkMath).use(remarkFixAdjacentMath);
|
|
13422
13457
|
const parsedTree = processor.parse(markdown);
|
|
13423
13458
|
const tree = processor.runSync(parsedTree);
|
|
13424
13459
|
return tree;
|
|
@@ -20078,15 +20113,7 @@ function renderBlock(node2, indentLevel, context) {
|
|
|
20078
20113
|
}
|
|
20079
20114
|
}
|
|
20080
20115
|
function renderMathBlock(node2, indentLevel, context) {
|
|
20081
|
-
|
|
20082
|
-
const meta = node2.meta;
|
|
20083
|
-
if (meta) {
|
|
20084
|
-
rawLatex = meta + (rawLatex ? "\n" + rawLatex : "");
|
|
20085
|
-
}
|
|
20086
|
-
if (rawLatex.endsWith("$$")) {
|
|
20087
|
-
rawLatex = rawLatex.slice(0, -2);
|
|
20088
|
-
}
|
|
20089
|
-
const value2 = rawLatex.trim();
|
|
20116
|
+
const value2 = node2.value.trim();
|
|
20090
20117
|
try {
|
|
20091
20118
|
const typstMath = tex2typst(value2);
|
|
20092
20119
|
return indentLines(`$ ${typstMath} $`, indentLevel);
|