Skip to content

Commit 25dd8f6

Browse files
joyeecheungevanlucas
authored andcommitted
tools: add direct anchors for error codes
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 <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 5d3a4ad commit 25dd8f6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tools/doc/html.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ function getSection(lexed) {
472472
return '';
473473
}
474474

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

476479
function buildToc(lexed, filename, cb) {
477480
var toc = [];
@@ -499,12 +502,15 @@ function buildToc(lexed, filename, cb) {
499502

500503
depth = tok.depth;
501504
const realFilename = path.basename(realFilenames[0], '.md');
502-
const id = getId(`${realFilename}_${tok.text.trim()}`);
505+
const apiName = tok.text.trim();
506+
const id = getId(`${realFilename}_${apiName}`);
503507
toc.push(new Array((depth - 1) * 2 + 1).join(' ') +
504508
`* <span class="stability_${tok.stability}">` +
505509
`<a href="#${id}">${tok.text}</a></span>`);
506-
tok.text += `<span><a class="mark" href="#${id}"` +
507-
`id="${id}">#</a></span>`;
510+
tok.text += getMark(id);
511+
if (realFilename === 'errors' && apiName.startsWith('ERR_')) {
512+
tok.text += getMark(apiName);
513+
}
508514
});
509515

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

0 commit comments

Comments
 (0)