tools: build API TOC using raw headers

Markdown interprets the syntax for optional arguments as a form
of a link, so instead of trying to build up the contents using
the node value, use grab the raw original markup instead.

Fixes regression noted in
https://github.com/nodejs/node/pull/21490#issuecomment-406785023

PR-URL: https://github.com/nodejs/node/pull/21922
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Sam Ruby 2018-07-21 08:20:11 -04:00 committed by Vse Mozhet Byt
parent 2d48f97ddd
commit 46de34b8c2

View File

@ -340,8 +340,10 @@ function buildToc({ filename }) {
depth = node.depth;
const realFilename = path.basename(realFilenames[0], '.md');
const headingText = node.children.map((child) => child.value)
.join().trim();
const headingText = node.children.map((child) =>
file.contents.slice(child.position.start.offset,
child.position.end.offset)
).join('').trim();
const id = getId(`${realFilename}_${headingText}`, idCounters);
const hasStability = node.stability !== undefined;