@ant-design/agentic-ui 2.22.0 → 2.24.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/Editor.js +14 -3
- package/dist/MarkdownEditor/editor/parser/parse/parseCode.d.ts +2 -1
- package/dist/MarkdownEditor/editor/parser/parse/parseCode.js +15 -8
- package/dist/MarkdownEditor/editor/parser/parse/parseHtml.js +56 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseTable.js +2 -6
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.d.ts +3 -2
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.js +101 -3
- package/dist/MarkdownEditor/el.d.ts +7 -0
- package/package.json +1 -1
|
@@ -1165,12 +1165,23 @@ var defaultAllowedTypes = [
|
|
|
1165
1165
|
return decorateList;
|
|
1166
1166
|
}
|
|
1167
1167
|
};
|
|
1168
|
+
// 在 SSR 环境下,如果有 initSchemaValue,直接使用它作为初始值
|
|
1169
|
+
// 因为 useEffect 在 SSR 环境下不会执行,initialNote 不会被调用
|
|
1170
|
+
var initialValue = useMemo(function() {
|
|
1171
|
+
var _props_initSchemaValue;
|
|
1172
|
+
if ((_props_initSchemaValue = props.initSchemaValue) === null || _props_initSchemaValue === void 0 ? void 0 : _props_initSchemaValue.length) {
|
|
1173
|
+
return props.initSchemaValue;
|
|
1174
|
+
}
|
|
1175
|
+
return [
|
|
1176
|
+
EditorUtils.p
|
|
1177
|
+
];
|
|
1178
|
+
}, [
|
|
1179
|
+
props.initSchemaValue
|
|
1180
|
+
]);
|
|
1168
1181
|
var _obj;
|
|
1169
1182
|
return wrapSSR(/*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Slate, {
|
|
1170
1183
|
editor: markdownEditorRef.current,
|
|
1171
|
-
initialValue:
|
|
1172
|
-
EditorUtils.p
|
|
1173
|
-
],
|
|
1184
|
+
initialValue: initialValue,
|
|
1174
1185
|
onChange: onSlateChange
|
|
1175
1186
|
}, /*#__PURE__*/ React.createElement(Editable, {
|
|
1176
1187
|
decorate: decorateFn,
|
|
@@ -13,9 +13,10 @@ export type LanguageHandler = (element: CodeElement, value: string) => CodeEleme
|
|
|
13
13
|
/**
|
|
14
14
|
* 处理代码块节点
|
|
15
15
|
* @param currentElement - 当前处理的代码块元素,包含语言和内容
|
|
16
|
+
* @param config - 可选的配置对象,可能包含从 HTML 注释中解析的属性
|
|
16
17
|
* @returns 返回格式化的代码块节点对象,根据语言类型进行特殊处理
|
|
17
18
|
*/
|
|
18
|
-
export declare const handleCode: (currentElement: any) => CodeElement;
|
|
19
|
+
export declare const handleCode: (currentElement: any, config?: any) => CodeElement;
|
|
19
20
|
/**
|
|
20
21
|
* 处理YAML节点
|
|
21
22
|
* @param currentElement - 当前处理的YAML元素
|
|
@@ -101,11 +101,16 @@ var ENDING_NEWLINE = /\n$/;
|
|
|
101
101
|
/**
|
|
102
102
|
* 处理代码块节点
|
|
103
103
|
* @param currentElement - 当前处理的代码块元素,包含语言和内容
|
|
104
|
+
* @param config - 可选的配置对象,可能包含从 HTML 注释中解析的属性
|
|
104
105
|
* @returns 返回格式化的代码块节点对象,根据语言类型进行特殊处理
|
|
105
|
-
*/ export var handleCode = function(currentElement) {
|
|
106
|
-
var
|
|
106
|
+
*/ export var handleCode = function(currentElement, config) {
|
|
107
|
+
var _effectiveLang_match, _currentElement_otherProps, _currentElement_value_trim;
|
|
107
108
|
var rawValue = currentElement.value || '';
|
|
108
|
-
|
|
109
|
+
// 如果 config 中包含 data-language,优先使用它来恢复语言类型
|
|
110
|
+
var configLanguage = config === null || config === void 0 ? void 0 : config['data-language'];
|
|
111
|
+
// 保持原有的行为:如果没有语言,应该使用 null 而不是空字符串
|
|
112
|
+
var effectiveLang = configLanguage || currentElement.lang || null;
|
|
113
|
+
var langString = effectiveLang ? ((_effectiveLang_match = effectiveLang.match(NOT_SPACE_START)) === null || _effectiveLang_match === void 0 ? void 0 : _effectiveLang_match[0]) || '' : '';
|
|
109
114
|
var code = "".concat(rawValue.replace(ENDING_NEWLINE, ''), "\n");
|
|
110
115
|
// 检查代码块是否完整
|
|
111
116
|
// 如果是缩进代码块,认为是完整的(因为没有结束标记)
|
|
@@ -144,7 +149,7 @@ var ENDING_NEWLINE = /\n$/;
|
|
|
144
149
|
}
|
|
145
150
|
var baseCodeElement = {
|
|
146
151
|
type: 'code',
|
|
147
|
-
language:
|
|
152
|
+
language: effectiveLang === 'apaasify' ? 'apaasify' : effectiveLang || null,
|
|
148
153
|
render: currentElement.meta === 'render',
|
|
149
154
|
value: currentElement.value,
|
|
150
155
|
isConfig: currentElement === null || currentElement === void 0 ? void 0 : (_currentElement_value_trim = currentElement.value.trim()) === null || _currentElement_value_trim === void 0 ? void 0 : _currentElement_value_trim.startsWith('<!--'),
|
|
@@ -156,14 +161,16 @@ var ENDING_NEWLINE = /\n$/;
|
|
|
156
161
|
// 添加流式状态支持
|
|
157
162
|
otherProps: otherProps
|
|
158
163
|
};
|
|
159
|
-
var handler = LANGUAGE_HANDLERS[
|
|
164
|
+
var handler = LANGUAGE_HANDLERS[effectiveLang];
|
|
160
165
|
var result = handler ? handler(baseCodeElement, currentElement.value) : baseCodeElement;
|
|
161
|
-
// 确保 otherProps
|
|
166
|
+
// 确保 otherProps 被保留,并合并 config 中的属性
|
|
162
167
|
var resultWithProps = result;
|
|
163
168
|
if (baseCodeElement.otherProps && !resultWithProps.otherProps) {
|
|
164
|
-
resultWithProps.otherProps = baseCodeElement.otherProps;
|
|
169
|
+
resultWithProps.otherProps = _object_spread({}, baseCodeElement.otherProps, config || {});
|
|
165
170
|
} else if (baseCodeElement.otherProps && resultWithProps.otherProps) {
|
|
166
|
-
resultWithProps.otherProps = _object_spread({}, resultWithProps.otherProps, baseCodeElement.otherProps);
|
|
171
|
+
resultWithProps.otherProps = _object_spread({}, resultWithProps.otherProps, baseCodeElement.otherProps, config || {});
|
|
172
|
+
} else if (config && Object.keys(config).length > 0) {
|
|
173
|
+
resultWithProps.otherProps = _object_spread({}, resultWithProps.otherProps || {}, config);
|
|
167
174
|
}
|
|
168
175
|
return resultWithProps;
|
|
169
176
|
};
|
|
@@ -100,6 +100,10 @@ function _sliced_to_array(arr, i) {
|
|
|
100
100
|
function _to_consumable_array(arr) {
|
|
101
101
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
102
102
|
}
|
|
103
|
+
function _type_of(obj) {
|
|
104
|
+
"@swc/helpers - typeof";
|
|
105
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
106
|
+
}
|
|
103
107
|
function _unsupported_iterable_to_array(o, minLen) {
|
|
104
108
|
if (!o) return;
|
|
105
109
|
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
@@ -464,6 +468,38 @@ import partialJsonParse from "../json-parse";
|
|
|
464
468
|
}
|
|
465
469
|
var commentValue = isUnclosedComment ? processedValue : currentElement.value;
|
|
466
470
|
var isComment = commentValue.trim().startsWith('<!--') && commentValue.trim().endsWith('-->');
|
|
471
|
+
// 检查是否是 otherProps 序列化生成的 JSON 注释
|
|
472
|
+
// 这些注释应该被跳过,不应该被解析为 HTML 代码块
|
|
473
|
+
// 但是,如果注释包含图表配置(chartType),应该保留为 code 节点以便表格解析器使用
|
|
474
|
+
if (isComment) {
|
|
475
|
+
try {
|
|
476
|
+
var _parsed_;
|
|
477
|
+
var commentContent = commentValue.replace('<!--', '').replace('-->', '').trim();
|
|
478
|
+
var parsed = JSON.parse(commentContent);
|
|
479
|
+
// 检查是否是图表配置
|
|
480
|
+
var isChartConfig = // 对象格式:{"chartType": ...}
|
|
481
|
+
(typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) === 'object' && parsed !== null && !Array.isArray(parsed) && parsed.chartType || // 数组格式:[{"chartType": ...}]
|
|
482
|
+
Array.isArray(parsed) && parsed.length > 0 && _type_of(parsed[0]) === 'object' && ((_parsed_ = parsed[0]) === null || _parsed_ === void 0 ? void 0 : _parsed_.chartType);
|
|
483
|
+
// 如果能够成功解析为 JSON 对象,且是对象类型(不是数组或基本类型)
|
|
484
|
+
// 注意:对象格式的图表配置已经在 handleHtml 中转换为数组格式了
|
|
485
|
+
// 这里只处理非图表配置的对象格式注释
|
|
486
|
+
if ((typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) === 'object' && parsed !== null && !Array.isArray(parsed)) {
|
|
487
|
+
// 如果包含 chartType 字段,说明是图表配置,应该已经在 handleHtml 中转换为数组格式
|
|
488
|
+
// 这里不应该再匹配到对象格式的图表配置,继续正常处理
|
|
489
|
+
if (isChartConfig && parsed.chartType) {
|
|
490
|
+
// 继续正常处理,创建 code 节点(此时应该已经是数组格式了)
|
|
491
|
+
} else {
|
|
492
|
+
// 否则认为是 otherProps 序列化生成的注释,应该返回空文本
|
|
493
|
+
// 这些注释应该在 parserMarkdownToSlateNode 中被跳过
|
|
494
|
+
return {
|
|
495
|
+
text: ''
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
} catch (e) {
|
|
500
|
+
// 解析失败,不是 JSON 格式的注释,继续正常处理
|
|
501
|
+
}
|
|
502
|
+
}
|
|
467
503
|
if (isComment || isStandardHtmlElement(commentValue)) {
|
|
468
504
|
return commentValue.match(/<\/?(table|div|ul|li|ol|p|strong)[^\n>]*?>/) ? htmlToFragmentList(commentValue, '') : {
|
|
469
505
|
type: 'code',
|
|
@@ -682,6 +718,26 @@ import partialJsonParse from "../json-parse";
|
|
|
682
718
|
var trimmedValue = (currentElement === null || currentElement === void 0 ? void 0 : (_currentElement_value = currentElement.value) === null || _currentElement_value === void 0 ? void 0 : _currentElement_value.trim()) || '';
|
|
683
719
|
var isUnclosedComment = trimmedValue.startsWith('<!--') && !trimmedValue.endsWith('-->');
|
|
684
720
|
var processedValue = isUnclosedComment ? trimmedValue + '-->' : (currentElement === null || currentElement === void 0 ? void 0 : currentElement.value) || '';
|
|
721
|
+
// 检查是否是对象格式的图表配置,如果是则转换为数组格式
|
|
722
|
+
var isComment = processedValue.trim().startsWith('<!--') && processedValue.trim().endsWith('-->');
|
|
723
|
+
if (isComment) {
|
|
724
|
+
try {
|
|
725
|
+
var commentContent = processedValue.replace('<!--', '').replace('-->', '').trim();
|
|
726
|
+
var parsed = JSON.parse(commentContent);
|
|
727
|
+
// 如果是对象格式且包含 chartType,转换为数组格式
|
|
728
|
+
if ((typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) === 'object' && parsed !== null && !Array.isArray(parsed) && parsed.chartType) {
|
|
729
|
+
var arrayFormat = [
|
|
730
|
+
parsed
|
|
731
|
+
];
|
|
732
|
+
var convertedContent = JSON.stringify(arrayFormat);
|
|
733
|
+
processedValue = "<!--".concat(convertedContent, "-->");
|
|
734
|
+
// 同时更新 currentElement.value,以便后续处理使用
|
|
735
|
+
currentElement.value = processedValue;
|
|
736
|
+
}
|
|
737
|
+
} catch (e) {
|
|
738
|
+
// 解析失败,不是 JSON 格式的注释,继续正常处理
|
|
739
|
+
}
|
|
740
|
+
}
|
|
685
741
|
var value = (processedValue === null || processedValue === void 0 ? void 0 : processedValue.replace('<!--', '').replace('-->', '').trim()) || '{}';
|
|
686
742
|
var contextProps = parseCommentContextProps(value, processedValue);
|
|
687
743
|
var isBlockLevel = !parent || [
|
|
@@ -150,11 +150,7 @@ var myRemark = {
|
|
|
150
150
|
*/ export var parseTableOrChart = function(table, preNode, plugins, parseNodes, parserConfig) {
|
|
151
151
|
var _table_children, _tableHeader_children, _table_children_slice, _table_children1, _table_align, _chartConfig_, _config_at, _config_at1;
|
|
152
152
|
var keyMap = new Map();
|
|
153
|
-
|
|
154
|
-
var config = // @ts-ignore
|
|
155
|
-
(preNode === null || preNode === void 0 ? void 0 : preNode.type) === 'code' && // @ts-ignore
|
|
156
|
-
(preNode === null || preNode === void 0 ? void 0 : preNode.language) === 'html' && (// @ts-ignore
|
|
157
|
-
preNode === null || preNode === void 0 ? void 0 : preNode.otherProps) ? preNode === null || preNode === void 0 ? void 0 : preNode.otherProps : {};
|
|
153
|
+
var config = (preNode === null || preNode === void 0 ? void 0 : preNode.type) === 'code' && (preNode === null || preNode === void 0 ? void 0 : preNode.language) === 'html' && (preNode === null || preNode === void 0 ? void 0 : preNode.otherProps) ? preNode === null || preNode === void 0 ? void 0 : preNode.otherProps : parserConfig || {};
|
|
158
154
|
var tableHeader = table === null || table === void 0 ? void 0 : (_table_children = table.children) === null || _table_children === void 0 ? void 0 : _table_children.at(0);
|
|
159
155
|
var columns = (tableHeader === null || tableHeader === void 0 ? void 0 : (_tableHeader_children = tableHeader.children) === null || _tableHeader_children === void 0 ? void 0 : _tableHeader_children.map(function(node) {
|
|
160
156
|
var _myRemark_stringify;
|
|
@@ -239,7 +235,7 @@ var myRemark = {
|
|
|
239
235
|
chartConfig = convertObjectToArray(chartConfig);
|
|
240
236
|
var isChart = (chartConfig === null || chartConfig === void 0 ? void 0 : chartConfig.chartType) || Array.isArray(chartConfig) && (chartConfig === null || chartConfig === void 0 ? void 0 : (_chartConfig_ = chartConfig[0]) === null || _chartConfig_ === void 0 ? void 0 : _chartConfig_.chartType) || (config === null || config === void 0 ? void 0 : config.chartType) || (config === null || config === void 0 ? void 0 : (_config_at1 = config.at) === null || _config_at1 === void 0 ? void 0 : (_config_at = _config_at1.call(config, 0)) === null || _config_at === void 0 ? void 0 : _config_at.chartType);
|
|
241
237
|
// 计算合并单元格信息
|
|
242
|
-
var mergeCells = config.mergeCells || [];
|
|
238
|
+
var mergeCells = (config === null || config === void 0 ? void 0 : config.mergeCells) || [];
|
|
243
239
|
// 创建合并单元格映射,用于快速查找
|
|
244
240
|
var mergeMap = new Map();
|
|
245
241
|
mergeCells === null || mergeCells === void 0 ? void 0 : mergeCells.forEach(function(param) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Elements } from '../../el';
|
|
1
|
+
import { ChartTypeConfig, Elements } from '../../el';
|
|
2
2
|
import { MarkdownEditorPlugin } from '../../plugin';
|
|
3
3
|
/**
|
|
4
4
|
* 解析Markdown字符串的配置选项
|
|
@@ -10,6 +10,7 @@ export interface ParserMarkdownToSlateNodeConfig {
|
|
|
10
10
|
paragraphTag?: string;
|
|
11
11
|
/** 是否正在输入中(打字机模式) */
|
|
12
12
|
typing?: boolean;
|
|
13
|
+
config?: ChartTypeConfig[];
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* Markdown 到 Slate 节点解析器类
|
|
@@ -18,7 +19,7 @@ export interface ParserMarkdownToSlateNodeConfig {
|
|
|
18
19
|
* 使用类形式可以避免在函数调用链中传递配置参数和插件。
|
|
19
20
|
*/
|
|
20
21
|
export declare class MarkdownToSlateParser {
|
|
21
|
-
private
|
|
22
|
+
private config;
|
|
22
23
|
private readonly plugins;
|
|
23
24
|
constructor(config?: ParserMarkdownToSlateNodeConfig, plugins?: MarkdownEditorPlugin[]);
|
|
24
25
|
/**
|
|
@@ -59,9 +59,37 @@ function _object_spread(target) {
|
|
|
59
59
|
}
|
|
60
60
|
return target;
|
|
61
61
|
}
|
|
62
|
+
function ownKeys(object, enumerableOnly) {
|
|
63
|
+
var keys = Object.keys(object);
|
|
64
|
+
if (Object.getOwnPropertySymbols) {
|
|
65
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
66
|
+
if (enumerableOnly) {
|
|
67
|
+
symbols = symbols.filter(function(sym) {
|
|
68
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
keys.push.apply(keys, symbols);
|
|
72
|
+
}
|
|
73
|
+
return keys;
|
|
74
|
+
}
|
|
75
|
+
function _object_spread_props(target, source) {
|
|
76
|
+
source = source != null ? source : {};
|
|
77
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
78
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
79
|
+
} else {
|
|
80
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
81
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return target;
|
|
85
|
+
}
|
|
62
86
|
function _to_consumable_array(arr) {
|
|
63
87
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
64
88
|
}
|
|
89
|
+
function _type_of(obj) {
|
|
90
|
+
"@swc/helpers - typeof";
|
|
91
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
92
|
+
}
|
|
65
93
|
function _unsupported_iterable_to_array(o, minLen) {
|
|
66
94
|
if (!o) return;
|
|
67
95
|
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
@@ -137,10 +165,76 @@ import mdastParser from "./remarkParse";
|
|
|
137
165
|
* - 插件未处理时,使用默认处理逻辑
|
|
138
166
|
*/ function parseNodes(nodes) {
|
|
139
167
|
var _this, _loop = function(i) {
|
|
168
|
+
var _currentElement_value_trim, _currentElement_value, _currentElement_value_trim1, _currentElement_value1;
|
|
140
169
|
var currentElement = nodes[i];
|
|
141
170
|
var el = null;
|
|
142
171
|
var pluginHandled = false;
|
|
143
|
-
|
|
172
|
+
// 检查当前元素是否是 HTML 注释
|
|
173
|
+
var isHtmlComment = currentElement.type === 'html' && ((_currentElement_value = currentElement.value) === null || _currentElement_value === void 0 ? void 0 : (_currentElement_value_trim = _currentElement_value.trim()) === null || _currentElement_value_trim === void 0 ? void 0 : _currentElement_value_trim.startsWith('<!--')) && ((_currentElement_value1 = currentElement.value) === null || _currentElement_value1 === void 0 ? void 0 : (_currentElement_value_trim1 = _currentElement_value1.trim()) === null || _currentElement_value_trim1 === void 0 ? void 0 : _currentElement_value_trim1.endsWith('-->'));
|
|
174
|
+
var htmlCommentProps = {};
|
|
175
|
+
var isOtherPropsComment = false;
|
|
176
|
+
if (isHtmlComment) {
|
|
177
|
+
try {
|
|
178
|
+
var commentContent = currentElement.value.replace('<!--', '').replace('-->', '').trim();
|
|
179
|
+
htmlCommentProps = JSON.parse(commentContent);
|
|
180
|
+
// 如果能够成功解析为 JSON 对象,且是对象类型(不是数组或基本类型)
|
|
181
|
+
if ((typeof htmlCommentProps === "undefined" ? "undefined" : _type_of(htmlCommentProps)) === 'object' && htmlCommentProps !== null && !Array.isArray(htmlCommentProps)) {
|
|
182
|
+
// 检查是否包含代码块的元数据属性(data-language、data-block、data-state)
|
|
183
|
+
// 这些属性表明这是代码块的 otherProps 序列化生成的注释
|
|
184
|
+
var hasCodeMetadataProps = htmlCommentProps['data-language'] || htmlCommentProps['data-block'] || htmlCommentProps['data-state'];
|
|
185
|
+
// 只有当包含代码块元数据属性时,才认为是 otherProps 注释
|
|
186
|
+
// 对齐注释(如 {"align":"center"})不包含这些属性,应该被保留
|
|
187
|
+
isOtherPropsComment = hasCodeMetadataProps;
|
|
188
|
+
}
|
|
189
|
+
if (Array.isArray(htmlCommentProps)) {
|
|
190
|
+
htmlCommentProps = {
|
|
191
|
+
config: htmlCommentProps
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
} catch (e) {
|
|
195
|
+
// 解析失败,不是 JSON 格式的注释,可能是真正的 HTML 注释
|
|
196
|
+
isOtherPropsComment = false;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
var nextElement = i + 1 < nodes.length ? nodes[i + 1] : null;
|
|
200
|
+
var isNextCodeBlock = (nextElement === null || nextElement === void 0 ? void 0 : nextElement.type) === 'code';
|
|
201
|
+
// 如果 HTML 注释是代码块的 otherProps 序列化生成的,应该跳过,避免被解析为独立的 HTML 代码节点
|
|
202
|
+
// 如果后面跟着代码块,存储注释属性供代码块使用
|
|
203
|
+
if (isHtmlComment && isOtherPropsComment) {
|
|
204
|
+
if (isNextCodeBlock) {
|
|
205
|
+
// 后面有代码块,存储属性供代码块使用
|
|
206
|
+
pendingHtmlCommentProps = htmlCommentProps;
|
|
207
|
+
}
|
|
208
|
+
// 无论后面是否有代码块,都跳过 HTML 注释,避免生成独立的 HTML 代码节点
|
|
209
|
+
return "continue";
|
|
210
|
+
}
|
|
211
|
+
// 确定要使用的 config:优先使用待处理的 HTML 注释属性,否则使用前一个 HTML 代码节点的属性
|
|
212
|
+
var config = pendingHtmlCommentProps ? pendingHtmlCommentProps : (preElement === null || preElement === void 0 ? void 0 : preElement.type) === 'code' && (preElement === null || preElement === void 0 ? void 0 : preElement.language) === 'html' && (preElement === null || preElement === void 0 ? void 0 : preElement.otherProps) ? preElement === null || preElement === void 0 ? void 0 : preElement.otherProps : {};
|
|
213
|
+
// 如果 HTML 注释不是代码块元数据注释,但包含 JSON 对象属性(如对齐注释),
|
|
214
|
+
// 应该跳过注释本身,但将属性应用到下一个元素
|
|
215
|
+
if (isHtmlComment && !isOtherPropsComment && htmlCommentProps && Object.keys(htmlCommentProps).length > 0) {
|
|
216
|
+
if (!Array.isArray(htmlCommentProps)) {
|
|
217
|
+
// 将对齐注释等非代码块元数据注释的属性存储到 contextProps 中,供下一个元素使用
|
|
218
|
+
contextProps = _object_spread({}, contextProps, htmlCommentProps);
|
|
219
|
+
// 同时将属性作为 config 传递,以便 applyContextPropsAndConfig 设置 otherProps
|
|
220
|
+
config = _object_spread({}, config, htmlCommentProps, contextProps);
|
|
221
|
+
// 跳过 HTML 注释本身,避免生成独立的 HTML 代码节点
|
|
222
|
+
return "continue";
|
|
223
|
+
} else {
|
|
224
|
+
config = _object_spread_props(_object_spread({}, config), {
|
|
225
|
+
config: _to_consumable_array((config === null || config === void 0 ? void 0 : config.config) || []).concat(_to_consumable_array(htmlCommentProps))
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// 如果当前元素应该使用 contextProps 中的属性作为 config(用于设置 otherProps)
|
|
230
|
+
// 这主要针对对齐注释等场景,需要同时设置 contextProps 和 otherProps
|
|
231
|
+
if (contextProps && Object.keys(contextProps).length > 0) {
|
|
232
|
+
config = _object_spread({}, config, contextProps);
|
|
233
|
+
}
|
|
234
|
+
// 如果使用了待处理的 HTML 注释属性,清空它
|
|
235
|
+
if (pendingHtmlCommentProps && config === pendingHtmlCommentProps) {
|
|
236
|
+
pendingHtmlCommentProps = null;
|
|
237
|
+
}
|
|
144
238
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
145
239
|
try {
|
|
146
240
|
// 首先尝试使用插件处理,使用 this.plugins
|
|
@@ -178,6 +272,9 @@ import mdastParser from "./remarkParse";
|
|
|
178
272
|
}
|
|
179
273
|
}
|
|
180
274
|
}
|
|
275
|
+
if (Object.keys(config).length > 0) {
|
|
276
|
+
_this.config = _object_spread({}, _this.config, config);
|
|
277
|
+
}
|
|
181
278
|
// 如果插件没有处理,使用默认处理逻辑
|
|
182
279
|
if (!pluginHandled) {
|
|
183
280
|
// 使用统一的处理函数,通过 this 访问配置和插件
|
|
@@ -222,6 +319,7 @@ import mdastParser from "./remarkParse";
|
|
|
222
319
|
var preElement = null;
|
|
223
320
|
var htmlTag = [];
|
|
224
321
|
var contextProps = {};
|
|
322
|
+
var pendingHtmlCommentProps = null;
|
|
225
323
|
for(var i = 0; i < nodes.length; i++)_this = this, _loop(i);
|
|
226
324
|
return els;
|
|
227
325
|
}
|
|
@@ -278,8 +376,8 @@ import mdastParser from "./remarkParse";
|
|
|
278
376
|
}
|
|
279
377
|
},
|
|
280
378
|
code: {
|
|
281
|
-
handler: function(el) {
|
|
282
|
-
return handleCode(el);
|
|
379
|
+
handler: function(el, _plugins, config) {
|
|
380
|
+
return handleCode(el, config);
|
|
283
381
|
}
|
|
284
382
|
},
|
|
285
383
|
yaml: {
|
|
@@ -17,7 +17,14 @@ export type CodeNode<T = Record<string, any>> = {
|
|
|
17
17
|
className?: string;
|
|
18
18
|
language?: string;
|
|
19
19
|
render?: boolean;
|
|
20
|
+
mergeCells?: Array<{
|
|
21
|
+
row: number;
|
|
22
|
+
col: number;
|
|
23
|
+
rowSpan: number;
|
|
24
|
+
colSpan: number;
|
|
25
|
+
}>;
|
|
20
26
|
frontmatter?: boolean;
|
|
27
|
+
config?: Record<string, any>[];
|
|
21
28
|
} & T;
|
|
22
29
|
children: [{
|
|
23
30
|
text: string;
|