@@ -42,10 +42,15 @@ export const extractPattern = (text, pattern, key, current) => {
4242 * @param {import('@types/mdast').List } list
4343 */
4444export const isTypedList = list => {
45+ if ( list . type !== 'list' ) {
46+ // Exit early if not a list
47+ return false ;
48+ }
49+
4550 const children = list ?. children ?. [ 0 ] ?. children ?. [ 0 ] ?. children ;
4651
47- // The first element must be a code block
4852 return (
53+ // The first element must be a code block
4954 children ?. [ 0 ] ?. type === 'inlineCode' &&
5055 // Followed by a space
5156 children ?. [ 1 ] ?. value . trim ( ) === '' &&
@@ -65,9 +70,11 @@ export const isTypedList = list => {
6570export function parseListItem ( child ) {
6671 const current = { } ;
6772
73+ const subList = child . children . find ( isTypedList ) ;
74+
6875 // Extract and clean raw text from the node, excluding nested lists
6976 current . textRaw = transformTypeReferences (
70- transformNodesToString ( child . children . filter ( node => node . type !== 'list' ) )
77+ transformNodesToString ( child . children . filter ( node => node !== subList ) )
7178 . replace ( / \s + / g, ' ' )
7279 . replace ( / < ! - - .* ?- - > / gs, '' )
7380 ) ;
@@ -89,9 +96,8 @@ export function parseListItem(child) {
8996 current . desc = text . replace ( LEADING_HYPHEN , '' ) . trim ( ) || undefined ;
9097
9198 // Parse nested lists (options) recursively if present
92- const optionsNode = child . children . find ( node => node . type === 'list' ) ;
93- if ( isTypedList ( optionsNode ) ) {
94- current . options = optionsNode . children . map ( parseListItem ) ;
99+ if ( subList ) {
100+ current . options = subList . children . map ( parseListItem ) ;
95101 }
96102
97103 return current ;
0 commit comments