@incremark/core 0.2.7 → 0.3.1

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.
@@ -0,0 +1,128 @@
1
+ import { Root, RootContent } from 'mdast';
2
+ import { Extension } from 'micromark-util-types';
3
+ import { Extension as Extension$1 } from 'mdast-util-from-markdown';
4
+ import { MarkedExtension } from 'marked';
5
+ import { b as ParserOptions, C as ContainerConfig, B as BlockStatus, P as ParsedBlock } from './index-CWuosVAK.js';
6
+
7
+ /**
8
+ * AST 构建器统一接口和类型定义
9
+ *
10
+ * 支持两种引擎:
11
+ * - marked: 极速模式,速度更快
12
+ * - micromark: 稳定模式,更可靠,支持 div 内嵌 markdown
13
+ */
14
+
15
+ /**
16
+ * 引擎类型
17
+ */
18
+ type EngineType = 'marked' | 'micromark';
19
+ /**
20
+ * AST 构建器接口
21
+ * 所有引擎实现必须遵循此接口
22
+ */
23
+ interface IAstBuilder {
24
+ /** 容器配置(用于边界检测) */
25
+ readonly containerConfig: ContainerConfig | undefined;
26
+ /**
27
+ * 解析文本为 AST
28
+ * @param text Markdown 文本
29
+ * @returns AST
30
+ */
31
+ parse(text: string): Root;
32
+ /**
33
+ * 将 AST 节点转换为 ParsedBlock
34
+ */
35
+ nodesToBlocks(nodes: RootContent[], startOffset: number, rawText: string, status: BlockStatus, generateBlockId: () => string): ParsedBlock[];
36
+ /**
37
+ * 更新配置选项(动态更新,不需要重建实例)
38
+ * @param options 部分配置选项
39
+ */
40
+ updateOptions(options: Partial<EngineParserOptions>): void;
41
+ }
42
+ /**
43
+ * Marked 引擎扩展配置
44
+ */
45
+ interface MarkedEngineExtension {
46
+ /** marked 扩展列表 */
47
+ extensions: MarkedExtension[];
48
+ }
49
+ /**
50
+ * Micromark 引擎扩展配置
51
+ */
52
+ interface MicromarkEngineExtension {
53
+ /** micromark 语法扩展 */
54
+ extensions: Extension[];
55
+ /** mdast 转换扩展 */
56
+ mdastExtensions: Extension$1[];
57
+ }
58
+ /**
59
+ * 统一插件格式
60
+ *
61
+ * 插件可以同时支持多个引擎,运行时会根据当前引擎选择对应配置
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const myPlugin: IncremarkPlugin = {
66
+ * name: 'my-plugin',
67
+ * type: 'both', // 支持两种引擎
68
+ * marked: {
69
+ * extensions: [myMarkedExtension]
70
+ * },
71
+ * micromark: {
72
+ * extensions: [myMicromarkExt],
73
+ * mdastExtensions: [myMdastExt]
74
+ * }
75
+ * }
76
+ * ```
77
+ */
78
+ interface IncremarkPlugin {
79
+ /** 插件名称 */
80
+ name: string;
81
+ /**
82
+ * 插件支持的引擎类型
83
+ * - 'marked': 仅支持 marked 引擎
84
+ * - 'micromark': 仅支持 micromark 引擎
85
+ * - 'both': 同时支持两种引擎
86
+ */
87
+ type: 'marked' | 'micromark' | 'both';
88
+ /**
89
+ * Marked 引擎配置
90
+ * 当 type 为 'marked' 或 'both' 时必须提供
91
+ */
92
+ marked?: MarkedEngineExtension;
93
+ /**
94
+ * Micromark 引擎配置
95
+ * 当 type 为 'micromark' 或 'both' 时必须提供
96
+ */
97
+ micromark?: MicromarkEngineExtension;
98
+ }
99
+ /**
100
+ * 引擎特定的解析器选项
101
+ *
102
+ * 注意:不再包含 engine 选项,引擎切换通过注入 astBuilder 类实现
103
+ * 这样可以确保 tree-shaking 正常工作
104
+ */
105
+ interface EngineParserOptions extends Omit<ParserOptions, 'extensions' | 'mdastExtensions'> {
106
+ /**
107
+ * 统一插件列表
108
+ * 插件会根据当前引擎自动选择对应的扩展配置
109
+ */
110
+ plugins?: IncremarkPlugin[];
111
+ /**
112
+ * Micromark 扩展(仅 micromark 引擎使用)
113
+ * @deprecated 建议使用 plugins 统一配置
114
+ */
115
+ extensions?: Extension[];
116
+ /**
117
+ * Mdast 扩展(仅 micromark 引擎使用)
118
+ * @deprecated 建议使用 plugins 统一配置
119
+ */
120
+ mdastExtensions?: Extension$1[];
121
+ /**
122
+ * Marked 扩展(仅 marked 引擎使用)
123
+ * @deprecated 建议使用 plugins 统一配置
124
+ */
125
+ markedExtensions?: MarkedExtension[];
126
+ }
127
+
128
+ export type { EngineParserOptions as E, IAstBuilder as I, MarkedEngineExtension as M, EngineType as a, IncremarkPlugin as b, MicromarkEngineExtension as c };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@incremark/core",
3
- "version": "0.2.7",
4
- "description": "增量式 Markdown 解析器核心库",
3
+ "version": "0.3.1",
4
+ "description": "High-performance incremental markdown parser specifically designed for AI streaming output scenarios.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -18,6 +18,14 @@
18
18
  "./utils": {
19
19
  "types": "./dist/utils/index.d.ts",
20
20
  "import": "./dist/utils/index.js"
21
+ },
22
+ "./engines/marked": {
23
+ "types": "./dist/engines/marked/index.d.ts",
24
+ "import": "./dist/engines/marked/index.js"
25
+ },
26
+ "./engines/micromark": {
27
+ "types": "./dist/engines/micromark/index.d.ts",
28
+ "import": "./dist/engines/micromark/index.js"
21
29
  }
22
30
  },
23
31
  "files": [
@@ -27,6 +35,7 @@
27
35
  "@types/lodash-es": "^4.17.12",
28
36
  "@types/mdast": "^4.0.0",
29
37
  "lodash-es": "^4.17.22",
38
+ "marked": "^17.0.1",
30
39
  "mdast-util-directive": "^3.0.0",
31
40
  "mdast-util-from-markdown": "^2.0.0",
32
41
  "mdast-util-gfm": "^3.0.0",
@@ -38,6 +47,7 @@
38
47
  "micromark-extension-math": "^3.0.0",
39
48
  "micromark-factory-destination": "^2.0.0",
40
49
  "micromark-factory-label": "^2.0.0",
50
+ "micromark-factory-space": "^2.0.0",
41
51
  "micromark-factory-title": "^2.0.0",
42
52
  "micromark-factory-whitespace": "^2.0.0",
43
53
  "micromark-util-character": "^2.0.0",
@@ -55,8 +65,13 @@
55
65
  "incremental",
56
66
  "streaming",
57
67
  "ai",
68
+ "chatgpt",
69
+ "llm",
58
70
  "mdast",
59
- "unified"
71
+ "high-performance",
72
+ "typewriter",
73
+ "micromark",
74
+ "marked"
60
75
  ],
61
76
  "license": "MIT",
62
77
  "repository": {