@incremark/core 0.1.2 → 0.2.0

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,217 +0,0 @@
1
- import { RootContent, Root } from 'mdast';
2
- import { Extension } from 'micromark-util-types';
3
- import { Extension as Extension$1 } from 'mdast-util-from-markdown';
4
-
5
- /**
6
- * 解析块的状态
7
- */
8
- type BlockStatus = 'pending' | 'stable' | 'completed';
9
- /**
10
- * AST 节点的通用接口(用于遍历)
11
- * 统一定义,避免各模块重复声明
12
- */
13
- interface AstNode {
14
- type: string;
15
- value?: string;
16
- children?: AstNode[];
17
- [key: string]: unknown;
18
- }
19
- /**
20
- * 解析出的块
21
- */
22
- interface ParsedBlock {
23
- /** 块的唯一 ID */
24
- id: string;
25
- /** 块状态 */
26
- status: BlockStatus;
27
- /** AST 节点 */
28
- node: RootContent;
29
- /** 原始文本起始位置(相对于完整文档) */
30
- startOffset: number;
31
- /** 原始文本结束位置 */
32
- endOffset: number;
33
- /** 原始文本内容 */
34
- rawText: string;
35
- }
36
- /**
37
- * 增量更新事件
38
- */
39
- interface IncrementalUpdate {
40
- /** 新完成的块 */
41
- completed: ParsedBlock[];
42
- /** 更新的块(内容变化) */
43
- updated: ParsedBlock[];
44
- /** 当前正在解析中的块(可能不完整) */
45
- pending: ParsedBlock[];
46
- /** 完整的 AST(包含所有已解析的内容) */
47
- ast: Root;
48
- }
49
- /**
50
- * 容器语法配置
51
- */
52
- interface ContainerConfig {
53
- /** 容器标记字符,默认 ':' */
54
- marker?: string;
55
- /** 最小标记长度,默认 3 */
56
- minMarkerLength?: number;
57
- /** 允许的容器名称(如 ['warning', 'info', 'youtube']),undefined 表示允许所有 */
58
- allowedNames?: string[];
59
- }
60
- /**
61
- * 解析器状态变化事件
62
- */
63
- interface ParserState {
64
- /** 已完成的块 */
65
- completedBlocks: ParsedBlock[];
66
- /** 待处理的块 */
67
- pendingBlocks: ParsedBlock[];
68
- /** 完整的 Markdown 内容 */
69
- markdown: string;
70
- /** 完整的 AST */
71
- ast: Root;
72
- }
73
- /**
74
- * 解析器配置
75
- */
76
- interface ParserOptions {
77
- /** 启用 GFM 扩展(表格、任务列表等) */
78
- gfm?: boolean;
79
- /**
80
- * 启用 ::: 容器语法支持(用于边界检测)
81
- * - false: 禁用(默认)
82
- * - true: 使用默认配置启用
83
- * - ContainerConfig: 使用自定义配置启用
84
- */
85
- containers?: boolean | ContainerConfig;
86
- /** 自定义块边界检测函数 */
87
- blockBoundaryDetector?: (content: string, position: number) => boolean;
88
- /** 自定义 micromark 扩展(如 directive) */
89
- extensions?: Extension[];
90
- /** 自定义 mdast 扩展(如 directiveFromMarkdown) */
91
- mdastExtensions?: Extension$1[];
92
- /** 状态变化回调 */
93
- onChange?: (state: ParserState) => void;
94
- }
95
- /**
96
- * 块上下文
97
- */
98
- interface BlockContext {
99
- /** 当前是否在代码块中 */
100
- inFencedCode: boolean;
101
- /** 代码块的 fence 字符(` 或 ~) */
102
- fenceChar?: string;
103
- /** 代码块的 fence 长度 */
104
- fenceLength?: number;
105
- /** 当前列表嵌套深度 */
106
- listDepth: number;
107
- /** 当前引用嵌套深度 */
108
- blockquoteDepth: number;
109
- /** 当前是否在容器块中 */
110
- inContainer: boolean;
111
- /** 容器的标记长度 */
112
- containerMarkerLength?: number;
113
- /** 容器名称 */
114
- containerName?: string;
115
- /** 容器嵌套深度(支持嵌套容器) */
116
- containerDepth: number;
117
- }
118
- /**
119
- * 容器检测结果
120
- */
121
- interface ContainerMatch {
122
- /** 容器名称 */
123
- name: string;
124
- /** 标记长度(冒号数量) */
125
- markerLength: number;
126
- /** 是否是结束标记 */
127
- isEnd: boolean;
128
- }
129
- /**
130
- * 块类型检测结果
131
- */
132
- interface BlockTypeInfo {
133
- type: string;
134
- /** 是否是容器节点(可以包含其他块) */
135
- isContainer: boolean;
136
- /** 是否需要显式关闭(如代码块) */
137
- requiresClosing: boolean;
138
- /** 关闭模式 */
139
- closingPattern?: RegExp;
140
- }
141
-
142
- /**
143
- * 块类型检测与边界判断
144
- *
145
- * Markdown 块级元素的识别规则
146
- */
147
-
148
- /**
149
- * 检测行是否是代码块 fence 开始
150
- */
151
- declare function detectFenceStart(line: string): {
152
- char: string;
153
- length: number;
154
- } | null;
155
- /**
156
- * 检测行是否是代码块 fence 结束
157
- */
158
- declare function detectFenceEnd(line: string, context: BlockContext): boolean;
159
- /**
160
- * 检测是否是空行或仅包含空白字符
161
- */
162
- declare function isEmptyLine(line: string): boolean;
163
- /**
164
- * 检测是否是标题行
165
- */
166
- declare function isHeading(line: string): boolean;
167
- /**
168
- * 检测是否是 thematic break(水平线)
169
- */
170
- declare function isThematicBreak(line: string): boolean;
171
- /**
172
- * 检测是否是列表项开始
173
- */
174
- declare function isListItemStart(line: string): {
175
- ordered: boolean;
176
- indent: number;
177
- } | null;
178
- /**
179
- * 检测是否是引用块开始
180
- */
181
- declare function isBlockquoteStart(line: string): boolean;
182
- /**
183
- * 检测是否是 HTML 块
184
- */
185
- declare function isHtmlBlock(line: string): boolean;
186
- /**
187
- * 检测表格分隔行
188
- */
189
- declare function isTableDelimiter(line: string): boolean;
190
- /**
191
- * 检测容器开始或结束
192
- *
193
- * 支持格式:
194
- * - ::: name 开始
195
- * - ::: name attr 开始(带属性)
196
- * - ::: 结束
197
- * - :::::: name 开始(更长的标记,用于嵌套)
198
- */
199
- declare function detectContainer(line: string, config?: ContainerConfig): ContainerMatch | null;
200
- /**
201
- * 检测容器结束
202
- */
203
- declare function detectContainerEnd(line: string, context: BlockContext, config?: ContainerConfig): boolean;
204
- /**
205
- * 判断两行之间是否构成块边界
206
- */
207
- declare function isBlockBoundary(prevLine: string, currentLine: string, context: BlockContext): boolean;
208
- /**
209
- * 创建初始上下文
210
- */
211
- declare function createInitialContext(): BlockContext;
212
- /**
213
- * 更新上下文(处理一行后)
214
- */
215
- declare function updateContext(line: string, context: BlockContext, containerConfig?: ContainerConfig | boolean): BlockContext;
216
-
217
- export { type AstNode as A, type BlockStatus as B, type ContainerConfig as C, type IncrementalUpdate as I, type ParserOptions as P, type ParsedBlock as a, type ParserState as b, type BlockContext as c, type ContainerMatch as d, type BlockTypeInfo as e, detectFenceStart as f, detectFenceEnd as g, isHeading as h, isEmptyLine as i, isThematicBreak as j, isListItemStart as k, isBlockquoteStart as l, isHtmlBlock as m, isTableDelimiter as n, detectContainer as o, detectContainerEnd as p, isBlockBoundary as q, createInitialContext as r, updateContext as u };