stream-markdown-parser 0.0.13 → 0.0.15
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/README.md +12 -9
- package/README.zh-CN.md +11 -9
- package/dist/index.d.ts +22 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +82 -14
- package/dist/index.js.map +1 -1
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -19,6 +19,8 @@ This package contains the core markdown parsing logic extracted from `stream-mar
|
|
|
19
19
|
- ⚡ **Fast** - Optimized for performance
|
|
20
20
|
- 🌊 **Streaming-friendly** - Progressive parsing support
|
|
21
21
|
|
|
22
|
+
> ℹ️ We now build on top of [`markdown-it-ts`](https://www.npmjs.com/package/markdown-it-ts), a TypeScript-first distribution of markdown-it. The API stays the same, but we only rely on its parsing pipeline and ship richer typings for tokens and hooks.
|
|
23
|
+
|
|
22
24
|
## Installation
|
|
23
25
|
|
|
24
26
|
```bash
|
|
@@ -36,16 +38,17 @@ yarn add stream-markdown-parser
|
|
|
36
38
|
```typescript
|
|
37
39
|
import { getMarkdown, parseMarkdownToStructure } from 'stream-markdown-parser'
|
|
38
40
|
|
|
39
|
-
// Create a markdown-it instance with default plugins
|
|
41
|
+
// Create a markdown-it-ts instance with default plugins
|
|
40
42
|
const md = getMarkdown()
|
|
41
43
|
|
|
42
|
-
// Parse markdown to
|
|
43
|
-
const html = md.render('# Hello World\n\nThis is **bold**.')
|
|
44
|
-
|
|
45
|
-
// Or parse to AST structure
|
|
44
|
+
// Parse markdown to our streaming-friendly AST structure
|
|
46
45
|
const nodes = parseMarkdownToStructure('# Hello World', md)
|
|
47
46
|
console.log(nodes)
|
|
48
47
|
// [{ type: 'heading', level: 1, children: [...] }]
|
|
48
|
+
|
|
49
|
+
// markdown-it-ts still exposes render() if you need HTML output,
|
|
50
|
+
// but this package now focuses on the token -> AST pipeline.
|
|
51
|
+
const html = md.render?.('# Hello World\n\nThis is **bold**.')
|
|
49
52
|
```
|
|
50
53
|
|
|
51
54
|
### With Math Options
|
|
@@ -117,7 +120,7 @@ const md = getMarkdown('editor-1', {
|
|
|
117
120
|
|
|
118
121
|
#### `getMarkdown(msgId?, options?)`
|
|
119
122
|
|
|
120
|
-
Creates a configured markdown-it instance.
|
|
123
|
+
Creates a configured `markdown-it-ts` instance (API-compatible with markdown-it).
|
|
121
124
|
|
|
122
125
|
**Parameters:**
|
|
123
126
|
- `msgId` (string, optional): Unique identifier for this instance. Default: `editor-${Date.now()}`
|
|
@@ -126,7 +129,7 @@ Creates a configured markdown-it instance.
|
|
|
126
129
|
**Options:**
|
|
127
130
|
```typescript
|
|
128
131
|
interface GetMarkdownOptions {
|
|
129
|
-
// Array of markdown-it plugins to use
|
|
132
|
+
// Array of markdown-it/markdown-it-ts plugins to use
|
|
130
133
|
plugin?: Array<Plugin | [Plugin, any]>
|
|
131
134
|
|
|
132
135
|
// Array of functions to mutate the md instance
|
|
@@ -143,7 +146,7 @@ Parses markdown content into a structured node tree.
|
|
|
143
146
|
|
|
144
147
|
**Parameters:**
|
|
145
148
|
- `content` (string): The markdown content to parse
|
|
146
|
-
- `md` (
|
|
149
|
+
- `md` (MarkdownItCore, optional): A markdown-it-ts instance. If not provided, creates one using `getMarkdown()`
|
|
147
150
|
- `options` (ParseOptions, optional): Parsing options with hooks
|
|
148
151
|
|
|
149
152
|
**Returns:** `ParsedNode[]` - An array of parsed nodes
|
|
@@ -154,7 +157,7 @@ Processes raw markdown-it tokens into a flat array.
|
|
|
154
157
|
|
|
155
158
|
#### `parseInlineTokens(tokens, md)`
|
|
156
159
|
|
|
157
|
-
Parses inline markdown-it tokens.
|
|
160
|
+
Parses inline markdown-it-ts tokens.
|
|
158
161
|
|
|
159
162
|
### Configuration Functions
|
|
160
163
|
|
package/README.zh-CN.md
CHANGED
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
- ⚡ **高性能** - 性能优化
|
|
20
20
|
- 🌊 **流式友好** - 支持渐进式解析
|
|
21
21
|
|
|
22
|
+
> ℹ️ 自当前版本起我们基于 [`markdown-it-ts`](https://www.npmjs.com/package/markdown-it-ts)(一个 TypeScript 优先的 markdown-it 发行版)进行构建。API 与 markdown-it 保持一致,但内部仅依赖其解析流程,并提供更丰富的 token 类型定义。
|
|
23
|
+
|
|
22
24
|
## 安装
|
|
23
25
|
|
|
24
26
|
```bash
|
|
@@ -36,16 +38,16 @@ yarn add stream-markdown-parser
|
|
|
36
38
|
```typescript
|
|
37
39
|
import { getMarkdown, parseMarkdownToStructure } from 'stream-markdown-parser'
|
|
38
40
|
|
|
39
|
-
// 创建一个带有默认插件的 markdown-it 实例
|
|
41
|
+
// 创建一个带有默认插件的 markdown-it-ts 实例
|
|
40
42
|
const md = getMarkdown()
|
|
41
43
|
|
|
42
|
-
// 将 Markdown
|
|
43
|
-
const html = md.render('# Hello World\n\nThis is **bold**.')
|
|
44
|
-
|
|
45
|
-
// 或解析为 AST 结构
|
|
44
|
+
// 将 Markdown 解析为流式友好的 AST 结构
|
|
46
45
|
const nodes = parseMarkdownToStructure('# Hello World', md)
|
|
47
46
|
console.log(nodes)
|
|
48
47
|
// [{ type: 'heading', level: 1, children: [...] }]
|
|
48
|
+
|
|
49
|
+
// 如果仍需 HTML 输出,markdown-it-ts 依旧提供 render()
|
|
50
|
+
const html = md.render?.('# Hello World\n\nThis is **bold**.')
|
|
49
51
|
```
|
|
50
52
|
|
|
51
53
|
### 配置数学公式选项
|
|
@@ -117,7 +119,7 @@ const md = getMarkdown('editor-1', {
|
|
|
117
119
|
|
|
118
120
|
#### `getMarkdown(msgId?, options?)`
|
|
119
121
|
|
|
120
|
-
创建一个配置好的 markdown-it
|
|
122
|
+
创建一个配置好的 `markdown-it-ts` 实例(与 markdown-it API 兼容)。
|
|
121
123
|
|
|
122
124
|
**参数:**
|
|
123
125
|
- `msgId` (string, 可选): 该实例的唯一标识符。默认值:`editor-${Date.now()}`
|
|
@@ -126,7 +128,7 @@ const md = getMarkdown('editor-1', {
|
|
|
126
128
|
**选项:**
|
|
127
129
|
```typescript
|
|
128
130
|
interface GetMarkdownOptions {
|
|
129
|
-
// 要使用的 markdown-it 插件数组
|
|
131
|
+
// 要使用的 markdown-it / markdown-it-ts 插件数组
|
|
130
132
|
plugin?: Array<Plugin | [Plugin, any]>
|
|
131
133
|
|
|
132
134
|
// 修改 md 实例的函数数组
|
|
@@ -143,7 +145,7 @@ interface GetMarkdownOptions {
|
|
|
143
145
|
|
|
144
146
|
**参数:**
|
|
145
147
|
- `content` (string): 要解析的 Markdown 内容
|
|
146
|
-
- `md` (
|
|
148
|
+
- `md` (MarkdownItCore, 可选): markdown-it-ts 实例。如果未提供,则使用 `getMarkdown()` 创建
|
|
147
149
|
- `options` (ParseOptions, 可选): 带有钩子的解析选项
|
|
148
150
|
|
|
149
151
|
**返回值:** `ParsedNode[]` - 解析后的节点数组
|
|
@@ -154,7 +156,7 @@ interface GetMarkdownOptions {
|
|
|
154
156
|
|
|
155
157
|
#### `parseInlineTokens(tokens, md)`
|
|
156
158
|
|
|
157
|
-
解析内联 markdown-it tokens。
|
|
159
|
+
解析内联 markdown-it-ts tokens。
|
|
158
160
|
|
|
159
161
|
### 配置函数
|
|
160
162
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as markdown_it_ts0 from "markdown-it-ts";
|
|
2
|
+
import { Token } from "markdown-it-ts";
|
|
2
3
|
|
|
3
4
|
//#region src/factory.d.ts
|
|
4
5
|
interface FactoryOptions extends Record<string, unknown> {
|
|
@@ -57,6 +58,10 @@ interface CodeBlockNode extends BaseNode {
|
|
|
57
58
|
updatedCode?: string;
|
|
58
59
|
raw: string;
|
|
59
60
|
}
|
|
61
|
+
interface HtmlBlockNode extends BaseNode {
|
|
62
|
+
type: 'html_block';
|
|
63
|
+
content: string;
|
|
64
|
+
}
|
|
60
65
|
interface InlineCodeNode extends BaseNode {
|
|
61
66
|
type: 'inline_code';
|
|
62
67
|
code: string;
|
|
@@ -190,20 +195,28 @@ interface ReferenceNode extends BaseNode {
|
|
|
190
195
|
type: 'reference';
|
|
191
196
|
id: string;
|
|
192
197
|
}
|
|
193
|
-
interface
|
|
198
|
+
interface MarkdownTokenLite {
|
|
194
199
|
type: string;
|
|
195
200
|
tag?: string;
|
|
196
201
|
content?: string;
|
|
197
202
|
info?: string;
|
|
198
|
-
loading?: boolean;
|
|
199
|
-
children?: MarkdownToken[];
|
|
200
|
-
attrs?: [string, string][];
|
|
201
203
|
markup?: string;
|
|
202
204
|
meta?: unknown;
|
|
203
|
-
map?: [number, number];
|
|
205
|
+
map?: [number, number] | number[] | null;
|
|
206
|
+
block?: boolean;
|
|
207
|
+
hidden?: boolean;
|
|
208
|
+
attrs?: [string, string][] | null;
|
|
209
|
+
nesting?: number;
|
|
210
|
+
level?: number;
|
|
211
|
+
children?: MarkdownToken[] | null;
|
|
212
|
+
loading?: boolean;
|
|
204
213
|
raw?: string;
|
|
205
214
|
}
|
|
206
|
-
type
|
|
215
|
+
type MarkdownToken = (Token & {
|
|
216
|
+
loading?: boolean;
|
|
217
|
+
raw?: string;
|
|
218
|
+
}) | MarkdownTokenLite;
|
|
219
|
+
type ParsedNode = TextNode | HeadingNode | ParagraphNode | ListNode | ListItemNode | CodeBlockNode | InlineCodeNode | LinkNode | ImageNode | ThematicBreakNode | BlockquoteNode | TableNode | TableRowNode | TableCellNode | StrongNode | EmphasisNode | StrikethroughNode | HighlightNode | InsertNode | SubscriptNode | SuperscriptNode | CheckboxNode | CheckboxInputNode | EmojiNode | DefinitionListNode | DefinitionItemNode | FootnoteNode | FootnoteReferenceNode | AdmonitionNode | HardBreakNode | MathInlineNode | MathBlockNode | ReferenceNode | HtmlBlockNode | Record<string, unknown>;
|
|
207
220
|
interface CustomComponents {
|
|
208
221
|
text: unknown;
|
|
209
222
|
paragraph: unknown;
|
|
@@ -297,9 +310,7 @@ interface GetMarkdownOptions extends FactoryOptions {
|
|
|
297
310
|
*/
|
|
298
311
|
i18n?: ((key: string) => string) | Record<string, string>;
|
|
299
312
|
}
|
|
300
|
-
declare function getMarkdown(msgId?: string, options?: GetMarkdownOptions): MarkdownIt;
|
|
301
|
-
declare function getCommonMarkdown(): MarkdownIt;
|
|
302
|
-
declare function renderMarkdown(md: MarkdownIt, content: string): string;
|
|
313
|
+
declare function getMarkdown(msgId?: string, options?: GetMarkdownOptions): markdown_it_ts0.MarkdownIt;
|
|
303
314
|
//#endregion
|
|
304
|
-
export { AdmonitionNode, BaseNode, BlockquoteNode, CheckboxInputNode, CheckboxNode, CodeBlockNode, CustomComponents, DefinitionItemNode, DefinitionListNode, ESCAPED_TEX_BRACE_COMMANDS, EmojiNode, EmphasisNode, FootnoteNode, FootnoteReferenceNode, GetMarkdownOptions, HardBreakNode, HeadingNode, HighlightNode, ImageNode, InlineCodeNode, InsertNode, KATEX_COMMANDS, LinkNode, ListItemNode, ListNode, MarkdownRender, MarkdownToken, MathBlockNode, MathInlineNode, type MathOptions, MermaidBlockNode, ParagraphNode, ParseOptions, ParsedNode, PostTransformNodesHook, ReferenceNode, StrikethroughNode, StrongNode, SubscriptNode, SuperscriptNode, TEX_BRACE_COMMANDS, TableCellNode, TableNode, TableRowNode, TextNode, ThematicBreakNode, TransformTokensHook, applyContainers, applyMath, findMatchingClose,
|
|
315
|
+
export { AdmonitionNode, BaseNode, BlockquoteNode, CheckboxInputNode, CheckboxNode, CodeBlockNode, CustomComponents, DefinitionItemNode, DefinitionListNode, ESCAPED_TEX_BRACE_COMMANDS, EmojiNode, EmphasisNode, FootnoteNode, FootnoteReferenceNode, GetMarkdownOptions, HardBreakNode, HeadingNode, HighlightNode, HtmlBlockNode, ImageNode, InlineCodeNode, InsertNode, KATEX_COMMANDS, LinkNode, ListItemNode, ListNode, MarkdownRender, MarkdownToken, MarkdownTokenLite, MathBlockNode, MathInlineNode, type MathOptions, MermaidBlockNode, ParagraphNode, ParseOptions, ParsedNode, PostTransformNodesHook, ReferenceNode, StrikethroughNode, StrongNode, SubscriptNode, SuperscriptNode, TEX_BRACE_COMMANDS, TableCellNode, TableNode, TableRowNode, TextNode, ThematicBreakNode, TransformTokensHook, applyContainers, applyMath, findMatchingClose, getMarkdown, isMathLike, normalizeStandaloneBackslashT, parseFenceToken, parseInlineTokens, parseMarkdownToStructure, processTokens, setDefaultMathOptions };
|
|
305
316
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/factory.ts","../src/types.ts","../src/parser/inline-parsers/index.ts","../src/parser/index.ts","../src/config.ts","../src/findMatchingClose.ts","../src/parser/inline-parsers/fence-parser.ts","../src/plugins/containers.ts","../src/plugins/isMathLike.ts","../src/plugins/math.ts","../src/index.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/factory.ts","../src/types.ts","../src/parser/inline-parsers/index.ts","../src/parser/index.ts","../src/config.ts","../src/findMatchingClose.ts","../src/parser/inline-parsers/fence-parser.ts","../src/plugins/containers.ts","../src/plugins/isMathLike.ts","../src/plugins/math.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;UAYiB,cAAA,SAAuB;sBAClB;;;EADL,WAAA,CAAA,EAAA;;;;ACVjB;;;UAAiB,QAAA;;;EDUA,OAAA,CAAA,EAAA,OAAe;;;;ACVf,UAQA,QAAA,SAAiB,QART,CAAA;EAQR,IAAA,EAAA,MAAS;EAMT,OAAA,EAAA,MAAY;EAOZ,MAAA,CAAA,EAAA,OAAc;AAM/B;AAQiB,UArBA,WAAA,SAAoB,QAqBC,CAAA;EAKrB,IAAA,EAAA,SAAA;EAiBA,KAAA,EAAA,MAAA;EAKA,IAAA,EAAA,MAAA;EAKA,QAAA,EAjDL,UAiDc,EAAA;AAQ1B;AAOiB,UA7DA,aAAA,SAAsB,QA6DY,CAAA;EAIlC,IAAA,EAAA,WAAA;EASL,QAAA,EAxEA,UAwEc,EAAA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H,WHyCG,GAAA,SAAA,CAAA,EAAA,IAAA;;;iBI3D/B,iBAAA;;;iBC6BA,eAAA,QAAuB,gBAAgB;;;iBC1BvC,eAAA,KAAoB;;;cCHvB;cAqBA;iBAuBG,UAAA;;;cC3BH;iBA0FG,6BAAA,mBAAgD;AT/F/C,iBSuJD,SAAA,CTtJM,EAAA,ESsJQ,UTvJgB,EAAA,QAAA,CAAA,ESuJO,WTvJP,CAAA,EAAA,IAAA;;;ACW7B,UScA,kBAAA,SAA2B,cTdG,CAAA;EAM9B,MAAA,CAAA,ESSN,KTTe,CAAA,OAKjB,CAAA;EAGQ,KAAA,CAAA,ESEP,KTFO,CAAA,CAAa,EAAA,ESET,UTAT,EAAA,GAAA,IAF0B,CAAA;EAKrB;AAiBjB;AAKA;AAKA;EAQiB,IAAA,CAAA,EAAA,CAAA,CAAA,GAAU,EAAA,MAAA,EAAA,GAAQ,MAAA,CAAA,GSjCE,MTiCM,CAAA,MAAA,EAAA,MAAA,CAAA;AAO3C;AAIiB,iBSzCD,WAAA,CTyCiB,KAAA,CAAA,EAAA,MAAA,EAAA,OAAA,CAAA,ESzC4C,kBTyC5C,CAAA,ESzCmE,eAAA,CAAA,UTyCnE"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import MarkdownIt from "markdown-it";
|
|
2
1
|
import { full } from "markdown-it-emoji";
|
|
3
2
|
import markdownItFootnote from "markdown-it-footnote";
|
|
4
3
|
import markdownItIns from "markdown-it-ins";
|
|
@@ -6,6 +5,7 @@ import markdownItMark from "markdown-it-mark";
|
|
|
6
5
|
import markdownItSub from "markdown-it-sub";
|
|
7
6
|
import markdownItSup from "markdown-it-sup";
|
|
8
7
|
import * as markdownItCheckbox from "markdown-it-task-checkbox";
|
|
8
|
+
import MarkdownIt from "markdown-it-ts";
|
|
9
9
|
import markdownItContainer from "markdown-it-container";
|
|
10
10
|
|
|
11
11
|
//#region src/config.ts
|
|
@@ -1140,6 +1140,65 @@ function parseHighlightToken(tokens, startIndex) {
|
|
|
1140
1140
|
};
|
|
1141
1141
|
}
|
|
1142
1142
|
|
|
1143
|
+
//#endregion
|
|
1144
|
+
//#region src/parser/inline-parsers/html-inline-code-parser.ts
|
|
1145
|
+
function parseHtmlInlineCodeToken(token, tokens, i) {
|
|
1146
|
+
let code = String(token.content ?? "").trim();
|
|
1147
|
+
const nextToken = tokens[i + 1];
|
|
1148
|
+
const nnextToken = tokens[i + 2];
|
|
1149
|
+
const tagMatch = code.match(/^<\s*([\w-]+)/);
|
|
1150
|
+
const tag = tagMatch ? tagMatch[1].toLowerCase() : "";
|
|
1151
|
+
function extractInner(html) {
|
|
1152
|
+
const m = html.match(/>([\s\S]*?)<\s*\/\s*[\w-]+>/);
|
|
1153
|
+
return m ? m[1] : "";
|
|
1154
|
+
}
|
|
1155
|
+
if (tag === "a") {
|
|
1156
|
+
let loading = false;
|
|
1157
|
+
if (!nextToken || nextToken?.type === "text" && (!nnextToken || nnextToken.type !== "html_inline") || !nextToken) loading = true;
|
|
1158
|
+
if (nextToken?.type === "text" && (nnextToken?.type === "html_inline" || !nnextToken)) {
|
|
1159
|
+
const hrefMatch = code.match(/href\s*=\s*"([^"]+)"|href\s*=\s*'([^']+)'|href\s*=\s*([^\s>]+)/i);
|
|
1160
|
+
const href = hrefMatch ? hrefMatch[1] || hrefMatch[2] || hrefMatch[3] : "";
|
|
1161
|
+
let index = i + 1;
|
|
1162
|
+
if (nextToken.type === "text") {
|
|
1163
|
+
code = nextToken.content?.replace(/<[^>]*$/, "") ?? "";
|
|
1164
|
+
index = i + 2;
|
|
1165
|
+
}
|
|
1166
|
+
if (nnextToken?.type === "html_inline" && nextToken.type === "text") index = i + 3;
|
|
1167
|
+
const inner = code || href || "";
|
|
1168
|
+
return [{
|
|
1169
|
+
type: "link",
|
|
1170
|
+
href: String(href ?? ""),
|
|
1171
|
+
title: null,
|
|
1172
|
+
text: code,
|
|
1173
|
+
children: [{
|
|
1174
|
+
type: "text",
|
|
1175
|
+
content: inner,
|
|
1176
|
+
raw: inner
|
|
1177
|
+
}],
|
|
1178
|
+
loading,
|
|
1179
|
+
raw: code
|
|
1180
|
+
}, index];
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
if (tag === "p" || tag === "div") {
|
|
1184
|
+
const inner = extractInner(code) || "";
|
|
1185
|
+
return [{
|
|
1186
|
+
type: "paragraph",
|
|
1187
|
+
children: [{
|
|
1188
|
+
type: "text",
|
|
1189
|
+
content: inner,
|
|
1190
|
+
raw: inner
|
|
1191
|
+
}],
|
|
1192
|
+
raw: code
|
|
1193
|
+
}, i + 1];
|
|
1194
|
+
}
|
|
1195
|
+
return [{
|
|
1196
|
+
type: "inline_code",
|
|
1197
|
+
code,
|
|
1198
|
+
raw: code
|
|
1199
|
+
}, i + 1];
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1143
1202
|
//#endregion
|
|
1144
1203
|
//#region src/parser/inline-parsers/image-parser.ts
|
|
1145
1204
|
function parseImageToken(token, loading = false) {
|
|
@@ -1626,6 +1685,12 @@ function parseInlineTokens(tokens, raw, pPreToken) {
|
|
|
1626
1685
|
pushNode(parseInlineCodeToken(token));
|
|
1627
1686
|
i++;
|
|
1628
1687
|
break;
|
|
1688
|
+
case "html_inline": {
|
|
1689
|
+
const [node, index] = parseHtmlInlineCodeToken(token, tokens, i);
|
|
1690
|
+
pushNode(node);
|
|
1691
|
+
i = index;
|
|
1692
|
+
break;
|
|
1693
|
+
}
|
|
1629
1694
|
case "link_open":
|
|
1630
1695
|
handleLinkOpen(token);
|
|
1631
1696
|
break;
|
|
@@ -2456,6 +2521,17 @@ function parseHardBreak() {
|
|
|
2456
2521
|
};
|
|
2457
2522
|
}
|
|
2458
2523
|
|
|
2524
|
+
//#endregion
|
|
2525
|
+
//#region src/parser/node-parsers/html-block-parser.ts
|
|
2526
|
+
function parseHtmlBlock(token) {
|
|
2527
|
+
return {
|
|
2528
|
+
type: "html_block",
|
|
2529
|
+
content: String(token.content ?? ""),
|
|
2530
|
+
raw: String(token.content ?? ""),
|
|
2531
|
+
loading: false
|
|
2532
|
+
};
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2459
2535
|
//#endregion
|
|
2460
2536
|
//#region src/parser/node-parsers/paragraph-parser.ts
|
|
2461
2537
|
function parseParagraph(tokens, index) {
|
|
@@ -2480,7 +2556,7 @@ function parseMarkdownToStructure(markdown, md, options = {}) {
|
|
|
2480
2556
|
const pre = options.preTransformTokens;
|
|
2481
2557
|
const post = options.postTransformTokens;
|
|
2482
2558
|
let transformedTokens = tokens;
|
|
2483
|
-
if (pre && typeof pre === "function") transformedTokens = pre(
|
|
2559
|
+
if (pre && typeof pre === "function") transformedTokens = pre(transformedTokens) || transformedTokens;
|
|
2484
2560
|
let result = processTokens(transformedTokens);
|
|
2485
2561
|
if (post && typeof post === "function") {
|
|
2486
2562
|
const postResult = post(transformedTokens);
|
|
@@ -2521,6 +2597,9 @@ function processTokens(tokens) {
|
|
|
2521
2597
|
i += 3;
|
|
2522
2598
|
break;
|
|
2523
2599
|
case "html_block":
|
|
2600
|
+
result.push(parseHtmlBlock(token));
|
|
2601
|
+
i += 1;
|
|
2602
|
+
break;
|
|
2524
2603
|
case "code_block":
|
|
2525
2604
|
result.push(parseCodeBlock(tokens[i]));
|
|
2526
2605
|
i += 1;
|
|
@@ -2698,18 +2777,7 @@ function getMarkdown(msgId = `editor-${Date.now()}`, options = {}) {
|
|
|
2698
2777
|
};
|
|
2699
2778
|
return md;
|
|
2700
2779
|
}
|
|
2701
|
-
function getCommonMarkdown() {
|
|
2702
|
-
return new MarkdownIt({
|
|
2703
|
-
html: true,
|
|
2704
|
-
linkify: true,
|
|
2705
|
-
typographer: true,
|
|
2706
|
-
breaks: false
|
|
2707
|
-
});
|
|
2708
|
-
}
|
|
2709
|
-
function renderMarkdown(md, content) {
|
|
2710
|
-
return md.render(content);
|
|
2711
|
-
}
|
|
2712
2780
|
|
|
2713
2781
|
//#endregion
|
|
2714
|
-
export { ESCAPED_TEX_BRACE_COMMANDS, KATEX_COMMANDS, TEX_BRACE_COMMANDS, applyContainers, applyMath, findMatchingClose,
|
|
2782
|
+
export { ESCAPED_TEX_BRACE_COMMANDS, KATEX_COMMANDS, TEX_BRACE_COMMANDS, applyContainers, applyMath, findMatchingClose, getMarkdown, isMathLike, normalizeStandaloneBackslashT, parseFenceToken, parseInlineTokens, parseMarkdownToStructure, processTokens, setDefaultMathOptions };
|
|
2715
2783
|
//# sourceMappingURL=index.js.map
|