Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion doc/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<!--introduced_in=v0.10.0-->

* [About this documentation](documentation.md)
* [Usage and example](synopsis.md)

<hr class="line"/>

Expand Down
94 changes: 0 additions & 94 deletions doc/api/synopsis.md

This file was deleted.

17 changes: 2 additions & 15 deletions test/doctool/test-doctool-html.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,9 @@ import {
unified,
} from '../../tools/doc/deps.mjs';

// 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',
},
};

function toHTML({ input, filename, nodeVersion, versions }) {
const content = unified()
.use(replaceLinks, { filename, linksMapper: testLinksMapper })
.use(replaceLinks)
.use(remarkParse)
.use(html.firstHeader)
.use(html.preprocessText, { nodeVersion })
Expand Down Expand Up @@ -119,7 +106,7 @@ const testData = [
'</a></h2><section><h3>Usage<span><a class="mark" href="#usage"' +
'id="usage">#</a></span><a aria-hidden="true" class="legacy"' +
'id="foo_usage"></a></h3><p><code>node \\[options\\] index.js' +
'</code></p><p>Please see the<a href="cli.html#cli-options">' +
'</code></p><p>Please see the<a href="cli.html#options">' +
'Command Line Options</a>document for more information.</p>' +
'</section><section><h3>' +
'Example<span><a class="mark" href="#example" id="example">' +
Expand Down
7 changes: 2 additions & 5 deletions tools/doc/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

import { readFileSync, promises as fs } from 'fs';
import { promises as fs } from 'fs';
import path from 'path';

import raw from 'rehype-raw';
Expand All @@ -34,9 +34,6 @@ import * as html from './html.mjs';
import * as json from './json.mjs';
import { replaceLinks } from './markdown.mjs';

const linksMapperFile = new URL('links-mapper.json', import.meta.url);
const linksMapper = JSON.parse(readFileSync(linksMapperFile, 'utf8'));

// Parse the args.
// Don't use nopt or whatever for this. It's simple enough.

Expand Down Expand Up @@ -84,7 +81,7 @@ async function main() {

const content = await unified()
.use(frontmatter)
.use(replaceLinks, { filename, linksMapper })
.use(replaceLinks)
.use(markdown)
.use(gfm)
.use(html.preprocessText, { nodeVersion })
Expand Down
6 changes: 0 additions & 6 deletions tools/doc/links-mapper.json

This file was deleted.

13 changes: 2 additions & 11 deletions tools/doc/markdown.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,13 @@ import { visit } from 'unist-util-visit';

export const referenceToLocalMdFile = /^(?![+a-z]+:)([^#?]+)\.md(#.+)?$/i;

export function replaceLinks({ filename, linksMapper }) {
export function replaceLinks() {
return (tree) => {
const fileHtmlUrls = linksMapper[filename];

visit(tree, (node) => {
node.url &&= node.url.replace(
referenceToLocalMdFile,
(_, filename, hash) => `${filename}.html${hash || ''}`,
);
});
visit(tree, 'definition', (node) => {
const htmlUrl = fileHtmlUrls?.[node.identifier];

if (htmlUrl && typeof htmlUrl === 'string') {
node.url = htmlUrl;
}
});
};
}
};
Loading