0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/tools/doc/markdown.js
Marek Łabuz 62c61b754d
tools: add unified plugin changing links for html docs
This commit introduces additional stage in the process of generating
html docs from markdown files. Plugin transforms links to *.md files
in the respository to links to *.html files in the online documentation.

Fixes: https://github.com/nodejs/node/issues/28689

PR-URL: https://github.com/nodejs/node/pull/29946
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2019-11-30 18:17:56 +01:00

22 lines
433 B
JavaScript

'use strict';
const visit = require('unist-util-visit');
module.exports = {
replaceLinks
};
function replaceLinks({ filename, linksMapper }) {
return (tree) => {
const fileHtmlUrls = linksMapper[filename];
visit(tree, 'definition', (node) => {
const htmlUrl = fileHtmlUrls && fileHtmlUrls[node.identifier];
if (htmlUrl && typeof htmlUrl === 'string') {
node.url = htmlUrl;
}
});
};
}