Skip to content

Commit 08c1365

Browse files
committed
list item stuff
Signed-off-by: flakey5 <[email protected]>
1 parent 6a0d6fb commit 08c1365

File tree

4 files changed

+238
-55
lines changed

4 files changed

+238
-55
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Denotes a method's return value
3+
*/
4+
export const RETURN_EXPRESSION = /^returns?\s*:?\s*/i;
5+
6+
/**
7+
* Denotes a method's name
8+
*/
9+
export const NAME_EXPRESSION = /^['`"]?([^'`": {]+)['`"]?\s*:?\s*/;
10+
11+
/**
12+
* Denotes a method's type
13+
*/
14+
export const TYPE_EXPRESSION = /^\{([^}]+)\}\s*/;
15+
16+
/**
17+
* Is there a leading hyphen
18+
*/
19+
export const LEADING_HYPHEN = /^-\s*/;
20+
21+
/**
22+
* Denotes a default value
23+
*/
24+
export const DEFAULT_EXPRESSION = /\s*\*\*Default:\*\*\s*([^]+)$/i;

src/generators/legacy-json/types.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ListItem } from 'mdast';
2+
13
export interface HierarchizedEntry extends ApiDocMetadataEntry {
24
hierarchyChildren: ApiDocMetadataEntry[];
35
}
@@ -61,3 +63,12 @@ export interface MiscSection extends SectionBase {
6163
type: 'misc';
6264
[key: string]: string | undefined;
6365
}
66+
67+
export interface List {
68+
textRaw: string;
69+
desc?: string;
70+
name: string;
71+
type?: string;
72+
default?: string;
73+
options?: List;
74+
}

src/generators/legacy-json/utils/buildHierarchy.mjs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
/**
22
* So we need the files to be in a hierarchy based off of depth, but they're
3-
* given to us flattened. So, let's fix that in a way that's incredibly
4-
* unfortunate but works!
5-
* @param {ApiDocMetadataEntry[]} entries
6-
* @returns {import('../types.d.ts').HierarchizedEntry[]}
3+
* given to us flattened. So, let's fix that.
4+
*
5+
* Assuming that {@link entries} is in the same order as the elements are in
6+
* the markdown, we can use the entry's depth property to reassemble the
7+
* hierarchy.
8+
*
9+
* If depth <= 1, it's a top-level element (aka a root).
10+
*
11+
* If it's depth is greater than the previous entry's depth, it's a child of
12+
* the previous entry. Otherwise (if it's less than or equal to the previous
13+
* entry's depth), we need to find the entry that it was the greater than. We
14+
* can do this by just looping through entries in reverse starting at the
15+
* current index - 1.
16+
*
17+
* @param {Array<ApiDocMetadataEntry>} entries
18+
* @returns {Array<import('../types.d.ts').HierarchizedEntry>}
719
*/
820
export function buildHierarchy(entries) {
921
const roots = [];
@@ -12,7 +24,8 @@ export function buildHierarchy(entries) {
1224
const entry = entries[i];
1325
const currentDepth = entry.heading.depth;
1426

15-
if (currentDepth === 1) {
27+
// We're a top-level entry
28+
if (currentDepth <= 1) {
1629
roots.push(entry);
1730
continue;
1831
}
@@ -27,10 +40,12 @@ export function buildHierarchy(entries) {
2740
}
2841
previousEntry.hierarchyChildren.push(entry);
2942
} else {
43+
// Loop to find the entry we're a child of
3044
for (let j = i - 2; j >= 0; j--) {
3145
const jEntry = entries[j];
3246
const jDepth = jEntry.heading.depth;
3347
if (currentDepth > jDepth) {
48+
// Found it
3449
jEntry.hierarchyChildren.push(entry);
3550
break;
3651
}

0 commit comments

Comments
 (0)