@ant-design/agentic-ui 2.29.57 → 2.29.58
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/parser/constants.d.ts +7 -0
- package/dist/MarkdownEditor/editor/parser/constants.js +16 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseTable.js +10 -3
- package/dist/MarkdownEditor/editor/parser/parse/parseText.js +20 -0
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.js +3 -1
- package/dist/MarkdownEditor/editor/utils/markdownToHtml.d.ts +19 -0
- package/dist/MarkdownEditor/editor/utils/markdownToHtml.js +4 -1
- package/package.json +1 -1
|
@@ -3,3 +3,10 @@
|
|
|
3
3
|
* 在 markdown 解析前替换,渲染与序列化时还原为 $。
|
|
4
4
|
*/
|
|
5
5
|
export declare const JINJA_DOLLAR_PLACEHOLDER = "\uE01A";
|
|
6
|
+
/**
|
|
7
|
+
* 保护时间格式(如 02:20:31)不被 remark-directive 误解析为 textDirective。
|
|
8
|
+
* remark-directive 会将 ":20"、":31" 等解析为指令,导致 "Cannot handle unknown node textDirective"。
|
|
9
|
+
* 在数字与冒号间插入零宽空格 \u200B 以阻断误解析。
|
|
10
|
+
* 须在 remark-directive 解析前执行。
|
|
11
|
+
*/
|
|
12
|
+
export declare function preprocessProtectTimeFromDirective(markdown: string): string;
|
|
@@ -2,3 +2,19 @@
|
|
|
2
2
|
* 占位符:保护 Jinja 块内 $ 不被 remark-math 解析为数学公式。
|
|
3
3
|
* 在 markdown 解析前替换,渲染与序列化时还原为 $。
|
|
4
4
|
*/ export var JINJA_DOLLAR_PLACEHOLDER = '\uE01A';
|
|
5
|
+
/** URL 协议占位符,用于保护时间格式预处理时不影响 https:// 等 */ var URL_PROTOCOL_PLACEHOLDER = '\uE01B\uE01B';
|
|
6
|
+
/**
|
|
7
|
+
* 保护时间格式(如 02:20:31)不被 remark-directive 误解析为 textDirective。
|
|
8
|
+
* remark-directive 会将 ":20"、":31" 等解析为指令,导致 "Cannot handle unknown node textDirective"。
|
|
9
|
+
* 在数字与冒号间插入零宽空格 \u200B 以阻断误解析。
|
|
10
|
+
* 须在 remark-directive 解析前执行。
|
|
11
|
+
*/ export function preprocessProtectTimeFromDirective(markdown) {
|
|
12
|
+
if (!markdown || markdown.length === 0) return markdown;
|
|
13
|
+
var withProtocolProtected = markdown.replace(/:\/\//g, URL_PROTOCOL_PLACEHOLDER);
|
|
14
|
+
// 使用反斜杠转义冒号,阻止 ":20"、":31" 等被 remark-directive 解析为 textDirective
|
|
15
|
+
// remark-directive 官方推荐:\:port 可防止 :port 被解析为指令
|
|
16
|
+
var withTimeProtected = withProtocolProtected.replace(/:(\d)/g, function(_, d) {
|
|
17
|
+
return "\\:".concat(d);
|
|
18
|
+
});
|
|
19
|
+
return withTimeProtected.replace(/\uE01B\uE01B/g, '://');
|
|
20
|
+
}
|
|
@@ -65,6 +65,7 @@ import { convertParagraphToImage, fixStrongWithSpecialChars } from "../remarkPar
|
|
|
65
65
|
import rehypeKatex from "rehype-katex";
|
|
66
66
|
import remarkFrontmatter from "remark-frontmatter";
|
|
67
67
|
import { EditorUtils } from "../../utils";
|
|
68
|
+
import { REMARK_REHYPE_DIRECTIVE_HANDLERS } from "../../utils/markdownToHtml";
|
|
68
69
|
// 表格相关常量
|
|
69
70
|
export var MIN_TABLE_CELL_LENGTH = 5; // 表格单元格最小长度
|
|
70
71
|
export var tableRegex = /^\|.*\|\s*\n\|[-:| ]+\|/m;
|
|
@@ -72,7 +73,8 @@ export var tableRegex = /^\|.*\|\s*\n\|[-:| ]+\|/m;
|
|
|
72
73
|
var stringifyObj = remark().use(remarkParse).use(fixStrongWithSpecialChars).use(convertParagraphToImage).use(remarkMath, {
|
|
73
74
|
singleDollarTextMath: false
|
|
74
75
|
}).use(remarkRehype, {
|
|
75
|
-
allowDangerousHtml: true
|
|
76
|
+
allowDangerousHtml: true,
|
|
77
|
+
handlers: REMARK_REHYPE_DIRECTIVE_HANDLERS
|
|
76
78
|
}).use(rehypeRaw).use(rehypeKatex).use(remarkGfm, {
|
|
77
79
|
singleTilde: false
|
|
78
80
|
}) // 禁用单波浪线删除线
|
|
@@ -81,8 +83,13 @@ var stringifyObj = remark().use(remarkParse).use(fixStrongWithSpecialChars).use(
|
|
|
81
83
|
]);
|
|
82
84
|
var myRemark = {
|
|
83
85
|
stringify: function stringify(obj) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
try {
|
|
87
|
+
var mdStr = stringifyObj.stringify(obj);
|
|
88
|
+
return mdStr;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error('myRemark.stringify error', obj);
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
86
93
|
}
|
|
87
94
|
};
|
|
88
95
|
/**
|
|
@@ -167,6 +167,17 @@ import { shouldTreatInlineMathAsText } from "./parseMath";
|
|
|
167
167
|
}
|
|
168
168
|
continue;
|
|
169
169
|
}
|
|
170
|
+
// remark-directive 的 textDirective/leafDirective,提取其 children 的文本内容
|
|
171
|
+
if (n.type === 'textDirective' || n.type === 'leafDirective') {
|
|
172
|
+
var directiveResult = parseText(n.children || [], leaf);
|
|
173
|
+
leafs = leafs.concat(directiveResult);
|
|
174
|
+
if (directiveResult.length === 0 && hasFormattingProps(leaf)) {
|
|
175
|
+
leafs.push(_object_spread_props(_object_spread({}, leaf), {
|
|
176
|
+
text: ''
|
|
177
|
+
}));
|
|
178
|
+
}
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
170
181
|
// @ts-ignore
|
|
171
182
|
leafs.push(_object_spread_props(_object_spread({}, leaf), {
|
|
172
183
|
text: n.value || ''
|
|
@@ -269,6 +280,15 @@ import { shouldTreatInlineMathAsText } from "./parseMath";
|
|
|
269
280
|
var inlineCodeResult = handleInlineCode(currentElement);
|
|
270
281
|
return _object_spread({}, leafWithHtmlTags, inlineCodeResult);
|
|
271
282
|
}
|
|
283
|
+
// remark-directive 的 textDirective/leafDirective,递归解析其 children
|
|
284
|
+
if (elementType === 'textDirective' || elementType === 'leafDirective') {
|
|
285
|
+
var _ref;
|
|
286
|
+
var children = currentElement.children || [];
|
|
287
|
+
var parsed = parseNodesFn(children, false, currentElement);
|
|
288
|
+
return (_ref = parsed === null || parsed === void 0 ? void 0 : parsed.at(0)) !== null && _ref !== void 0 ? _ref : {
|
|
289
|
+
text: ''
|
|
290
|
+
};
|
|
291
|
+
}
|
|
272
292
|
// 处理内联元素(strong, link, emphasis, delete)
|
|
273
293
|
var inlineElementTypes = [
|
|
274
294
|
'strong',
|
|
@@ -103,6 +103,7 @@ import { handleBlockquote, handleContainerDirective, handleFootnoteDefinition, h
|
|
|
103
103
|
import { handleCode, handleYaml } from "./parse/parseCode";
|
|
104
104
|
import { handleDefinition, handleInlineCode, handleThematicBreak } from "./parse/parseElements";
|
|
105
105
|
import { addEmptyLinesIfNeeded } from "./parse/parseEmptyLines";
|
|
106
|
+
import { preprocessProtectTimeFromDirective } from "./constants";
|
|
106
107
|
import { handleFootnoteReference } from "./parse/parseFootnote";
|
|
107
108
|
import { handleHtml, preprocessNonStandardHtmlTags, preprocessThinkTags } from "./parse/parseHtml";
|
|
108
109
|
import { handleInlineMath, handleMath } from "./parse/parseMath";
|
|
@@ -235,7 +236,8 @@ var removeAnswerTags = function removeAnswerTags(text) {
|
|
|
235
236
|
{
|
|
236
237
|
key: "preprocessMarkdown",
|
|
237
238
|
value: function preprocessMarkdown(md) {
|
|
238
|
-
var
|
|
239
|
+
var timeProtected = preprocessProtectTimeFromDirective(md || '');
|
|
240
|
+
var thinkProcessed = removeAnswerTags(preprocessThinkTags(timeProtected));
|
|
239
241
|
var nonStandardProcessed = removeAnswerTags(preprocessNonStandardHtmlTags(thinkProcessed));
|
|
240
242
|
return preprocessMarkdownTableNewlines(nonStandardProcessed);
|
|
241
243
|
}
|
|
@@ -19,6 +19,24 @@ export interface MarkdownToHtmlConfig {
|
|
|
19
19
|
* @returns 转义后的字符串
|
|
20
20
|
*/
|
|
21
21
|
export declare function escapeHtml(html: string, encode?: boolean): string;
|
|
22
|
+
/**
|
|
23
|
+
* mdast-util-to-hast 自定义 handler:将 remark-directive 的 textDirective 转为 span 元素
|
|
24
|
+
* 避免 "Cannot handle unknown node textDirective" 错误
|
|
25
|
+
*/
|
|
26
|
+
declare function textDirectiveHandler(state: any, node: any): any;
|
|
27
|
+
/**
|
|
28
|
+
* mdast-util-to-hast 自定义 handler:将 remark-directive 的 leafDirective 转为 span 元素
|
|
29
|
+
* 避免 "Cannot handle unknown node leafDirective" 错误
|
|
30
|
+
*/
|
|
31
|
+
declare function leafDirectiveHandler(state: any, node: any): any;
|
|
32
|
+
/**
|
|
33
|
+
* remark-rehype 的 directive 节点 handlers,用于避免 "Cannot handle unknown node textDirective" 等错误
|
|
34
|
+
* 可复用于 parseTable 等其他使用 remark-rehype 的场景
|
|
35
|
+
*/
|
|
36
|
+
export declare const REMARK_REHYPE_DIRECTIVE_HANDLERS: {
|
|
37
|
+
textDirective: typeof textDirectiveHandler;
|
|
38
|
+
leafDirective: typeof leafDirectiveHandler;
|
|
39
|
+
};
|
|
22
40
|
export declare const DEFAULT_MARKDOWN_REMARK_PLUGINS: readonly MarkdownRemarkPlugin[];
|
|
23
41
|
/**
|
|
24
42
|
* 将 Markdown 内容转换为 HTML(异步版本)
|
|
@@ -85,3 +103,4 @@ export declare const markdownToHtml: (markdown: string, plugins?: MarkdownToHtml
|
|
|
85
103
|
* - 同步版本可能影响用户界面响应性
|
|
86
104
|
*/
|
|
87
105
|
export declare const markdownToHtmlSync: (markdown: string, plugins?: MarkdownToHtmlOptions, config?: MarkdownToHtmlConfig) => string;
|
|
106
|
+
export {};
|
|
@@ -255,7 +255,10 @@ var remarkRehypePlugin = remarkRehype;
|
|
|
255
255
|
state.patch(node, result);
|
|
256
256
|
return state.applyData(node, result);
|
|
257
257
|
}
|
|
258
|
-
|
|
258
|
+
/**
|
|
259
|
+
* remark-rehype 的 directive 节点 handlers,用于避免 "Cannot handle unknown node textDirective" 等错误
|
|
260
|
+
* 可复用于 parseTable 等其他使用 remark-rehype 的场景
|
|
261
|
+
*/ export var REMARK_REHYPE_DIRECTIVE_HANDLERS = {
|
|
259
262
|
textDirective: textDirectiveHandler,
|
|
260
263
|
leafDirective: leafDirectiveHandler
|
|
261
264
|
};
|