Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: flatten apidoc headers #21936

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 21 additions & 6 deletions tools/doc/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ function linkJsTypeDocs(text) {
return parts.join('`');
}

// Preprocess stability blockquotes and YAML blocks
// Preprocess headers, stability blockquotes, and YAML blocks.
function preprocessElements({ filename }) {
return (tree) => {
return (tree, file) => {
const STABILITY_RE = /(.*:)\s*(\d)([\s\S]*)/;
let headingIndex = -1;
let heading = null;
Expand All @@ -196,6 +196,22 @@ function preprocessElements({ filename }) {
headingIndex = index;
heading = node;

// Ensure optional API parameters are not treated as links by
// collapsing all of heading into a single text node.
if (heading.children.length > 1) {
const position = {
start: heading.children[0].position.start,
end: heading.position.end
};

heading.children = [{
type: 'text',
value: file.contents.slice(
position.start.offset, position.end.offset),
position
}];
}

} else if (node.type === 'html' && common.isYAMLBlock(node.value)) {
node.value = parseYAML(node.value);

Expand Down Expand Up @@ -340,10 +356,9 @@ function buildToc({ filename }) {

depth = node.depth;
const realFilename = path.basename(realFilenames[0], '.md');
const headingText = node.children.map((child) =>
file.contents.slice(child.position.start.offset,
child.position.end.offset)
).join('').trim();
const headingText = file.contents.slice(
node.children[0].position.start.offset,
node.position.end.offset).trim();
const id = getId(`${realFilename}_${headingText}`, idCounters);

const hasStability = node.stability !== undefined;
Expand Down