GeezerVison is showing github.com — tools: add direct anchors for error codes · nodejs/node@25dd8f6
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: tools/doc/html.js +9-3Lines changed: 9 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -472,6 +472,9 @@ function getSection(lexed) { |
472 | 472 | return ''; |
473 | 473 | } |
474 | 474 |
|
| 475 | +function getMark(anchor) { |
| 476 | + return `<span><a class="mark" href="#${anchor}" id="${anchor}">#</a></span>`; |
| 477 | +} |
475 | 478 |
|
476 | 479 | function buildToc(lexed, filename, cb) { |
477 | 480 | var toc = []; |
@@ -499,12 +502,15 @@ function buildToc(lexed, filename, cb) { |
499 | 502 |
|
500 | 503 | depth = tok.depth; |
501 | 504 | 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}`); |
503 | 507 | toc.push(new Array((depth - 1) * 2 + 1).join(' ') + |
504 | 508 | `* <span class="stability_${tok.stability}">` + |
505 | 509 | `<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 | + } |
508 | 514 | }); |
509 | 515 |
|
510 | 516 | toc = marked.parse(toc.join('\n')); |
|