33import { u as createTree } from 'unist-builder' ;
44import { SKIP } from 'unist-util-visit' ;
55
6- import {
7- DOC_API_STABILITY_SECTION_REF_URL ,
8- VALID_JAVASCRIPT_PROPERTY ,
9- } from './constants.mjs' ;
6+ import { DOC_API_STABILITY_SECTION_REF_URL } from './constants.mjs' ;
107import {
118 extractYamlContent ,
129 parseHeadingIntoMetadata ,
@@ -16,6 +13,7 @@ import {
1613} from '../parser/index.mjs' ;
1714import { getRemark } from '../remark.mjs' ;
1815import { transformNodesToString } from '../unist.mjs' ;
16+ import { isTypedList } from './utils.mjs' ;
1917
2018/**
2119 * Creates an instance of the Query Manager, which allows to do multiple sort
@@ -272,46 +270,28 @@ createQueries.UNIST = {
272270 * @param {import('@types/mdast').List } list
273271 * @returns {boolean }
274272 */
275- isTypedList : list => {
276- // Exit early if not a list node
277- if ( list . type !== 'list' ) {
278- return false ;
279- }
280-
281- // Get the content nodes of the first list item's paragraph
282- const [ node , ...contentNodes ] =
283- list ?. children ?. [ 0 ] ?. children ?. [ 0 ] ?. children ?? [ ] ;
284-
285- // Exit if no node
286- if ( ! node ) {
287- return false ;
288- }
289-
290- const possibleProperty = node ?. value ?. trimStart ( ) ;
291-
292- // Check for other starters
293- if ( possibleProperty ?. match ( createQueries . QUERIES . typedListStarters ) ) {
294- return true ;
295- }
273+ isLooselyTypedList : list => Boolean ( isTypedList ( list ) ) ,
296274
297- // Check for direct type link pattern (starts with '<')
298- if ( node . type === 'link' && node . children ?. [ 0 ] ?. value ?. [ 0 ] === '<' ) {
299- return true ;
300- }
301-
302- // Check for inline code + space + type link pattern
303- if (
304- node . type === 'inlineCode' &&
305- possibleProperty ?. match ( VALID_JAVASCRIPT_PROPERTY ) &&
306- contentNodes [ 0 ] ?. value ?. trim ( ) === '' &&
307- contentNodes [ 1 ] ?. type === 'link' &&
308- contentNodes [ 1 ] ?. children ?. [ 0 ] ?. value ?. [ 0 ] === '<'
309- ) {
310- return true ;
275+ /**
276+ * @param {import('@types/mdast').List } list
277+ * @returns {boolean }
278+ */
279+ isStronglyTypedList : list => {
280+ const confidence = isTypedList ( list ) ;
281+
282+ if ( confidence === 1 ) {
283+ // This is a loosely typed list, but we can still check if it is strongly typed.
284+ const [ , secondNode , thirdNode ] =
285+ list . children ?. [ 0 ] ?. children ?. [ 0 ] ?. children ?? [ ] ;
286+
287+ return (
288+ secondNode ?. value ?. trim ( ) === '' &&
289+ thirdNode ?. type === 'link' &&
290+ thirdNode ?. children ?. [ 0 ] ?. value ?. [ 0 ] === '<'
291+ ) ;
311292 }
312293
313- // Not a typed list
314- return false ;
294+ return Boolean ( confidence ) ;
315295 } ,
316296} ;
317297
0 commit comments