forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmarkdown.js
More file actions
32 lines (26 loc) · 742 Bytes
/
Copy pathmarkdown.js
File metadata and controls
32 lines (26 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'use strict';
const visit = require('unist-util-visit');
const referenceToLocalMdFile = /^(?![+a-z]+:)([^#?]+)\.md(#.+)?$/i;
module.exports = {
replaceLinks,
referenceToLocalMdFile,
};
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;
}
});
};
}