-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.mjs
40 lines (36 loc) · 1.14 KB
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* External dependencies
*/
import json2md from 'json2md';
/**
* Internal dependencies
*/
import { generateMarkdownPropsJson } from './props.mjs';
export function generateMarkdownDocs( { typeDocs, subcomponentTypeDocs } ) {
const mainDocsJson = [
'<!-- This file is generated automatically and cannot be edited directly. -->\n',
{ h1: typeDocs.displayName },
{
p: `<p class="callout callout-info">See the <a href="https://wordpress.github.io/gutenberg/?path=/docs/components-${ typeDocs.displayName.toLowerCase() }--docs">WordPress Storybook</a> for more detailed, interactive documentation.</p>`,
},
typeDocs.description,
...generateMarkdownPropsJson( typeDocs.props ),
];
const subcomponentDocsJson = subcomponentTypeDocs?.length
? [
{ h2: 'Subcomponents' },
...subcomponentTypeDocs.flatMap( ( subcomponentTypeDoc ) => [
{
h3: subcomponentTypeDoc.displayName,
},
subcomponentTypeDoc.description,
...generateMarkdownPropsJson( subcomponentTypeDoc.props, {
headingLevel: 4,
} ),
] ),
]
: [];
return json2md(
[ ...mainDocsJson, ...subcomponentDocsJson ].filter( Boolean )
);
}