UNPKG

@lobehub/ui

Version:

Lobe UI is an open-source UI component library for building AIGC web apps

32 lines (29 loc) 1.16 kB
import { SKIP, visit } from 'unist-util-visit'; // eslint-disable-next-line unicorn/consistent-function-scoping export var remarkCustomFootnotes = function remarkCustomFootnotes() { return function (tree, file) { var footnoteLinks = new Map(); visit(tree, 'footnoteDefinition', function (node) { var linkData = null; // 查找第一个link类型的子节点 visit(node, 'link', function (linkNode) { if (linkData) return SKIP; // 只取第一个链接 // 提取链接文本 var textNode = linkNode.children.find(function (n) { return n.type === 'text'; }); linkData = { alt: (textNode === null || textNode === void 0 ? void 0 : textNode.value) || '', title: (textNode === null || textNode === void 0 ? void 0 : textNode.value) || '', url: linkNode.url // 或者根据需求处理 }; return SKIP; // 找到后停止遍历 }); if (linkData) { footnoteLinks.set(node.identifier, linkData); } }); // 将数据存入文件上下文 file.data.footnoteLinks = Object.fromEntries(footnoteLinks); }; };