From 60465700ed055640e737ca3a53e16465dfec00d6 Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Sun, 19 Aug 2018 14:03:21 -0400 Subject: tools: Include links to source code in documentation Parse source code using acorn; extracting exports. When producing documentation, match exports to headers. When a match is found, add a [src] link. This first commit handles simple exported classes and functions, and does so without requiring any changes to the source code or markdown. Subsequent commits will attempt to match more headers, and some of these changes are likely to require changes to the source code and/or markdown. PR-URL: https://github.com/nodejs/node/pull/22405 Reviewed-By: James M Snell Reviewed-By: Refael Ackermann Reviewed-By: Vse Mozhet Byt --- tools/doc/generate.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tools/doc/generate.js') diff --git a/tools/doc/generate.js b/tools/doc/generate.js index f2e3e8a164..28e09d003f 100644 --- a/tools/doc/generate.js +++ b/tools/doc/generate.js @@ -40,6 +40,7 @@ let filename = null; let nodeVersion = null; let analytics = null; let outputDir = null; +let apilinks = {}; args.forEach(function(arg) { if (!arg.startsWith('--')) { @@ -50,6 +51,10 @@ args.forEach(function(arg) { analytics = arg.replace(/^--analytics=/, ''); } else if (arg.startsWith('--output-directory=')) { outputDir = arg.replace(/^--output-directory=/, ''); + } else if (arg.startsWith('--apilinks=')) { + apilinks = JSON.parse( + fs.readFileSync(arg.replace(/^--apilinks=/, ''), 'utf8') + ); } }); @@ -71,7 +76,7 @@ fs.readFile(filename, 'utf8', (er, input) => { .use(json.jsonAPI, { filename }) .use(html.firstHeader) .use(html.preprocessElements, { filename }) - .use(html.buildToc, { filename }) + .use(html.buildToc, { filename, apilinks }) .use(remark2rehype, { allowDangerousHTML: true }) .use(raw) .use(htmlStringify) -- cgit v1.2.3