| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7bc8c85 commit da1e5ae
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -746,7 +746,7 @@ $(LINK_DATA): $(wildcard lib/*.js) tools/doc/apilinks.js | |||
| 746 | 746 | $(call available-node, $(gen-apilink)) | |
| 747 | 747 | ||
| 748 | 748 | out/doc/api/%.json out/doc/api/%.html: doc/api/%.md tools/doc/generate.js \ | |
| 749 | - tools/doc/html.js tools/doc/json.js tools/doc/apilinks.js | $(LINK_DATA) | ||
| 749 | + tools/doc/markdown.js tools/doc/html.js tools/doc/json.js tools/doc/apilinks.js | $(LINK_DATA) | ||
| 750 | 750 | $(call available-node, $(gen-api)) | |
| 751 | 751 | ||
| 752 | 752 | out/doc/api/all.html: $(apidocs_html) tools/doc/allhtml.js \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ try { | |||
| 11 | 11 | const assert = require('assert'); | |
| 12 | 12 | const { readFile } = require('fs'); | |
| 13 | 13 | const fixtures = require('../common/fixtures'); | |
| 14 | + const { replaceLinks } = require('../../tools/doc/markdown.js'); | ||
| 14 | 15 | const html = require('../../tools/doc/html.js'); | |
| 15 | 16 | const path = require('path'); | |
| 16 | 17 | ||
@@ -22,8 +23,22 @@ const remark2rehype = require('remark-rehype'); | |||
| 22 | 23 | const raw = require('rehype-raw'); | |
| 23 | 24 | const htmlStringify = require('rehype-stringify'); | |
| 24 | 25 | ||
| 26 | + // Test links mapper is an object of the following structure: | ||
| 27 | + // { | ||
| 28 | + // [filename]: { | ||
| 29 | + // [link definition identifier]: [url to the linked resource] | ||
| 30 | + // } | ||
| 31 | + // } | ||
| 32 | + const testLinksMapper = { | ||
| 33 | + 'foo': { | ||
| 34 | + 'command line options': 'cli.html#cli-options', | ||
| 35 | + 'web server': 'example.html' | ||
| 36 | + } | ||
| 37 | + }; | ||
| 38 | + | ||
| 25 | 39 | async function toHTML({ input, filename, nodeVersion }) { | |
| 26 | 40 | const content = unified() | |
| 41 | + .use(replaceLinks, { filename, linksMapper: testLinksMapper }) | ||
| 27 | 42 | .use(markdown) | |
| 28 | 43 | .use(html.firstHeader) | |
| 29 | 44 | .use(html.preprocessText) | |
@@ -96,6 +111,21 @@ const testData = [ | |||
| 96 | 111 | file: fixtures.path('altdocs.md'), | |
| 97 | 112 | html: '<li><a href="https://nodejs.org/docs/latest-v8.x/api/foo.html">8.x', | |
| 98 | 113 | }, | |
| 114 | + { | ||
| 115 | + file: fixtures.path('document_with_links.md'), | ||
| 116 | + html: '<h1>Usage and Example<span><a class="mark"' + | ||
| 117 | + 'href="#foo_usage_and_example" id="foo_usage_and_example">#</a>' + | ||
| 118 | + '</span></h1><h2>Usage<span><a class="mark" href="#foo_usage"' + | ||
| 119 | + 'id="foo_usage">#</a></span></h2><p><code>node \\[options\\] index.js' + | ||
| 120 | + '</code></p><p>Please see the<a href="cli.html#cli-options">' + | ||
| 121 | + 'Command Line Options</a>document for more information.</p><h2>' + | ||
| 122 | + 'Example<span><a class="mark" href="#foo_example" id="foo_example">' + | ||
| 123 | + '#</a></span></h2><p>An example of a<a href="example.html">' + | ||
| 124 | + 'webserver</a>written with Node.js which responds with<code>' + | ||
| 125 | + '\'Hello, World!\'</code>:</p><h2>See also<span><a class="mark"' + | ||
| 126 | + 'href="#foo_see_also" id="foo_see_also">#</a></span></h2><p>Check' + | ||
| 127 | + 'out also<a href="https://nodejs.org/">this guide</a></p>' | ||
| 128 | + }, | ||
| 99 | 129 | ]; | |
| 100 | 130 | ||
| 101 | 131 | const spaces = /\s/g; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,20 @@ | |||
| 1 | + # Usage and Example | ||
| 2 | + | ||
| 3 | + ## Usage | ||
| 4 | + | ||
| 5 | + `node \[options\] index.js` | ||
| 6 | + | ||
| 7 | + Please see the [Command Line Options][] document for more information. | ||
| 8 | + | ||
| 9 | + ## Example | ||
| 10 | + | ||
| 11 | + An example of a [web server][] written with Node.js which responds with | ||
| 12 | + `'Hello, World!'`: | ||
| 13 | + | ||
| 14 | + ## See also | ||
| 15 | + | ||
| 16 | + Check out also [this guide][] | ||
| 17 | + | ||
| 18 | + [Command Line Options]: cli.md#options | ||
| 19 | + [this guide]: https://nodejs.org/ | ||
| 20 | + [web server]: example.md | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,8 @@ const remark2rehype = require('remark-rehype'); | |||
| 29 | 29 | const raw = require('rehype-raw'); | |
| 30 | 30 | const htmlStringify = require('rehype-stringify'); | |
| 31 | 31 | ||
| 32 | + const { replaceLinks } = require('./markdown'); | ||
| 33 | + const linksMapper = require('./links-mapper'); | ||
| 32 | 34 | const html = require('./html'); | |
| 33 | 35 | const json = require('./json'); | |
| 34 | 36 | ||
@@ -70,6 +72,7 @@ async function main() { | |||
| 70 | 72 | const input = await fs.readFile(filename, 'utf8'); | |
| 71 | 73 | ||
| 72 | 74 | const content = await unified() | |
| 75 | + .use(replaceLinks, { filename, linksMapper }) | ||
| 73 | 76 | .use(markdown) | |
| 74 | 77 | .use(html.preprocessText) | |
| 75 | 78 | .use(json.jsonAPI, { filename }) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + { | ||
| 2 | + "doc/api/synopsis.md": { | ||
| 3 | + "command line options": "cli.html#cli_command_line_options", | ||
| 4 | + "web server": "http.html" | ||
| 5 | + } | ||
| 6 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,21 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const visit = require('unist-util-visit'); | ||
| 4 | + | ||
| 5 | + module.exports = { | ||
| 6 | + replaceLinks | ||
| 7 | + }; | ||
| 8 | + | ||
| 9 | + function replaceLinks({ filename, linksMapper }) { | ||
| 10 | + return (tree) => { | ||
| 11 | + const fileHtmlUrls = linksMapper[filename]; | ||
| 12 | + | ||
| 13 | + visit(tree, 'definition', (node) => { | ||
| 14 | + const htmlUrl = fileHtmlUrls && fileHtmlUrls[node.identifier]; | ||
| 15 | + | ||
| 16 | + if (htmlUrl && typeof htmlUrl === 'string') { | ||
| 17 | + node.url = htmlUrl; | ||
| 18 | + } | ||
| 19 | + }); | ||
| 20 | + }; | ||
| 21 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments