Skip to content

Commit 678a15c

Browse files
committed
fix(legacy-json): verify list type
1 parent e44f080 commit 678a15c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ export const extractPattern = (text, pattern, key, current) => {
3737
return text.replace(pattern, '');
3838
};
3939

40+
/**
41+
* Determines if the input List node is a typed list
42+
* @param {import('@types/mdast').List} list
43+
*/
44+
export const isTypedList = list => {
45+
const children = list?.children?.[0]?.children?.[0]?.children;
46+
47+
// The first element must be a code block
48+
return (
49+
children?.[0]?.type === 'inlineCode' &&
50+
// Followed by a space
51+
children?.[1]?.value.trim() === '' &&
52+
// Followed by a link (type)
53+
children?.[2]?.type === 'link' &&
54+
// Types start with `<`
55+
children?.[2]?.children?.[0]?.value?.[0] === '<'
56+
);
57+
};
58+
4059
/**
4160
* Parses an individual list item node to extract its properties
4261
*
@@ -71,7 +90,7 @@ export function parseListItem(child) {
7190

7291
// Parse nested lists (options) recursively if present
7392
const optionsNode = child.children.find(node => node.type === 'list');
74-
if (optionsNode) {
93+
if (isTypedList(optionsNode)) {
7594
current.options = optionsNode.children.map(parseListItem);
7695
}
7796

0 commit comments

Comments
 (0)