Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ reproduce literal output.
A conforming [document][term-document] MUST contain elements in the following
order. Items marked OPTIONAL MAY be omitted entirely.

1. **Title heading** (REQUIRED) - Exactly one [ATX heading][cm-atx-heading]
at depth 1.
1. **Title heading** (OPTIONAL) - An [ATX heading][cm-atx-heading] at depth 1.
2. **[Simple directives][§6.2]** (OPTIONAL) - Zero or more
[HTML comment][cm-html-comment] directives providing
[document][term-document]-level metadata. These MUST immediately follow
Expand Down
5 changes: 5 additions & 0 deletions src/generators/jsx-ast/utils/buildContent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ export const extractHeadingContent = content => {
* @param {import('unist').Node|null} changeElement - The change history element, if available
*/
export const createHeadingElement = (content, changeElement) => {
// If the heading is empty, we don't render it
if (!content.children || content.children.length === 0) {
return { type: 'text', value: '' };
}

const { type, slug } = content.data;

let headingContent = extractHeadingContent(content);
Expand Down
2 changes: 1 addition & 1 deletion src/generators/metadata/utils/parse.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const parseApiDoc = ({ path, tree, mdx = false }, typeMap) => {
// Handles the normalisation URLs that reference to API doc files with .md extension
visit(tree, UNIST.isMarkdownUrl, node => visitMarkdownLink(node));

// If the document has no headings but it has content, we add a fake heading to the top
// If the document has no headings but it has content, we add a fake heading to the top, it will not be rendered
if (headingNodes.length === 0 && tree.children.length > 0) {
tree.children.unshift(createTree('heading', { depth: 1 }, []));
}
Comment on lines +90 to 93

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just remove this statement... Why are we adding a fake heading in the first place?

Then, createHeadings won't need a fast path

Expand Down
Loading