function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_without_holes(arr) {
    if (Array.isArray(arr)) return _array_like_to_array(arr);
}
function _class_call_check(instance, Constructor) {
    if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
    }
}
function _defineProperties(target, props) {
    for(var i = 0; i < props.length; i++){
        var descriptor = props[i];
        descriptor.enumerable = descriptor.enumerable || false;
        descriptor.configurable = true;
        if ("value" in descriptor) descriptor.writable = true;
        Object.defineProperty(target, descriptor.key, descriptor);
    }
}
function _create_class(Constructor, protoProps, staticProps) {
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
    if (staticProps) _defineProperties(Constructor, staticProps);
    return Constructor;
}
function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _iterable_to_array(iter) {
    if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _non_iterable_spread() {
    throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
function _to_consumable_array(arr) {
    return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
}
function _type_of(obj) {
    "@swc/helpers - typeof";
    return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
import { preprocessNormalizeLeafToContainerDirective } from "./constants";
import { applyContextPropsAndConfig } from "./parse/applyContextPropsAndConfig";
import { handleBlockquote, handleContainerDirective, handleFootnoteDefinition, handleHeading, handleList, handleListItem, handleParagraph, handleTextAndInlineElements } from "./parse/parseBlockElements";
import { handleCode, handleYaml } from "./parse/parseCode";
import { handleDefinition, handleInlineCode, handleThematicBreak } from "./parse/parseElements";
import { addEmptyLinesIfNeeded } from "./parse/parseEmptyLines";
import { handleFootnoteReference } from "./parse/parseFootnote";
import { handleHtml, preprocessNonStandardHtmlTags, preprocessThinkTags } from "./parse/parseHtml";
import { handleInlineMath, handleMath } from "./parse/parseMath";
import { handleImage } from "./parse/parseMedia";
import { parseTableOrChart, preprocessMarkdownTableNewlines } from "./parse/parseTable";
import mdastParser from "./remarkParse";
// 全局解析缓存
var parseCache = new Map();
/**
 * 清空解析缓存
 */ export var clearParseCache = function clearParseCache() {
    parseCache.clear();
};
/** 从 mdast 节点提取纯文本（用于识别仅含 ::: 的闭合标记段落） */ function getMdastNodeText(node) {
    if (!node || (typeof node === "undefined" ? "undefined" : _type_of(node)) !== 'object') return '';
    var n = node;
    if (n.type === 'text' && n.value !== undefined && n.value !== null) return String(n.value);
    if (Array.isArray(n.children)) {
        return n.children.map(function(c) {
            return getMdastNodeText(c);
        }).join('');
    }
    return '';
}
/**
 * 生成简单的字符串哈希
 */ export var simpleHash = function simpleHash(str) {
    var hash = 0;
    for(var i = 0; i < str.length; i++){
        var char = str.charCodeAt(i);
        hash = (hash << 5) - hash + char;
        hash = hash & hash;
    }
    return hash.toString(36);
};
/**
 * 将 Markdown 文本按块分割
 * 正确处理代码块、HTML 标签、脚注等内容
 * 返回带有内容和哈希的块数组
 */ var splitMarkdownIntoBlocks = function splitMarkdownIntoBlocks(md, config, plugins) {
    var blocks = [];
    var currentBlock = '';
    var inCodeBlock = false;
    var htmlTagDepth = 0;
    var lines = md.split('\n');
    for(var i = 0; i < lines.length; i++){
        var line = lines[i];
        // 检测代码块开始/结束
        if (line.trim().startsWith('```')) {
            inCodeBlock = !inCodeBlock;
        }
        // 检测 HTML 标签深度（非代码块时）
        if (!inCodeBlock) {
            var openTags = (line.match(/<[a-zA-Z][^/>]*>/g) || []).length;
            var closeTags = (line.match(/<\/[a-zA-Z][^>]*>/g) || []).length;
            var selfClosing = (line.match(/<[^>]*\/>/g) || []).length;
            htmlTagDepth += openTags - closeTags - selfClosing;
            htmlTagDepth = Math.max(0, htmlTagDepth);
        }
        // 检查当前块是否以 HTML 结尾（注释或标签）
        var blockEndsWithHtml = /<!--[\s\S]*?-->$|<[^>]+>$/.test(currentBlock.trim());
        // 检查当前块是否包含脚注引用（需要和脚注定义一起解析）
        var hasFootnoteRef = /\[\^[^\]]+\]/.test(currentBlock);
        // 检查下一行是否是脚注定义
        var nextLineIsFootnoteDef = i + 1 < lines.length && /^\[\^[^\]]+\]:/.test(lines[i + 1].trim());
        // 只有在非代码块、非 HTML 块、且当前块不以 HTML 结尾、且不涉及脚注时，连续空行才作为分割点
        var isBlockBoundary = line === '' && !inCodeBlock && htmlTagDepth === 0 && !blockEndsWithHtml && !hasFootnoteRef && !nextLineIsFootnoteDef && currentBlock.endsWith('\n');
        if (isBlockBoundary) {
            if (currentBlock.trim()) {
                blocks.push(currentBlock.trim());
            }
            currentBlock = '';
            continue;
        }
        currentBlock += line + '\n';
    }
    if (currentBlock.trim()) {
        blocks.push(currentBlock.trim());
    }
    // 合并小于 100 个字符的块到下一个块，同时处理包含 --- 的块
    var MIN_BLOCK_SIZE = 100;
    var mergedBlocks = [];
    for(var i1 = 0; i1 < blocks.length; i1++){
        var block = blocks[i1];
        // 检查当前块是否包含 --- (frontmatter 分隔符或 thematic break)
        // 如果包含 ---，且有上一个块，则合并到上一个块
        var containsHr = /^---\s*$/m.test(block);
        if (containsHr && mergedBlocks.length > 0) {
            mergedBlocks[mergedBlocks.length - 1] += '\n\n' + block;
            continue;
        }
        // 如果当前块小于 100 个字符，且有下一个块，则合并到下一个块
        if (block.length < MIN_BLOCK_SIZE && i1 + 1 < blocks.length) {
            blocks[i1 + 1] = block + '\n\n' + blocks[i1 + 1];
            continue;
        }
        mergedBlocks.push(block);
    }
    // 生成带哈希的块数组
    var configStr = config ? JSON.stringify(config) : '';
    var pluginsCount = (plugins === null || plugins === void 0 ? void 0 : plugins.length) || 0;
    var configHash = simpleHash("".concat(configStr, "_").concat(pluginsCount));
    return mergedBlocks.map(function(content, index) {
        return {
            content: content,
            hash: "".concat(simpleHash(content), "_").concat(configHash, "_").concat(index)
        };
    });
};
// 删除 <answer> 和 </answer> 标签，保留中间内容
var removeAnswerTags = function removeAnswerTags(text) {
    return text.replace(/<answer>\s*/g, '').replace(/\s*<\/answer>/g, '');
};
/**
 * Markdown 到 Slate 节点解析器类
 *
 * 将 Markdown 字符串解析为 Slate 编辑器节点，支持配置选项和插件。
 * 使用类形式可以避免在函数调用链中传递配置参数和插件。
 */ export var MarkdownToSlateParser = /*#__PURE__*/ function() {
    "use strict";
    function MarkdownToSlateParser() {
        var config = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, plugins = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
        _class_call_check(this, MarkdownToSlateParser);
        _define_property(this, "config", void 0);
        _define_property(this, "plugins", void 0);
        this.config = config;
        this.plugins = plugins;
    }
    _create_class(MarkdownToSlateParser, [
        {
            key: "preprocessMarkdown",
            value: function preprocessMarkdown(md) {
                var thinkProcessed = removeAnswerTags(preprocessThinkTags(md || ''));
                var nonStandardProcessed = removeAnswerTags(preprocessNonStandardHtmlTags(thinkProcessed));
                var tableProcessed = preprocessMarkdownTableNewlines(nonStandardProcessed);
                return preprocessNormalizeLeafToContainerDirective(tableProcessed);
            }
        },
        {
            key: "buildMarkdownRoot",
            value: function buildMarkdownRoot(md) {
                var preprocessedMarkdown = this.preprocessMarkdown(md);
                var ast = mdastParser.parse(preprocessedMarkdown);
                var processedMarkdown = mdastParser.runSync(ast);
                return processedMarkdown.children;
            }
        },
        {
            key: "filterTopLevelSchema",
            value: function filterTopLevelSchema(schema) {
                return schema === null || schema === void 0 ? void 0 : schema.filter(function(item) {
                    var _item_children, _item_children1;
                    if (item.type === 'paragraph' && !((_item_children = item.children) === null || _item_children === void 0 ? void 0 : _item_children.length)) {
                        return false;
                    }
                    if (item.type === 'paragraph' && ((_item_children1 = item.children) === null || _item_children1 === void 0 ? void 0 : _item_children1.length) === 1) {
                        if (item.children[0].text === '\n' || item.children[0].text === undefined) {
                            return false;
                        }
                        return true;
                    }
                    return true;
                });
            }
        },
        {
            key: "createEmptyParagraph",
            value: function createEmptyParagraph() {
                return {
                    type: 'paragraph',
                    children: [
                        {
                            text: ''
                        }
                    ]
                };
            }
        },
        {
            key: "createParseContext",
            value: function createParseContext() {
                return {
                    preNode: null,
                    preElement: null,
                    htmlTag: [],
                    contextProps: {}
                };
            }
        },
        {
            key: "parseHtmlCommentProps",
            value: function parseHtmlCommentProps(currentElement) {
                var htmlValue = currentElement === null || currentElement === void 0 ? void 0 : currentElement.value;
                var isHtmlComment = currentElement.type === 'html' && typeof htmlValue === 'string' && htmlValue.trim().startsWith('<!--') && htmlValue.trim().endsWith('-->');
                if (!isHtmlComment) {
                    return null;
                }
                try {
                    var commentContent = htmlValue.replace('<!--', '').replace('-->', '').trim();
                    var parsed = JSON.parse(commentContent);
                    if (Array.isArray(parsed)) {
                        return {
                            config: parsed
                        };
                    }
                    if (parsed && Object.keys(parsed).length > 0) {
                        return parsed;
                    }
                    return null;
                } catch (e) {
                    return null;
                }
            }
        },
        {
            key: "resolveConfig",
            value: function resolveConfig(preElement, contextProps) {
                var baseConfig = (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 : {};
                if (contextProps && Object.keys(contextProps).length > 0) {
                    return _object_spread({}, baseConfig, contextProps);
                }
                return baseConfig;
            }
        },
        {
            key: "parseWithPlugins",
            value: function parseWithPlugins(currentElement) {
                var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
                try {
                    for(var _iterator = this.plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                        var plugin = _step.value;
                        var _plugin_parseMarkdown;
                        var rule = (_plugin_parseMarkdown = plugin.parseMarkdown) === null || _plugin_parseMarkdown === void 0 ? void 0 : _plugin_parseMarkdown.find(function(r) {
                            return r.match(currentElement);
                        });
                        if (rule) {
                            var converted = rule.convert(currentElement);
                            if (Array.isArray(converted) && converted.length === 2) {
                                return {
                                    handled: true,
                                    el: converted[0]
                                };
                            }
                            return {
                                handled: true,
                                el: converted
                            };
                        }
                    }
                } catch (err) {
                    _didIteratorError = true;
                    _iteratorError = err;
                } finally{
                    try {
                        if (!_iteratorNormalCompletion && _iterator.return != null) {
                            _iterator.return();
                        }
                    } finally{
                        if (_didIteratorError) {
                            throw _iteratorError;
                        }
                    }
                }
                return {
                    handled: false,
                    el: null
                };
            }
        },
        {
            /**
   * 解析 Markdown 字符串并返回解析后的结构和链接信息
   *
   * @param md - 要解析的 Markdown 字符串
   * @returns 一个包含解析后的元素数组和链接信息的对象
   */ key: "parse",
            value: function parse(md) {
                var markdownRoot = this.buildMarkdownRoot(md);
                var schema = this.parseNodes(markdownRoot, true, undefined);
                var filteredSchema = this.filterTopLevelSchema(schema);
                return {
                    schema: filteredSchema,
                    links: []
                };
            }
        },
        {
            key: "parseNodes",
            value: /**
   * 解析 Markdown AST 节点为 Slate 节点（类方法版本）
   * - 当有插件时，优先使用插件处理
   * - 插件未处理时，使用默认处理逻辑
   */ function parseNodes(nodes) {
                var top = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false, parent = arguments.length > 2 ? arguments[2] : void 0;
                if (!(nodes === null || nodes === void 0 ? void 0 : nodes.length)) {
                    return [
                        this.createEmptyParagraph()
                    ];
                }
                var els = [];
                var context = this.createParseContext();
                var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
                try {
                    for(var _iterator = nodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                        var currentElement = _step.value;
                        // 根级仅含 ::: 的段落为 remark-directive 闭合标记，不渲染
                        if (top && currentElement.type === 'paragraph' && getMdastNodeText(currentElement).trim() === ':::') {
                            continue;
                        }
                        var htmlCommentProps = this.parseHtmlCommentProps(currentElement);
                        if (htmlCommentProps) {
                            // 将注释属性存储到 contextProps 中，供下一个元素使用
                            context.contextProps = _object_spread({}, context.contextProps, htmlCommentProps);
                            continue;
                        }
                        var config = this.resolveConfig(context.preElement, context.contextProps);
                        var pluginResult = this.parseWithPlugins(currentElement);
                        var el = pluginResult.el;
                        if (Object.keys(config).length > 0) {
                            this.config = _object_spread({}, this.config, config);
                        }
                        if (!pluginResult.handled) {
                            var result = this.handleSingleElement({
                                currentElement: currentElement,
                                config: config,
                                parent: parent,
                                htmlTag: context.htmlTag,
                                preElement: context.preElement
                            });
                            el = result.el;
                            if (result.contextProps) {
                                context.contextProps = _object_spread({}, context.contextProps, result.contextProps);
                            }
                            // 更新 htmlTag 数组，以便后续节点可以使用
                            if (result.htmlTag) {
                                context.htmlTag = result.htmlTag;
                            }
                        }
                        els = addEmptyLinesIfNeeded(els, context.preNode, currentElement, top);
                        if (el) {
                            var appliedElement = applyContextPropsAndConfig(el, context.contextProps, config);
                            // 使用 if-else 而不是条件表达式，避免类型错误
                            if (Array.isArray(appliedElement)) {
                                els = _to_consumable_array(els).concat(_to_consumable_array(appliedElement));
                            } else {
                                els = _to_consumable_array(els).concat([
                                    appliedElement
                                ]);
                            }
                        }
                        context.preNode = currentElement;
                        context.preElement = el;
                    }
                } catch (err) {
                    _didIteratorError = true;
                    _iteratorError = err;
                } finally{
                    try {
                        if (!_iteratorNormalCompletion && _iterator.return != null) {
                            _iterator.return();
                        }
                    } finally{
                        if (_didIteratorError) {
                            throw _iteratorError;
                        }
                    }
                }
                return els;
            }
        },
        {
            key: "getElementHandlers",
            value: /**
   * 处理单个元素（类方法版本）
   */ /**
   * 获取统一的元素处理器映射表
   */ function getElementHandlers() {
                var _this = this;
                var parseNodesFn = function parseNodesFn(nodes, top, parent) {
                    return _this.parseNodes(nodes, top, parent);
                };
                var parseNodesForTable = function parseNodesForTable(nodes, _plugins, top, parent) {
                    return _this.parseNodes(nodes, top || false, parent);
                };
                return {
                    html: {
                        handler: function handler() {
                            return null;
                        },
                        needsHtmlResult: true
                    },
                    image: {
                        handler: function handler(el) {
                            return handleImage(el);
                        }
                    },
                    inlineMath: {
                        handler: function handler(el) {
                            return handleInlineMath(el);
                        }
                    },
                    math: {
                        handler: function handler(el) {
                            return handleMath(el);
                        }
                    },
                    footnoteReference: {
                        handler: function handler(el) {
                            return handleFootnoteReference(el);
                        }
                    },
                    inlineCode: {
                        handler: function handler(el) {
                            return handleInlineCode(el);
                        }
                    },
                    thematicBreak: {
                        handler: function handler() {
                            return handleThematicBreak();
                        }
                    },
                    code: {
                        handler: function handler(el, context) {
                            return handleCode(el, context.config);
                        }
                    },
                    yaml: {
                        handler: function handler(el) {
                            return handleYaml(el);
                        }
                    },
                    definition: {
                        handler: function handler(el) {
                            return handleDefinition(el);
                        }
                    },
                    heading: {
                        handler: function handler(el) {
                            return handleHeading(el, parseNodesFn);
                        }
                    },
                    list: {
                        handler: function handler(el) {
                            return handleList(el, parseNodesFn);
                        }
                    },
                    listItem: {
                        handler: function handler(el) {
                            return handleListItem(el, parseNodesFn);
                        }
                    },
                    blockquote: {
                        handler: function handler(el) {
                            return handleBlockquote(el, parseNodesFn);
                        }
                    },
                    containerDirective: {
                        handler: function handler(el) {
                            return handleContainerDirective(el, parseNodesFn);
                        }
                    },
                    footnoteDefinition: {
                        handler: function handler(el) {
                            return handleFootnoteDefinition(el, parseNodesFn);
                        }
                    },
                    paragraph: {
                        handler: function handler(el, context) {
                            return handleParagraph(el, context.config, parseNodesFn);
                        }
                    },
                    table: {
                        // 传入 config：当上一条是图表注释且被 continue 掉时，config 来自 contextProps，
                        // 作为 contextChartConfig 供 parseTableOrChart 在 preNode 无 html 配置时使用
                        handler: function handler(el, context) {
                            return parseTableOrChart(el, context.preElement || context.parent, _this.plugins, parseNodesForTable, _this.config, context.config);
                        }
                    }
                };
            }
        },
        {
            key: "handleSingleElement",
            value: function handleSingleElement(params) {
                var _this = this;
                var currentElement = params.currentElement, config = params.config, parent = params.parent, htmlTag = params.htmlTag, preElement = params.preElement;
                var elementType = currentElement.type;
                var elementHandlers = this.getElementHandlers();
                var handlerInfo = elementHandlers[elementType];
                if (handlerInfo === null || handlerInfo === void 0 ? void 0 : handlerInfo.needsHtmlResult) {
                    var htmlResult = handleHtml(currentElement, parent, htmlTag, function(md) {
                        return {
                            schema: _this.parse(md).schema
                        };
                    });
                    var result = {
                        el: htmlResult.el
                    };
                    if (htmlResult.contextProps) {
                        result.contextProps = htmlResult.contextProps;
                    }
                    if (htmlResult.htmlTag) {
                        result.htmlTag = htmlResult.htmlTag;
                    }
                    return result;
                }
                if (!handlerInfo) {
                    return {
                        el: handleTextAndInlineElements(currentElement, htmlTag, function(nodes, top, parent) {
                            return _this.parseNodes(nodes, top, parent);
                        }, this.config)
                    };
                }
                var handlerResult = handlerInfo.handler(currentElement, {
                    config: config,
                    parent: parent,
                    htmlTag: htmlTag,
                    preElement: preElement
                });
                return {
                    el: handlerResult
                };
            }
        }
    ]);
    return MarkdownToSlateParser;
}();
/**
 * 解析Markdown字符串并返回解析后的结构和链接信息。
 *
 * @param md - 要解析的Markdown字符串。
 * @param plugins - 可选的Markdown编辑器插件数组，用于扩展解析功能。
 * @param config - 可选的解析配置选项。
 * @returns 一个包含解析后的元素数组和链接信息的对象。
 *
 * @property schema - 解析后的元素数组。
 * @property links - 包含路径和目标链接的对象数组。
 *
 * @example
 * ```typescript
 * // 使用函数形式（向后兼容）
 * const result = parserMarkdownToSlateNode(markdown, plugins, { openLinksInNewTab: true });
 *
 * // 使用类形式（推荐，避免配置传递问题）
 * const parser = new MarkdownToSlateParser(
 *   { openLinksInNewTab: true },
 *   plugins
 * );
 * const result = parser.parse(markdown);
 * ```
 */ export var parserMarkdownToSlateNode = function parserMarkdownToSlateNode(md, plugins, config) {
    var _loop = function(i) {
        var _allSchemas;
        var _blocks_i = blocks[i], content = _blocks_i.content, hash = _blocks_i.hash;
        // 检查缓存
        if (parseCache.has(hash)) {
            var _allSchemas1;
            var cachedSchema = parseCache.get(hash);
            (_allSchemas1 = allSchemas).push.apply(_allSchemas1, _to_consumable_array(cachedSchema));
            return "continue";
        }
        // 缓存未命中，解析块
        var result = parser.parse(content);
        // 为 schema 元素添加 hash
        var schemaWithHash = result.schema.map(function(s, index) {
            return _object_spread_props(_object_spread({}, s), {
                hash: "".concat(hash, "-").concat(index)
            });
        });
        // 存入缓存（带 hash）
        parseCache.set(hash, schemaWithHash);
        // 限制缓存大小（最多 100 个条目）
        if (parseCache.size > 100) {
            var firstKey = parseCache.keys().next().value;
            if (firstKey) {
                parseCache.delete(firstKey);
            }
        }
        (_allSchemas = allSchemas).push.apply(_allSchemas, _to_consumable_array(schemaWithHash));
    };
    // 将 markdown 按块分割，同时生成哈希
    var blocks = splitMarkdownIntoBlocks(md || '', config, plugins);
    // 复用同一个 parser 实例
    var parser = new MarkdownToSlateParser(config || {}, plugins || []);
    // 如果只有一个块，直接解析
    if (blocks.length <= 1) {
        var _blocks_;
        var result = parser.parse(md);
        var blockHash = ((_blocks_ = blocks[0]) === null || _blocks_ === void 0 ? void 0 : _blocks_.hash) || simpleHash(md || '');
        // 为 schema 元素添加 hash
        return {
            schema: result.schema.map(function(s, index) {
                return _object_spread_props(_object_spread({}, s), {
                    hash: blockHash + '-' + index
                });
            }),
            links: result.links
        };
    }
    // 对每个块进行缓存查找或解析
    var allSchemas = [];
    for(var i = 0; i < blocks.length; i++)_loop(i);
    return {
        schema: allSchemas,
        links: []
    };
};
