mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
de01f475d5
- Migrated to ESM because some dependencies now require it. - Did not update `highlight.js` to v11 because it has many breaking changes. - Used non-deprecated `highlight.js` API. Refs: https://github.com/highlightjs/highlight.js/issues/2277 Fixes: https://github.com/nodejs/node/issues/38938 Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: https://github.com/nodejs/node/pull/38966 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
26 lines
675 B
JavaScript
26 lines
675 B
JavaScript
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;
|
|
}
|
|
});
|
|
};
|
|
}
|