/
githubmirror
/
node
Обзор
Документация
Войти
/
githubmirror
/
node
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v20.20.2
tools/doc/markdown.mjs
25 строк
676 B
Antoine du Hamel
tools: enforce use of trailing commas in `tools/`
18 дек 2022, 19:39
Не верифицирован
18 дек 2022, 19:39
3ce4cef
Код
Авторство
О чём код?
import { visit } from 'unist-util-visit'; export const referenceToLocalMdFile = /^(?![+a-z]+:)([^#?]+)\.md(#.+)?$/i; export function replaceLinks({ filename, linksMapper }) { return (tree) => { const fileHtmlUrls = linksMapper[filename]; visit(tree, (node) => { if (node.url) { node.url = node.url.replace( referenceToLocalMdFile, (_, filename, hash) => `${filename}.html${hash || ''}`, ); } }); visit(tree, 'definition', (node) => { const htmlUrl = fileHtmlUrls && fileHtmlUrls[node.identifier]; if (htmlUrl && typeof htmlUrl === 'string') { node.url = htmlUrl; } }); }; }