@incremark/core 0.3.0 → 0.3.2

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.
@@ -1,6 +1,6 @@
1
1
  import { Root, RootContent } from 'mdast';
2
- import { C as ContainerConfig, H as HtmlTreeExtensionOptions, B as BlockStatus, P as ParsedBlock } from './index-mZ7yCqNH.js';
3
- import { I as IAstBuilder, E as EngineParserOptions } from './types-C_EW5vfp.js';
2
+ import { C as ContainerConfig, H as HtmlTreeExtensionOptions, B as BlockStatus, P as ParsedBlock } from './index-CWuosVAK.js';
3
+ import { I as IAstBuilder, E as EngineParserOptions } from './types-B7GTGJc2.js';
4
4
 
5
5
  /**
6
6
  * Marked AST 构建器(极速模式)
@@ -62,7 +62,12 @@ declare class MarkedAstBuilder implements IAstBuilder {
62
62
  /**
63
63
  * 将 AST 节点转换为 ParsedBlock
64
64
  */
65
- nodesToBlocks(nodes: RootContent[], startOffset: number, rawText: string, status: BlockStatus, generateBlockId: () => string): ParsedBlock[];
65
+ nodesToBlocks(nodes: RootContent[], startOffset: number, rawText: string, status: BlockStatus, generateBlockId: (startOffset: number) => string): ParsedBlock[];
66
+ /**
67
+ * 更新配置选项
68
+ * @param options 部分配置选项
69
+ */
70
+ updateOptions(options: Partial<EngineParserOptions>): void;
66
71
  }
