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
5 changes: 2 additions & 3 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, RECOMMENDED) - 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 Expand Up @@ -278,7 +277,7 @@ NOT be used.

#### 4.2.1. Depth 1

The [document][term-document] title. Exactly one depth-1 heading MUST appear
The [document][term-document] title. Exactly one depth-1 heading SHOULD appear
per document.

#### 4.2.2. Depth 2
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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, I was thinking of that and searching for what the effect will be. Let me revise what I found.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  1. While traversing AST, in this file, parseApiDoc extracts content by visiting heading nodes visit(tree, UNIST.isHeading, (headingNode, index) => {...}}. It uses each heading as an anchor and slices the AST content between it and the next heading. If a document has no headings, the visit never fires, and parseApiDoc returns an empty array, which drops all the page content.

  2. in type.d.ts, The MetadataEntry interface strictly requires heading: HeadingNode (it is not optional).

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.

I see, so headings are required, I guess. In that case, we should make the default heading something like {project} Documentation, and then in webpack use CSS/postprocessing to remove it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just think of accessibility, SEO and other projects that will use doc-kit, instead of pushing elements to the DOM that serve zero visual purpose, we can handle it here.

In the end, that's your decision, guys 😅

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.

Your right

Expand Down
Loading