diff options
author | Marek Łabuz <mareklabuz@Mareks-MacBook-Pro-2.local> | 2019-10-12 15:00:42 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-11-30 18:17:56 +0100 |
commit | 62c61b754d7ade2d806fe9017818eb252c54353c (patch) | |
tree | 601323a20172ffa6e4129bfc53a1a2a9d4a754d4 /test | |
parent | 79faa875026a275b3e5eca019b3c50e1cbe2e34e (diff) | |
download | android-node-v8-62c61b754d7ade2d806fe9017818eb252c54353c.tar.gz android-node-v8-62c61b754d7ade2d806fe9017818eb252c54353c.tar.bz2 android-node-v8-62c61b754d7ade2d806fe9017818eb252c54353c.zip |
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>
Diffstat (limited to 'test')
-rw-r--r-- | test/doctool/test-doctool-html.js | 30 | ||||
-rw-r--r-- | test/fixtures/document_with_links.md | 20 |
2 files changed, 50 insertions, 0 deletions
diff --git a/test/doctool/test-doctool-html.js b/test/doctool/test-doctool-html.js index 11b28dc8a2..ee8099f8cd 100644 --- a/test/doctool/test-doctool-html.js +++ b/test/doctool/test-doctool-html.js @@ -11,6 +11,7 @@ try { const assert = require('assert'); const { readFile } = require('fs'); const fixtures = require('../common/fixtures'); +const { replaceLinks } = require('../../tools/doc/markdown.js'); const html = require('../../tools/doc/html.js'); const path = require('path'); @@ -22,8 +23,22 @@ const remark2rehype = require('remark-rehype'); const raw = require('rehype-raw'); const htmlStringify = require('rehype-stringify'); +// Test links mapper is an object of the following structure: +// { +// [filename]: { +// [link definition identifier]: [url to the linked resource] +// } +// } +const testLinksMapper = { + 'foo': { + 'command line options': 'cli.html#cli-options', + 'web server': 'example.html' + } +}; + async function toHTML({ input, filename, nodeVersion }) { const content = unified() + .use(replaceLinks, { filename, linksMapper: testLinksMapper }) .use(markdown) .use(html.firstHeader) .use(html.preprocessText) @@ -96,6 +111,21 @@ const testData = [ file: fixtures.path('altdocs.md'), html: '<li><a href="https://nodejs.org/docs/latest-v8.x/api/foo.html">8.x', }, + { + file: fixtures.path('document_with_links.md'), + html: '<h1>Usage and Example<span><a class="mark"' + + 'href="#foo_usage_and_example" id="foo_usage_and_example">#</a>' + + '</span></h1><h2>Usage<span><a class="mark" href="#foo_usage"' + + 'id="foo_usage">#</a></span></h2><p><code>node \\[options\\] index.js' + + '</code></p><p>Please see the<a href="cli.html#cli-options">' + + 'Command Line Options</a>document for more information.</p><h2>' + + 'Example<span><a class="mark" href="#foo_example" id="foo_example">' + + '#</a></span></h2><p>An example of a<a href="example.html">' + + 'webserver</a>written with Node.js which responds with<code>' + + '\'Hello, World!\'</code>:</p><h2>See also<span><a class="mark"' + + 'href="#foo_see_also" id="foo_see_also">#</a></span></h2><p>Check' + + 'out also<a href="https://nodejs.org/">this guide</a></p>' + }, ]; const spaces = /\s/g; diff --git a/test/fixtures/document_with_links.md b/test/fixtures/document_with_links.md new file mode 100644 index 0000000000..1392029a30 --- /dev/null +++ b/test/fixtures/document_with_links.md @@ -0,0 +1,20 @@ +# Usage and Example + +## Usage + +`node \[options\] index.js` + +Please see the [Command Line Options][] document for more information. + +## Example + +An example of a [web server][] written with Node.js which responds with +`'Hello, World!'`: + +## See also + +Check out also [this guide][] + +[Command Line Options]: cli.md#options +[this guide]: https://nodejs.org/ +[web server]: example.md |