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.
@@ -13427,10 +13427,45 @@ var markdown2typstLib = (() => {
13427
13427
  }
13428
13428
  }
13429
13429
 
13430
+ // src/remark-fix-math.ts
13431
+ function remarkFixAdjacentMath() {
13432
+ return (tree) => {
13433
+ visit(tree, "math", (node2) => {
13434
+ let value2 = node2.value || "";
13435
+ const meta = node2.meta;
13436
+ if (meta) {
13437
+ value2 = meta + (value2 ? "\n" + value2 : "");
13438
+ node2.meta = null;
13439
+ }
13440
+ const match = value2.match(/\$\$/);
13441
+ if (match) {
13442
+ const splitIndex = match.index;
13443
+ const mathContent = value2.substring(0, splitIndex);
13444
+ const remainder = value2.substring(splitIndex + 2);
13445
+ node2.value = mathContent.trim();
13446
+ if (remainder.trim().length > 0) {
13447
+ const processor = unified().use(remarkParse);
13448
+ const remainderAst = processor.parse(remainder.trim());
13449
+ node2.data = node2.data || {};
13450
+ node2.data.insertAfter = remainderAst.children;
13451
+ }
13452
+ } else {
13453
+ node2.value = value2.trim();
13454
+ }
13455
+ });
13456
+ visit(tree, (node2, index2, parent) => {
13457
+ if (node2.data && node2.data.insertAfter && parent && index2 !== void 0) {
13458
+ parent.children.splice(index2 + 1, 0, ...node2.data.insertAfter);
13459
+ delete node2.data.insertAfter;
13460
+ }
13461
+ });
13462
+ };
13463
+ }
13464
+
13430
13465
  // src/parser.ts
13431
13466
  function parseMarkdown(markdown, onError) {
13432
13467
  try {
13433
- const processor = unified().use(remarkParse).use(remarkFrontmatter, ["yaml"]).use(remarkGfm, { singleTilde: false }).use(remarkMath);
13468
+ const processor = unified().use(remarkParse).use(remarkFrontmatter, ["yaml"]).use(remarkGfm, { singleTilde: false }).use(remarkMath).use(remarkFixAdjacentMath);
13434
13469
  const parsedTree = processor.parse(markdown);
13435
13470
  const tree = processor.runSync(parsedTree);
13436
13471
  return tree;
@@ -20090,15 +20125,7 @@ var markdown2typstLib = (() => {
20090
20125
  }
20091
20126
  }
20092
20127
  function renderMathBlock(node2, indentLevel, context) {
20093
- let rawLatex = node2.value || "";
20094
- const meta = node2.meta;
20095
- if (meta) {
20096
- rawLatex = meta + (rawLatex ? "\n" + rawLatex : "");
20097
- }
20098
- if (rawLatex.endsWith("$$")) {
20099
- rawLatex = rawLatex.slice(0, -2);
20100
- }
20101
- const value2 = rawLatex.trim();
20128
+ const value2 = node2.value.trim();
20102
20129
  try {
20103
20130
  const typstMath = tex2typst(value2);
20104
20131
  return indentLines(`$ ${typstMath} $`, indentLevel);