@ant-design/agentic-ui 2.27.10 → 2.28.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.
- package/dist/MarkdownEditor/editor/elements/Blockquote/index.js +11 -1
- package/dist/MarkdownEditor/editor/elements/Break/index.js +2 -0
- package/dist/MarkdownEditor/editor/elements/Card/index.js +11 -0
- package/dist/MarkdownEditor/editor/elements/Code/index.js +22 -7
- package/dist/MarkdownEditor/editor/elements/FootnoteDefinition/index.js +15 -1
- package/dist/MarkdownEditor/editor/elements/FootnoteReference/index.js +11 -1
- package/dist/MarkdownEditor/editor/elements/Head/index.d.ts +1 -1
- package/dist/MarkdownEditor/editor/elements/Head/index.js +17 -1
- package/dist/MarkdownEditor/editor/elements/Hr/index.js +2 -0
- package/dist/MarkdownEditor/editor/elements/Image/index.js +75 -34
- package/dist/MarkdownEditor/editor/elements/InlineKatex/index.js +5 -0
- package/dist/MarkdownEditor/editor/elements/Katex/index.js +5 -0
- package/dist/MarkdownEditor/editor/elements/LinkCard/index.js +13 -1
- package/dist/MarkdownEditor/editor/elements/List/List.js +16 -1
- package/dist/MarkdownEditor/editor/elements/List/ListItem.js +16 -4
- package/dist/MarkdownEditor/editor/elements/Mermaid/index.js +7 -2
- package/dist/MarkdownEditor/editor/elements/Paragraph/index.js +14 -2
- package/dist/MarkdownEditor/editor/elements/Schema/index.js +13 -0
- package/dist/MarkdownEditor/editor/elements/index.js +131 -16
- package/dist/MarkdownEditor/editor/parser/parse/parseBlockElements.js +84 -17
- package/dist/MarkdownEditor/editor/parser/parse/parseCode.js +39 -2
- package/dist/MarkdownEditor/editor/parser/parse/parseElements.js +27 -2
- package/dist/MarkdownEditor/editor/parser/parse/parseFootnote.js +11 -1
- package/dist/MarkdownEditor/editor/parser/parse/parseMath.js +31 -4
- package/dist/MarkdownEditor/editor/parser/parse/parseMedia.js +41 -6
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.js +141 -24
- package/dist/MarkdownEditor/editor/parser/parserSlateNodeToMarkdown.js +127 -6
- package/dist/MarkdownEditor/editor/plugins/insertParsedHtmlNodes.js +109 -2
- package/package.json +1 -1
|
@@ -50,6 +50,7 @@ function _object_spread_props(target, source) {
|
|
|
50
50
|
}
|
|
51
51
|
return target;
|
|
52
52
|
}
|
|
53
|
+
import { debugInfo } from "../../../../Utils/debugUtils";
|
|
53
54
|
import json5 from "json5";
|
|
54
55
|
import { isCodeBlockLikelyComplete } from "../../utils/findMatchingClose";
|
|
55
56
|
import partialJsonParse from "../json-parse";
|
|
@@ -104,13 +105,23 @@ var ENDING_NEWLINE = /\n$/;
|
|
|
104
105
|
* @param config - 可选的配置对象,可能包含从 HTML 注释中解析的属性
|
|
105
106
|
* @returns 返回格式化的代码块节点对象,根据语言类型进行特殊处理
|
|
106
107
|
*/ export var handleCode = function(currentElement, config) {
|
|
107
|
-
var _effectiveLang_match, _currentElement_otherProps, _currentElement_value_trim;
|
|
108
|
+
var _currentElement_value, _effectiveLang_match, _currentElement_otherProps, _currentElement_value_trim, _resultWithProps_value;
|
|
109
|
+
debugInfo('handleCode - 处理代码块', {
|
|
110
|
+
rawValueLength: (_currentElement_value = currentElement.value) === null || _currentElement_value === void 0 ? void 0 : _currentElement_value.length,
|
|
111
|
+
lang: currentElement.lang,
|
|
112
|
+
configLanguage: config === null || config === void 0 ? void 0 : config['data-language'],
|
|
113
|
+
meta: currentElement.meta
|
|
114
|
+
});
|
|
108
115
|
var rawValue = currentElement.value || '';
|
|
109
116
|
// 如果 config 中包含 data-language,优先使用它来恢复语言类型
|
|
110
117
|
var configLanguage = config === null || config === void 0 ? void 0 : config['data-language'];
|
|
111
118
|
// 保持原有的行为:如果没有语言,应该使用 null 而不是空字符串
|
|
112
119
|
var effectiveLang = configLanguage || currentElement.lang || null;
|
|
113
120
|
var langString = effectiveLang ? ((_effectiveLang_match = effectiveLang.match(NOT_SPACE_START)) === null || _effectiveLang_match === void 0 ? void 0 : _effectiveLang_match[0]) || '' : '';
|
|
121
|
+
debugInfo('handleCode - 语言处理', {
|
|
122
|
+
effectiveLang: effectiveLang,
|
|
123
|
+
langString: langString
|
|
124
|
+
});
|
|
114
125
|
var code = "".concat(rawValue.replace(ENDING_NEWLINE, ''), "\n");
|
|
115
126
|
// 检查代码块是否完整
|
|
116
127
|
// 如果是缩进代码块,认为是完整的(因为没有结束标记)
|
|
@@ -162,6 +173,13 @@ var ENDING_NEWLINE = /\n$/;
|
|
|
162
173
|
otherProps: otherProps
|
|
163
174
|
};
|
|
164
175
|
var handler = LANGUAGE_HANDLERS[effectiveLang];
|
|
176
|
+
debugInfo('handleCode - 语言处理器', {
|
|
177
|
+
effectiveLang: effectiveLang,
|
|
178
|
+
hasHandler: !!handler,
|
|
179
|
+
handlerName: handler ? Object.keys(LANGUAGE_HANDLERS).find(function(k) {
|
|
180
|
+
return LANGUAGE_HANDLERS[k] === handler;
|
|
181
|
+
}) : undefined
|
|
182
|
+
});
|
|
165
183
|
var result = handler ? handler(baseCodeElement, currentElement.value) : baseCodeElement;
|
|
166
184
|
// 确保 otherProps 被保留,并合并 config 中的属性
|
|
167
185
|
var resultWithProps = result;
|
|
@@ -172,6 +190,15 @@ var ENDING_NEWLINE = /\n$/;
|
|
|
172
190
|
} else if (config && Object.keys(config).length > 0) {
|
|
173
191
|
resultWithProps.otherProps = _object_spread({}, resultWithProps.otherProps || {}, config);
|
|
174
192
|
}
|
|
193
|
+
debugInfo('handleCode - 代码块处理完成', {
|
|
194
|
+
type: resultWithProps.type,
|
|
195
|
+
language: resultWithProps.language,
|
|
196
|
+
render: resultWithProps.render,
|
|
197
|
+
isConfig: resultWithProps.isConfig,
|
|
198
|
+
valueLength: (_resultWithProps_value = resultWithProps.value) === null || _resultWithProps_value === void 0 ? void 0 : _resultWithProps_value.length,
|
|
199
|
+
hasOtherProps: !!resultWithProps.otherProps,
|
|
200
|
+
otherPropsKeys: resultWithProps.otherProps ? Object.keys(resultWithProps.otherProps) : []
|
|
201
|
+
});
|
|
175
202
|
return resultWithProps;
|
|
176
203
|
};
|
|
177
204
|
/**
|
|
@@ -179,7 +206,11 @@ var ENDING_NEWLINE = /\n$/;
|
|
|
179
206
|
* @param currentElement - 当前处理的YAML元素
|
|
180
207
|
* @returns 返回格式化的YAML代码块节点对象
|
|
181
208
|
*/ export var handleYaml = function(currentElement) {
|
|
182
|
-
|
|
209
|
+
var _currentElement_value;
|
|
210
|
+
debugInfo('handleYaml - 处理 YAML', {
|
|
211
|
+
valueLength: (_currentElement_value = currentElement.value) === null || _currentElement_value === void 0 ? void 0 : _currentElement_value.length
|
|
212
|
+
});
|
|
213
|
+
var result = {
|
|
183
214
|
type: 'code',
|
|
184
215
|
language: 'yaml',
|
|
185
216
|
value: currentElement.value,
|
|
@@ -190,4 +221,10 @@ var ENDING_NEWLINE = /\n$/;
|
|
|
190
221
|
}
|
|
191
222
|
]
|
|
192
223
|
};
|
|
224
|
+
debugInfo('handleYaml - YAML 处理完成', {
|
|
225
|
+
type: result.type,
|
|
226
|
+
language: result.language,
|
|
227
|
+
frontmatter: result.frontmatter
|
|
228
|
+
});
|
|
229
|
+
return result;
|
|
193
230
|
};
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { debugInfo } from "../../../../Utils/debugUtils";
|
|
1
2
|
/**
|
|
2
3
|
* 处理内联代码节点
|
|
3
4
|
* @param currentElement - 当前处理的内联代码元素
|
|
4
5
|
* @returns 返回格式化的内联代码节点对象,支持占位符和初始值
|
|
5
6
|
*/ export var handleInlineCode = function(currentElement) {
|
|
6
7
|
var _currentElement_value, _currentElement_value1;
|
|
8
|
+
debugInfo('handleInlineCode - 处理内联代码', {
|
|
9
|
+
value: currentElement.value
|
|
10
|
+
});
|
|
7
11
|
var hasPlaceHolder = (_currentElement_value = currentElement.value) === null || _currentElement_value === void 0 ? void 0 : _currentElement_value.match(/\$\{(.*?)\}/);
|
|
8
12
|
var values = undefined;
|
|
9
13
|
if (hasPlaceHolder) {
|
|
@@ -52,13 +56,21 @@
|
|
|
52
56
|
result.placeholder = undefined;
|
|
53
57
|
result.initialValue = undefined;
|
|
54
58
|
}
|
|
59
|
+
debugInfo('handleInlineCode - 内联代码处理完成', {
|
|
60
|
+
code: result.code,
|
|
61
|
+
tag: result.tag,
|
|
62
|
+
text: result.text,
|
|
63
|
+
placeholder: result.placeholder,
|
|
64
|
+
initialValue: result.initialValue
|
|
65
|
+
});
|
|
55
66
|
return result;
|
|
56
67
|
};
|
|
57
68
|
/**
|
|
58
69
|
* 处理分割线节点
|
|
59
70
|
* @returns 返回格式化的分割线节点对象
|
|
60
71
|
*/ export var handleThematicBreak = function() {
|
|
61
|
-
|
|
72
|
+
debugInfo('handleThematicBreak - 处理分割线');
|
|
73
|
+
var result = {
|
|
62
74
|
type: 'hr',
|
|
63
75
|
children: [
|
|
64
76
|
{
|
|
@@ -66,13 +78,21 @@
|
|
|
66
78
|
}
|
|
67
79
|
]
|
|
68
80
|
};
|
|
81
|
+
debugInfo('handleThematicBreak - 分割线处理完成', {
|
|
82
|
+
type: result.type
|
|
83
|
+
});
|
|
84
|
+
return result;
|
|
69
85
|
};
|
|
70
86
|
/**
|
|
71
87
|
* 处理定义节点
|
|
72
88
|
* @param currentElement - 当前处理的定义元素,包含标签和URL
|
|
73
89
|
* @returns 返回格式化的定义段落节点对象
|
|
74
90
|
*/ export var handleDefinition = function(currentElement) {
|
|
75
|
-
|
|
91
|
+
debugInfo('handleDefinition - 处理定义', {
|
|
92
|
+
label: currentElement.label,
|
|
93
|
+
url: currentElement.url
|
|
94
|
+
});
|
|
95
|
+
var result = {
|
|
76
96
|
type: 'paragraph',
|
|
77
97
|
children: [
|
|
78
98
|
{
|
|
@@ -80,4 +100,9 @@
|
|
|
80
100
|
}
|
|
81
101
|
]
|
|
82
102
|
};
|
|
103
|
+
debugInfo('handleDefinition - 定义处理完成', {
|
|
104
|
+
type: result.type,
|
|
105
|
+
text: result.children[0].text
|
|
106
|
+
});
|
|
107
|
+
return result;
|
|
83
108
|
};
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
+
import { debugInfo } from "../../../../Utils/debugUtils";
|
|
1
2
|
/**
|
|
2
3
|
* 处理脚注引用
|
|
3
4
|
* @param currentElement - 当前处理的脚注引用元素
|
|
4
5
|
* @returns 返回格式化的脚注引用节点对象
|
|
5
6
|
*/ export var handleFootnoteReference = function(currentElement) {
|
|
6
7
|
var _currentElement_identifier;
|
|
7
|
-
|
|
8
|
+
debugInfo('handleFootnoteReference - 处理脚注引用', {
|
|
9
|
+
identifier: currentElement.identifier
|
|
10
|
+
});
|
|
11
|
+
var result = {
|
|
8
12
|
text: "".concat((_currentElement_identifier = currentElement.identifier) === null || _currentElement_identifier === void 0 ? void 0 : _currentElement_identifier.toUpperCase()),
|
|
9
13
|
identifier: currentElement.identifier,
|
|
10
14
|
type: 'footnoteReference'
|
|
11
15
|
};
|
|
16
|
+
debugInfo('handleFootnoteReference - 脚注引用处理完成', {
|
|
17
|
+
type: result.type,
|
|
18
|
+
text: result.text,
|
|
19
|
+
identifier: result.identifier
|
|
20
|
+
});
|
|
21
|
+
return result;
|
|
12
22
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { debugInfo } from "../../../../Utils/debugUtils";
|
|
1
2
|
// 常量定义
|
|
2
3
|
var INLINE_MATH_SUFFIX_PATTERN = '(?:%|[kKmMbB]|千|万|亿|兆|万亿|百万|亿万)?';
|
|
3
4
|
var INLINE_MATH_CURRENCY_PATTERN = new RegExp("^[+-]?\\d{1,3}(?:,\\d{3})*(?:\\.\\d+)?".concat(INLINE_MATH_SUFFIX_PATTERN, "$"));
|
|
@@ -19,9 +20,17 @@ var INLINE_MATH_SIMPLE_NUMBER_PATTERN = new RegExp("^[+-]?\\d+(?:\\.\\d+)?".conc
|
|
|
19
20
|
* @param currentElement - 当前处理的内联数学公式元素
|
|
20
21
|
* @returns 返回格式化的内联KaTeX节点对象
|
|
21
22
|
*/ export var handleInlineMath = function(currentElement) {
|
|
23
|
+
debugInfo('handleInlineMath - 处理内联数学公式', {
|
|
24
|
+
value: currentElement === null || currentElement === void 0 ? void 0 : currentElement.value
|
|
25
|
+
});
|
|
22
26
|
var inlineMathValue = typeof (currentElement === null || currentElement === void 0 ? void 0 : currentElement.value) === 'string' ? currentElement.value : '';
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
var treatAsText = shouldTreatInlineMathAsText(inlineMathValue);
|
|
28
|
+
debugInfo('handleInlineMath - 判断结果', {
|
|
29
|
+
treatAsText: treatAsText,
|
|
30
|
+
value: inlineMathValue
|
|
31
|
+
});
|
|
32
|
+
if (treatAsText) {
|
|
33
|
+
var result = {
|
|
25
34
|
type: 'paragraph',
|
|
26
35
|
children: [
|
|
27
36
|
{
|
|
@@ -29,8 +38,12 @@ var INLINE_MATH_SIMPLE_NUMBER_PATTERN = new RegExp("^[+-]?\\d+(?:\\.\\d+)?".conc
|
|
|
29
38
|
}
|
|
30
39
|
]
|
|
31
40
|
};
|
|
41
|
+
debugInfo('handleInlineMath - 作为文本处理', {
|
|
42
|
+
type: result.type
|
|
43
|
+
});
|
|
44
|
+
return result;
|
|
32
45
|
}
|
|
33
|
-
|
|
46
|
+
var result1 = {
|
|
34
47
|
type: 'inline-katex',
|
|
35
48
|
children: [
|
|
36
49
|
{
|
|
@@ -38,13 +51,21 @@ var INLINE_MATH_SIMPLE_NUMBER_PATTERN = new RegExp("^[+-]?\\d+(?:\\.\\d+)?".conc
|
|
|
38
51
|
}
|
|
39
52
|
]
|
|
40
53
|
};
|
|
54
|
+
debugInfo('handleInlineMath - 作为内联公式处理', {
|
|
55
|
+
type: result1.type
|
|
56
|
+
});
|
|
57
|
+
return result1;
|
|
41
58
|
};
|
|
42
59
|
/**
|
|
43
60
|
* 处理数学公式块
|
|
44
61
|
* @param currentElement - 当前处理的数学公式块元素
|
|
45
62
|
* @returns 返回格式化的KaTeX块节点对象
|
|
46
63
|
*/ export var handleMath = function(currentElement) {
|
|
47
|
-
|
|
64
|
+
var _currentElement_value;
|
|
65
|
+
debugInfo('handleMath - 处理数学公式块', {
|
|
66
|
+
valueLength: (_currentElement_value = currentElement.value) === null || _currentElement_value === void 0 ? void 0 : _currentElement_value.length
|
|
67
|
+
});
|
|
68
|
+
var result = {
|
|
48
69
|
type: 'katex',
|
|
49
70
|
language: 'latex',
|
|
50
71
|
katex: true,
|
|
@@ -55,4 +76,10 @@ var INLINE_MATH_SIMPLE_NUMBER_PATTERN = new RegExp("^[+-]?\\d+(?:\\.\\d+)?".conc
|
|
|
55
76
|
}
|
|
56
77
|
]
|
|
57
78
|
};
|
|
79
|
+
debugInfo('handleMath - 数学公式块处理完成', {
|
|
80
|
+
type: result.type,
|
|
81
|
+
language: result.language,
|
|
82
|
+
katex: result.katex
|
|
83
|
+
});
|
|
84
|
+
return result;
|
|
58
85
|
};
|
|
@@ -50,6 +50,7 @@ function _object_spread_props(target, source) {
|
|
|
50
50
|
}
|
|
51
51
|
return target;
|
|
52
52
|
}
|
|
53
|
+
import { debugInfo } from "../../../../Utils/debugUtils";
|
|
53
54
|
import { EditorUtils } from "../../utils";
|
|
54
55
|
import { decodeURIComponentUrl, findAttachment } from "./parseHtml";
|
|
55
56
|
/**
|
|
@@ -57,21 +58,38 @@ import { decodeURIComponentUrl, findAttachment } from "./parseHtml";
|
|
|
57
58
|
* @param currentElement - 当前处理的图片元素,包含url和alt属性
|
|
58
59
|
* @returns 返回格式化的图片节点对象
|
|
59
60
|
*/ export var handleImage = function(currentElement) {
|
|
60
|
-
|
|
61
|
+
debugInfo('handleImage - 处理图片', {
|
|
62
|
+
url: currentElement === null || currentElement === void 0 ? void 0 : currentElement.url,
|
|
63
|
+
alt: currentElement === null || currentElement === void 0 ? void 0 : currentElement.alt,
|
|
64
|
+
finished: currentElement === null || currentElement === void 0 ? void 0 : currentElement.finished
|
|
65
|
+
});
|
|
66
|
+
var result = EditorUtils.createMediaNode(decodeURIComponentUrl(currentElement === null || currentElement === void 0 ? void 0 : currentElement.url), 'image', {
|
|
61
67
|
alt: currentElement.alt,
|
|
62
68
|
finished: currentElement.finished
|
|
63
69
|
});
|
|
70
|
+
debugInfo('handleImage - 图片处理完成', {
|
|
71
|
+
type: currentElement === null || currentElement === void 0 ? void 0 : currentElement.type,
|
|
72
|
+
url: currentElement === null || currentElement === void 0 ? void 0 : currentElement.url
|
|
73
|
+
});
|
|
74
|
+
return result;
|
|
64
75
|
};
|
|
65
76
|
/**
|
|
66
77
|
* 处理附件链接
|
|
67
78
|
*/ export var handleAttachmentLink = function(currentElement) {
|
|
79
|
+
var _currentElement_children;
|
|
80
|
+
debugInfo('handleAttachmentLink - 处理附件链接', {
|
|
81
|
+
childrenCount: (_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length
|
|
82
|
+
});
|
|
68
83
|
var text = currentElement.children.map(function(n) {
|
|
69
84
|
return n.value || '';
|
|
70
85
|
}).join('');
|
|
71
86
|
var attach = findAttachment(text);
|
|
72
|
-
if (!attach)
|
|
87
|
+
if (!attach) {
|
|
88
|
+
debugInfo('handleAttachmentLink - 未找到附件');
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
73
91
|
var name = text.match(/>(.*)<\/a>/);
|
|
74
|
-
|
|
92
|
+
var result = {
|
|
75
93
|
type: 'attach',
|
|
76
94
|
url: decodeURIComponentUrl(attach === null || attach === void 0 ? void 0 : attach.url),
|
|
77
95
|
size: attach.size,
|
|
@@ -95,13 +113,24 @@ import { decodeURIComponentUrl, findAttachment } from "./parseHtml";
|
|
|
95
113
|
],
|
|
96
114
|
name: name ? name[1] : attach === null || attach === void 0 ? void 0 : attach.url
|
|
97
115
|
};
|
|
116
|
+
debugInfo('handleAttachmentLink - 附件链接处理完成', {
|
|
117
|
+
type: result.type,
|
|
118
|
+
url: result.url,
|
|
119
|
+
size: result.size,
|
|
120
|
+
name: result.name
|
|
121
|
+
});
|
|
122
|
+
return result;
|
|
98
123
|
};
|
|
99
124
|
/**
|
|
100
125
|
* 处理链接卡片
|
|
101
126
|
*/ export var handleLinkCard = function(currentElement, config) {
|
|
102
|
-
var _currentElement_children;
|
|
103
|
-
|
|
104
|
-
|
|
127
|
+
var _currentElement_children, _currentElement_children1;
|
|
128
|
+
debugInfo('handleLinkCard - 处理链接卡片', {
|
|
129
|
+
childrenCount: currentElement === null || currentElement === void 0 ? void 0 : (_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length,
|
|
130
|
+
configType: config === null || config === void 0 ? void 0 : config.type
|
|
131
|
+
});
|
|
132
|
+
var link = currentElement === null || currentElement === void 0 ? void 0 : (_currentElement_children1 = currentElement.children) === null || _currentElement_children1 === void 0 ? void 0 : _currentElement_children1.at(0);
|
|
133
|
+
var result = _object_spread_props(_object_spread({}, config), {
|
|
105
134
|
type: 'link-card',
|
|
106
135
|
url: decodeURIComponentUrl(link === null || link === void 0 ? void 0 : link.url),
|
|
107
136
|
children: [
|
|
@@ -124,4 +153,10 @@ import { decodeURIComponentUrl, findAttachment } from "./parseHtml";
|
|
|
124
153
|
],
|
|
125
154
|
name: link.title
|
|
126
155
|
});
|
|
156
|
+
debugInfo('handleLinkCard - 链接卡片处理完成', {
|
|
157
|
+
type: result.type,
|
|
158
|
+
url: result.url,
|
|
159
|
+
name: result.name
|
|
160
|
+
});
|
|
161
|
+
return result;
|
|
127
162
|
};
|
|
@@ -74,6 +74,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
74
74
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
75
75
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
76
76
|
}
|
|
77
|
+
import { debugInfo } from "../../../Utils/debugUtils";
|
|
77
78
|
import { applyContextPropsAndConfig } from "./parse/applyContextPropsAndConfig";
|
|
78
79
|
import { handleBlockquote, handleFootnoteDefinition, handleHeading, handleList, handleListItem, handleParagraph, handleTextAndInlineElements } from "./parse/parseBlockElements";
|
|
79
80
|
import { handleCode, handleYaml } from "./parse/parseCode";
|
|
@@ -113,29 +114,65 @@ var removeAnswerTags = function(text) {
|
|
|
113
114
|
* @returns 一个包含解析后的元素数组和链接信息的对象
|
|
114
115
|
*/ key: "parse",
|
|
115
116
|
value: function parse(md) {
|
|
117
|
+
var _this_plugins, _ast_children;
|
|
118
|
+
debugInfo('parserMarkdownToSlateNode.parse - 开始解析', {
|
|
119
|
+
inputLength: md === null || md === void 0 ? void 0 : md.length,
|
|
120
|
+
hasPlugins: ((_this_plugins = this.plugins) === null || _this_plugins === void 0 ? void 0 : _this_plugins.length) > 0,
|
|
121
|
+
config: this.config
|
|
122
|
+
});
|
|
116
123
|
// 先预处理 <think> 标签,然后预处理其他非标准 HTML 标签,最后处理表格换行
|
|
117
124
|
var thinkProcessed = removeAnswerTags(preprocessThinkTags(md || ''));
|
|
125
|
+
debugInfo('parserMarkdownToSlateNode.parse - thinkProcessed', {
|
|
126
|
+
length: thinkProcessed.length,
|
|
127
|
+
changed: thinkProcessed !== md
|
|
128
|
+
});
|
|
118
129
|
var nonStandardProcessed = removeAnswerTags(preprocessNonStandardHtmlTags(thinkProcessed));
|
|
130
|
+
debugInfo('parserMarkdownToSlateNode.parse - nonStandardProcessed', {
|
|
131
|
+
length: nonStandardProcessed.length,
|
|
132
|
+
changed: nonStandardProcessed !== thinkProcessed
|
|
133
|
+
});
|
|
119
134
|
// parse() 只执行 parser,需要 runSync() 来执行 transformer 插件
|
|
120
|
-
var
|
|
135
|
+
var preprocessedMarkdown = preprocessMarkdownTableNewlines(nonStandardProcessed);
|
|
136
|
+
debugInfo('parserMarkdownToSlateNode.parse - preprocessedMarkdown', {
|
|
137
|
+
length: preprocessedMarkdown.length
|
|
138
|
+
});
|
|
139
|
+
var ast = mdastParser.parse(preprocessedMarkdown);
|
|
140
|
+
debugInfo('parserMarkdownToSlateNode.parse - AST 解析完成', {
|
|
141
|
+
astType: ast === null || ast === void 0 ? void 0 : ast.type,
|
|
142
|
+
childrenCount: ast === null || ast === void 0 ? void 0 : (_ast_children = ast.children) === null || _ast_children === void 0 ? void 0 : _ast_children.length
|
|
143
|
+
});
|
|
121
144
|
var processedMarkdown = mdastParser.runSync(ast);
|
|
122
145
|
var markdownRoot = processedMarkdown.children;
|
|
146
|
+
debugInfo('parserMarkdownToSlateNode.parse - 插件处理完成', {
|
|
147
|
+
rootChildrenCount: markdownRoot === null || markdownRoot === void 0 ? void 0 : markdownRoot.length
|
|
148
|
+
});
|
|
123
149
|
// 使用类的配置和插件,通过 this 访问
|
|
124
150
|
var schema = this.parseNodes(markdownRoot, true, undefined);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
151
|
+
debugInfo('parserMarkdownToSlateNode.parse - 节点解析完成', {
|
|
152
|
+
schemaLength: schema === null || schema === void 0 ? void 0 : schema.length,
|
|
153
|
+
schemaTypes: schema === null || schema === void 0 ? void 0 : schema.map(function(s) {
|
|
154
|
+
return s.type;
|
|
155
|
+
})
|
|
156
|
+
});
|
|
157
|
+
var filteredSchema = schema === null || schema === void 0 ? void 0 : schema.filter(function(item) {
|
|
158
|
+
var _item_children, _item_children1;
|
|
159
|
+
if (item.type === 'paragraph' && !((_item_children = item.children) === null || _item_children === void 0 ? void 0 : _item_children.length)) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
if (item.type === 'paragraph' && ((_item_children1 = item.children) === null || _item_children1 === void 0 ? void 0 : _item_children1.length) === 1) {
|
|
163
|
+
if (item.children[0].text === '\n' || item.children[0].text === undefined) {
|
|
129
164
|
return false;
|
|
130
165
|
}
|
|
131
|
-
if (item.type === 'paragraph' && ((_item_children1 = item.children) === null || _item_children1 === void 0 ? void 0 : _item_children1.length) === 1) {
|
|
132
|
-
if (item.children[0].text === '\n' || item.children[0].text === undefined) {
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
166
|
return true;
|
|
138
|
-
}
|
|
167
|
+
}
|
|
168
|
+
return true;
|
|
169
|
+
});
|
|
170
|
+
debugInfo('parserMarkdownToSlateNode.parse - 过滤完成', {
|
|
171
|
+
beforeFilter: schema === null || schema === void 0 ? void 0 : schema.length,
|
|
172
|
+
afterFilter: filteredSchema === null || filteredSchema === void 0 ? void 0 : filteredSchema.length
|
|
173
|
+
});
|
|
174
|
+
return {
|
|
175
|
+
schema: filteredSchema,
|
|
139
176
|
links: []
|
|
140
177
|
};
|
|
141
178
|
}
|
|
@@ -148,8 +185,13 @@ var removeAnswerTags = function(text) {
|
|
|
148
185
|
* - 插件未处理时,使用默认处理逻辑
|
|
149
186
|
*/ function parseNodes(nodes) {
|
|
150
187
|
var _this, _loop = function(i) {
|
|
151
|
-
var _currentElement_value_trim, _currentElement_value, _currentElement_value_trim1, _currentElement_value1;
|
|
188
|
+
var _currentElement_children, _currentElement_value_trim, _currentElement_value, _currentElement_value_trim1, _currentElement_value1;
|
|
152
189
|
var currentElement = nodes[i];
|
|
190
|
+
debugInfo("parserMarkdownToSlateNode.parseNodes - 处理节点 ".concat(i, "/").concat(nodes.length), {
|
|
191
|
+
type: currentElement === null || currentElement === void 0 ? void 0 : currentElement.type,
|
|
192
|
+
hasChildren: !!(currentElement === null || currentElement === void 0 ? void 0 : currentElement.children),
|
|
193
|
+
childrenCount: currentElement === null || currentElement === void 0 ? void 0 : (_currentElement_children = currentElement.children) === null || _currentElement_children === void 0 ? void 0 : _currentElement_children.length
|
|
194
|
+
});
|
|
153
195
|
var el = null;
|
|
154
196
|
var pluginHandled = false;
|
|
155
197
|
// 检查当前元素是否是 HTML 注释
|
|
@@ -222,6 +264,10 @@ var removeAnswerTags = function(text) {
|
|
|
222
264
|
return r.match(currentElement);
|
|
223
265
|
});
|
|
224
266
|
if (rule) {
|
|
267
|
+
debugInfo("parserMarkdownToSlateNode.parseNodes - 插件处理节点 ".concat(i), {
|
|
268
|
+
pluginName: plugin.name || 'unknown',
|
|
269
|
+
elementType: currentElement === null || currentElement === void 0 ? void 0 : currentElement.type
|
|
270
|
+
});
|
|
225
271
|
var converted = rule.convert(currentElement);
|
|
226
272
|
// 检查转换结果是否为 NodeEntry<Text> 格式
|
|
227
273
|
if (Array.isArray(converted) && converted.length === 2) {
|
|
@@ -232,6 +278,9 @@ var removeAnswerTags = function(text) {
|
|
|
232
278
|
el = converted;
|
|
233
279
|
}
|
|
234
280
|
pluginHandled = true;
|
|
281
|
+
debugInfo("parserMarkdownToSlateNode.parseNodes - 插件转换完成 ".concat(i), {
|
|
282
|
+
convertedType: el === null || el === void 0 ? void 0 : el.type
|
|
283
|
+
});
|
|
235
284
|
break;
|
|
236
285
|
}
|
|
237
286
|
}
|
|
@@ -254,9 +303,19 @@ var removeAnswerTags = function(text) {
|
|
|
254
303
|
}
|
|
255
304
|
// 如果插件没有处理,使用默认处理逻辑
|
|
256
305
|
if (!pluginHandled) {
|
|
306
|
+
debugInfo("parserMarkdownToSlateNode.parseNodes - 使用默认处理 ".concat(i), {
|
|
307
|
+
elementType: currentElement === null || currentElement === void 0 ? void 0 : currentElement.type,
|
|
308
|
+
configKeys: Object.keys(config || {})
|
|
309
|
+
});
|
|
257
310
|
// 使用统一的处理函数,通过 this 访问配置和插件
|
|
258
311
|
var result = _this.handleSingleElement(currentElement, config, parent, htmlTag, preElement);
|
|
259
312
|
el = result.el;
|
|
313
|
+
debugInfo("parserMarkdownToSlateNode.parseNodes - 默认处理完成 ".concat(i), {
|
|
314
|
+
resultType: Array.isArray(el) ? 'array' : el === null || el === void 0 ? void 0 : el.type,
|
|
315
|
+
resultLength: Array.isArray(el) ? el.length : 1,
|
|
316
|
+
hasContextProps: !!result.contextProps,
|
|
317
|
+
hasHtmlTag: !!result.htmlTag
|
|
318
|
+
});
|
|
260
319
|
if (result.contextProps) {
|
|
261
320
|
contextProps = _object_spread({}, contextProps, result.contextProps);
|
|
262
321
|
}
|
|
@@ -281,16 +340,24 @@ var removeAnswerTags = function(text) {
|
|
|
281
340
|
preElement = el;
|
|
282
341
|
};
|
|
283
342
|
var top = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false, parent = arguments.length > 2 ? arguments[2] : void 0;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
343
|
+
debugInfo('parserMarkdownToSlateNode.parseNodes - 开始解析节点', {
|
|
344
|
+
nodesCount: nodes === null || nodes === void 0 ? void 0 : nodes.length,
|
|
345
|
+
top: top,
|
|
346
|
+
parentType: parent === null || parent === void 0 ? void 0 : parent.type
|
|
347
|
+
});
|
|
348
|
+
if (!(nodes === null || nodes === void 0 ? void 0 : nodes.length)) {
|
|
349
|
+
debugInfo('parserMarkdownToSlateNode.parseNodes - 空节点,返回默认段落');
|
|
350
|
+
return [
|
|
351
|
+
{
|
|
352
|
+
type: 'paragraph',
|
|
353
|
+
children: [
|
|
354
|
+
{
|
|
355
|
+
text: ''
|
|
356
|
+
}
|
|
357
|
+
]
|
|
358
|
+
}
|
|
359
|
+
];
|
|
360
|
+
}
|
|
294
361
|
var els = [];
|
|
295
362
|
var preNode = null;
|
|
296
363
|
var preElement = null;
|
|
@@ -298,6 +365,12 @@ var removeAnswerTags = function(text) {
|
|
|
298
365
|
var contextProps = {};
|
|
299
366
|
var pendingHtmlCommentProps = null;
|
|
300
367
|
for(var i = 0; i < nodes.length; i++)_this = this, _loop(i);
|
|
368
|
+
debugInfo('parserMarkdownToSlateNode.parseNodes - 所有节点解析完成', {
|
|
369
|
+
totalElements: els.length,
|
|
370
|
+
elementTypes: els.map(function(e) {
|
|
371
|
+
return (e === null || e === void 0 ? void 0 : e.type) || 'text';
|
|
372
|
+
})
|
|
373
|
+
});
|
|
301
374
|
return els;
|
|
302
375
|
}
|
|
303
376
|
},
|
|
@@ -410,9 +483,21 @@ var removeAnswerTags = function(text) {
|
|
|
410
483
|
value: function handleSingleElement(currentElement, config, parent, htmlTag, preElement) {
|
|
411
484
|
var _this = this;
|
|
412
485
|
var elementType = currentElement.type;
|
|
486
|
+
debugInfo('handleSingleElement - 开始处理元素', {
|
|
487
|
+
elementType: elementType,
|
|
488
|
+
hasConfig: !!config && Object.keys(config).length > 0,
|
|
489
|
+
configKeys: config ? Object.keys(config) : [],
|
|
490
|
+
parentType: parent === null || parent === void 0 ? void 0 : parent.type,
|
|
491
|
+
htmlTagLength: htmlTag === null || htmlTag === void 0 ? void 0 : htmlTag.length,
|
|
492
|
+
preElementType: preElement === null || preElement === void 0 ? void 0 : preElement.type
|
|
493
|
+
});
|
|
413
494
|
var elementHandlers = this.getElementHandlers();
|
|
414
495
|
var handlerInfo = elementHandlers[elementType];
|
|
415
496
|
if (handlerInfo === null || handlerInfo === void 0 ? void 0 : handlerInfo.needsHtmlResult) {
|
|
497
|
+
var _result_el;
|
|
498
|
+
debugInfo('handleSingleElement - 使用 HTML 结果处理', {
|
|
499
|
+
elementType: elementType
|
|
500
|
+
});
|
|
416
501
|
var htmlResult = handleHtml(currentElement, parent, htmlTag);
|
|
417
502
|
var result = {
|
|
418
503
|
el: htmlResult.el
|
|
@@ -423,16 +508,48 @@ var removeAnswerTags = function(text) {
|
|
|
423
508
|
if (htmlResult.htmlTag) {
|
|
424
509
|
result.htmlTag = htmlResult.htmlTag;
|
|
425
510
|
}
|
|
511
|
+
debugInfo('handleSingleElement - HTML 结果处理完成', {
|
|
512
|
+
elementType: elementType,
|
|
513
|
+
resultType: Array.isArray(result.el) ? 'array' : (_result_el = result.el) === null || _result_el === void 0 ? void 0 : _result_el.type,
|
|
514
|
+
hasContextProps: !!result.contextProps,
|
|
515
|
+
hasHtmlTag: !!result.htmlTag
|
|
516
|
+
});
|
|
426
517
|
return result;
|
|
427
518
|
}
|
|
428
519
|
if (!handlerInfo) {
|
|
429
|
-
|
|
520
|
+
var _result_el1;
|
|
521
|
+
debugInfo('handleSingleElement - 使用默认文本处理', {
|
|
522
|
+
elementType: elementType
|
|
523
|
+
});
|
|
524
|
+
var result1 = {
|
|
430
525
|
el: handleTextAndInlineElements(currentElement, htmlTag, function(nodes, top, parent) {
|
|
431
526
|
return _this.parseNodes(nodes, top, parent);
|
|
432
527
|
}, this.config)
|
|
433
528
|
};
|
|
529
|
+
debugInfo('handleSingleElement - 默认文本处理完成', {
|
|
530
|
+
elementType: elementType,
|
|
531
|
+
resultType: Array.isArray(result1.el) ? 'array' : (_result_el1 = result1.el) === null || _result_el1 === void 0 ? void 0 : _result_el1.type,
|
|
532
|
+
resultLength: Array.isArray(result1.el) ? result1.el.length : 1
|
|
533
|
+
});
|
|
534
|
+
return result1;
|
|
434
535
|
}
|
|
536
|
+
debugInfo('handleSingleElement - 调用元素处理器', {
|
|
537
|
+
elementType: elementType,
|
|
538
|
+
handlerExists: !!handlerInfo.handler
|
|
539
|
+
});
|
|
435
540
|
var handlerResult = handlerInfo.handler(currentElement, this.plugins, config, parent, htmlTag, preElement, this);
|
|
541
|
+
debugInfo('handleSingleElement - 元素处理完成', {
|
|
542
|
+
elementType: elementType,
|
|
543
|
+
resultType: Array.isArray(handlerResult) ? 'array' : handlerResult === null || handlerResult === void 0 ? void 0 : handlerResult.type,
|
|
544
|
+
resultLength: Array.isArray(handlerResult) ? handlerResult.length : 1,
|
|
545
|
+
resultPreview: Array.isArray(handlerResult) ? handlerResult.map(function(r) {
|
|
546
|
+
return {
|
|
547
|
+
type: r === null || r === void 0 ? void 0 : r.type
|
|
548
|
+
};
|
|
549
|
+
}) : {
|
|
550
|
+
type: handlerResult === null || handlerResult === void 0 ? void 0 : handlerResult.type
|
|
551
|
+
}
|
|
552
|
+
});
|
|
436
553
|
return {
|
|
437
554
|
el: handlerResult
|
|
438
555
|
};
|