67
72
  /**
68
73
  * AstBuilder 别名(向后兼容)
@@ -1,4 +1,4 @@
1
- import { c as BlockContext, C as ContainerConfig, d as ContainerMatch } from '../index-mZ7yCqNH.js';
1
+ import { c as BlockContext, C as ContainerConfig, d as ContainerMatch } from '../index-CWuosVAK.js';
2
2
  import 'mdast';
3
3
  import 'micromark-util-types';
4
4
  import 'mdast-util-from-markdown';
@@ -1,9 +1,9 @@
1
- import { M as MarkedAstBuilder } from '../../MarkedAstBuildter-BsjxZko_.js';
2
- export { A as AstBuilder } from '../../MarkedAstBuildter-BsjxZko_.js';
3
- import { E as EngineParserOptions } from '../../types-C_EW5vfp.js';
4
- export { I as IAstBuilder, b as IncremarkPlugin, M as MarkedEngineExtension } from '../../types-C_EW5vfp.js';
1
+ import { M as MarkedAstBuilder } from '../../MarkedAstBuildter-B2QhLKKy.js';
2
+ export { A as AstBuilder } from '../../MarkedAstBuildter-B2QhLKKy.js';
3
+ import { E as EngineParserOptions } from '../../types-B7GTGJc2.js';
4
+ export { I as IAstBuilder, b as IncremarkPlugin, M as MarkedEngineExtension } from '../../types-B7GTGJc2.js';
5
5
  import 'mdast';
6
- import '../../index-mZ7yCqNH.js';
6
+ import '../../index-CWuosVAK.js';
7
7
  import 'micromark-util-types';
8
8
  import 'mdast-util-from-markdown';
9
9
  import 'marked';
@@ -599,24 +599,48 @@ function createOptimisticReferenceExtension() {
599
599
  }
600
600
 
601
601
  // src/extensions/marked-extensions/mathExtension.ts
602
- function createBlockMathExtension() {
602
+ function resolveOptions(options) {
603
+ return {
604
+ tex: options?.tex ?? false
605
+ };
606
+ }
607
+ function createBlockMathExtension(options) {
608
+ const resolved = resolveOptions(options);
603
609
  return {
604
610
  name: "blockMath",
605
611
  level: "block",
606
612
  start(src) {
607
- const match = src.match(/^ {0,3}\$\$/m);
608
- return match?.index;
613
+ const dollarMatch = src.match(/^ {0,3}\$\$/m);
614
+ let bracketMatch = null;
615
+ if (resolved.tex) {
616
+ bracketMatch = src.match(/^ {0,3}\\\[/m);
617
+ }
618
+ if (dollarMatch && bracketMatch) {
619
+ return Math.min(dollarMatch.index, bracketMatch.index);
620
+ }
621
+ return dollarMatch?.index ?? bracketMatch?.index;
609
622
  },
610
623
  tokenizer(src) {
611
- const rule = /^ {0,3}\$\$([\s\S]*?)\$\$ *(?:\n+|$)/;
612
- const match = rule.exec(src);
613
- if (match) {
624
+ const dollarRule = /^ {0,3}\$\$([\s\S]*?)\$\$ *(?:\n+|$)/;
625
+ const dollarMatch = dollarRule.exec(src);
626
+ if (dollarMatch) {
614
627
  return {
615
628
  type: "blockMath",
616
- raw: match[0],
617
- text: match[1].trim()
629
+ raw: dollarMatch[0],
630
+ text: dollarMatch[1].trim()
618
631
  };
619
632
  }
633
+ if (resolved.tex) {
634
+ const bracketRule = /^ {0,3}\\\[([\s\S]*?)\\\] *(?:\n+|$)/;
635
+ const bracketMatch = bracketRule.exec(src);
636
+ if (bracketMatch) {
637
+ return {
638
+ type: "blockMath",
639
+ raw: bracketMatch[0],
640
+ text: bracketMatch[1].trim()
641
+ };
642
+ }
643
+ }
620
644
  return void 0;
621
645
  },
622
646
  renderer() {
@@ -624,26 +648,46 @@ function createBlockMathExtension() {
624
648
  }
625
649
  };
626
650
  }
627
- function createInlineMathExtension() {
651
+ function createInlineMathExtension(options) {
652
+ const resolved = resolveOptions(options);
628
653
  return {
629
654
  name: "inlineMath",
630
655
  level: "inline",
631
656
  start(src) {
632
- const index = src.indexOf("$");
633
- if (index === -1) return void 0;
634
- if (src[index + 1] === "$") return void 0;
635
- return index;
657
+ const dollarIndex = src.indexOf("$");
658
+ const validDollarIndex = dollarIndex !== -1 && src[dollarIndex + 1] !== "$" ? dollarIndex : -1;
659
+ let parenIndex = -1;
660
+ if (resolved.tex) {
661
+ parenIndex = src.indexOf("\\(");
662
+ }
663
+ if (validDollarIndex !== -1 && parenIndex !== -1) {
664
+ return Math.min(validDollarIndex, parenIndex);
665
+ }
666
+ if (validDollarIndex !== -1) return validDollarIndex;
667
+ if (parenIndex !== -1) return parenIndex;
668
+ return void 0;
636
669
  },
637
670
  tokenizer(src) {
638
- const rule = /^\$(?!\$)((?:\\.|[^\\\n$])+?)\$(?!\d)/;
639
- const match = rule.exec(src);
640
- if (match) {
671
+ const dollarRule = /^\$(?!\$)((?:\\.|[^\\\n$])+?)\$(?!\d)/;
672
+ const dollarMatch = dollarRule.exec(src);
673
+ if (dollarMatch) {
641
674
  return {
642
675
  type: "inlineMath",
643
- raw: match[0],
644
- text: match[1].trim()
676
+ raw: dollarMatch[0],
677
+ text: dollarMatch[1].trim()
645
678
  };
646
679
  }
680
+ if (resolved.tex) {
681
+ const parenRule = /^\\\(([\s\S]*?)\\\)/;
682
+ const parenMatch = parenRule.exec(src);
683
+ if (parenMatch) {
684
+ return {
685
+ type: "inlineMath",
686
+ raw: parenMatch[0],
687
+ text: parenMatch[1].trim()
688
+ };
689
+ }
690
+ }
647
691
  return void 0;
648
692
  },
649
693
  renderer() {
@@ -1301,8 +1345,9 @@ var MarkedAstBuilder = class {
1301
1345
  const inlineExts = [optimisticRefExt.tokenizer, ...userInlineExts];
1302
1346
  const inlineStartExts = [optimisticRefExt.start, ...userInlineStartExts];
1303
1347
  if (this.options.math) {
1304
- const blockMathExt = createBlockMathExtension();
1305
- const inlineMathExt = createInlineMathExtension();
1348
+ const mathOptions = typeof this.options.math === "object" ? this.options.math : {};
1349
+ const blockMathExt = createBlockMathExtension(mathOptions);
1350
+ const inlineMathExt = createInlineMathExtension(mathOptions);
1306
1351
  blockExts.unshift(blockMathExt.tokenizer);
1307
1352
  blockStartExts.unshift(blockMathExt.start);
1308
1353
  inlineExts.unshift(inlineMathExt.tokenizer);
@@ -1518,7 +1563,7 @@ var MarkedAstBuilder = class {
1518
1563
  const absoluteStart = startOffset + relativeStart;
1519
1564
  const absoluteEnd = startOffset + relativeEnd;
1520
1565
  blocks.push({
1521
- id: generateBlockId(),
1566
+ id: generateBlockId(absoluteStart),
1522
1567
  status,
1523
1568
  node,
1524
1569
  startOffset: absoluteStart,
@@ -1528,6 +1573,28 @@ var MarkedAstBuilder = class {
1528
1573
  }
1529
1574
  return blocks;
1530
1575
  }
1576
+ /**
1577
+ * 更新配置选项
1578
+ * @param options 部分配置选项
1579
+ */
1580
+ updateOptions(options) {
1581
+ Object.assign(this.options, options);
1582
+ if ("containers" in options) {
1583
+ this.containerConfig = typeof options.containers === "object" ? options.containers : options.containers === true ? {} : void 0;
1584
+ }
1585
+ if ("htmlTree" in options) {
1586
+ this.htmlTreeOptions = typeof options.htmlTree === "object" ? options.htmlTree : options.htmlTree === true ? {} : void 0;
1587
+ }
1588
+ if (options.plugins || options.markedExtensions) {
1589
+ this.userExtensions.length = 0;
1590
+ if (options.plugins) {
1591
+ this.userExtensions.push(...extractMarkedExtensions(options.plugins));
1592
+ }
1593
+ if (options.markedExtensions) {
1594
+ this.userExtensions.push(...options.markedExtensions);
1595
+ }
1596
+ }
1597
+ }
1531
1598
  };
1532
1599
  var AstBuilder = MarkedAstBuilder;
1533
1600