Skip to content

Commit

Permalink
tools: add direct anchors for error codes
Browse files Browse the repository at this point in the history
This adds direct anchors for the error codes in errors.html.
For example, previously the anchor for ERR_ASSERTION
is #errors_err_assertion, now there is also #ERR_ASSERTION.

PR-URL: #16779
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung authored and evanlucas committed Nov 13, 2017
1 parent 5d3a4ad commit 25dd8f6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tools/doc/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ function getSection(lexed) {
return '';
}

function getMark(anchor) {
return `<span><a class="mark" href="#${anchor}" id="${anchor}">#</a></span>`;
}

function buildToc(lexed, filename, cb) {
var toc = [];
Expand Down Expand Up @@ -499,12 +502,15 @@ function buildToc(lexed, filename, cb) {

depth = tok.depth;
const realFilename = path.basename(realFilenames[0], '.md');
const id = getId(`${realFilename}_${tok.text.trim()}`);
const apiName = tok.text.trim();
const id = getId(`${realFilename}_${apiName}`);
toc.push(new Array((depth - 1) * 2 + 1).join(' ') +
`* <span class="stability_${tok.stability}">` +
`<a href="#${id}">${tok.text}</a></span>`);
tok.text += `<span><a class="mark" href="#${id}"` +
`id="${id}">#</a></span>`;
tok.text += getMark(id);
if (realFilename === 'errors' && apiName.startsWith('ERR_')) {
tok.text += getMark(apiName);
}
});

toc = marked.parse(toc.join('\n'));
Expand Down

0 comments on commit 25dd8f6

Please sign in to comment.