UNPKG

@lobehub/ui

Version:

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

1 lines 2.1 kB
{"version":3,"file":"rehypeCustomFootnotes.mjs","names":["linksData: Record<string, FootnoteLink>"],"sources":["../../../src/Markdown/plugins/rehypeCustomFootnotes.ts"],"sourcesContent":["import { visit } from 'unist-util-visit';\n\nimport type { FootnoteLink } from './remarkCustomFootnotes';\n\n// eslint-disable-next-line unicorn/consistent-function-scoping\nexport const rehypeCustomFootnotes = () => (tree: any, file: any) => {\n const linksData: Record<string, FootnoteLink> = file.data.footnoteLinks || {};\n\n visit(tree, 'element', (node) => {\n if (node.tagName === 'section' && node.properties.className?.includes('footnotes')) {\n // 转换数据格式为数组(按identifier排序)\n const sortedLinks = Object.entries(linksData)\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([id, data]) => ({ id, ...data }));\n // 注入数据属性\n node.properties['data-footnote-links'] = JSON.stringify(sortedLinks);\n }\n\n if (node.tagName === 'sup') {\n const link = node.children.find((n: any) => n.tagName === 'a');\n\n if (link) {\n // a node example\n // {\n // \"href\": \"#user-content-fn-3\",\n // \"id\": \"user-content-fnref-3-2\",\n // \"dataFootnoteRef\": true,\n // }\n const linkRefIndex = link.properties?.id?.replace(/^user-content-fnref-/, '')[0];\n\n if (linkRefIndex !== undefined)\n link.properties['data-link'] = JSON.stringify(linksData[linkRefIndex]);\n }\n }\n });\n};\n"],"mappings":";;;AAKA,MAAa,+BAA+B,MAAW,SAAc;CACnE,MAAMA,YAA0C,KAAK,KAAK,iBAAiB,EAAE;AAE7E,OAAM,MAAM,YAAY,SAAS;AAC/B,MAAI,KAAK,YAAY,aAAa,KAAK,WAAW,WAAW,SAAS,YAAY,EAAE;GAElF,MAAM,cAAc,OAAO,QAAQ,UAAU,CAC1C,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,CAAC,CACtC,KAAK,CAAC,IAAI,WAAW;IAAE;IAAI,GAAG;IAAM,EAAE;AAEzC,QAAK,WAAW,yBAAyB,KAAK,UAAU,YAAY;;AAGtE,MAAI,KAAK,YAAY,OAAO;GAC1B,MAAM,OAAO,KAAK,SAAS,MAAM,MAAW,EAAE,YAAY,IAAI;AAE9D,OAAI,MAAM;IAOR,MAAM,eAAe,KAAK,YAAY,IAAI,QAAQ,wBAAwB,GAAG,CAAC;AAE9E,QAAI,iBAAiB,OACnB,MAAK,WAAW,eAAe,KAAK,UAAU,UAAU,cAAc;;;GAG5E"}