import { Token, TokenGroup } from "../../../types/Token"; import { HtmlListElement } from "../../../types/html/HtmlListElement"; import { HtmlElementType } from "../../../types/html/HtmlElementType"; import { HtmlElement } from "../../../types/html/HtmlElement"; import { toCamelCase } from "../../string"; export function parseList( classes: string[], body: Token[], children: HtmlElement[] ): HtmlListElement | null { const refIndex = body.findIndex( x => x.group === TokenGroup.Generic && x.section === 'reference' ); const url = body.find( x => x.group === TokenGroup.Custom && x.section === 'string' ); let sourceUrl = url ? url.key : undefined; let sourceFunction = undefined; if( !sourceUrl && refIndex !== -1 ) { let nameSymbols = []; for( let i = refIndex + 1; i < body.length; i++ ) { if( body[i].group !== TokenGroup.Custom || body[i].section ) break; nameSymbols.push( body[i].key ); } if( nameSymbols.length > 0 ) { sourceFunction = toCamelCase( nameSymbols ); } } if( !sourceUrl && !sourceFunction ) return null; return { type: 'html', tag: HtmlElementType.List, classes, children, sourceUrl, sourceFunction } }