import { advance_probe, is_ascii_alnum, is_digit, is_hex_digit, is_space, matches_ci, scan_to_line_end, skip_space, token_type, type Lexer, type SyntaxLang, } from './lexer.ts'; /** * Hand-written HTML/XML lexer. * * Emits: flat `comment`, `processing_instruction`, `doctype`, `cdata`, and * `entity` (alias `named_entity` for the `&`-style form); a `tag` container * holding a nested `tag` (the `` (even one * containing a second `', i + 4); const comment_end = close === -1 || close + 3 > end ? end : close + 3; l.leaf(T_COMMENT, i, comment_end); return comment_end; } if (i + 9 <= end && matches_ci(text, i + 2, 'doctype')) { let j = i + 9; while (j < end) { const c = text.charCodeAt(j); if (c === 62) break; // > if (c === 91) { // [ internal subset — skip to the matching ] const close_bracket = text.indexOf(']', j + 1); j = close_bracket === -1 || close_bracket >= end ? end : close_bracket + 1; continue; } j++; } const doctype_end = j < end ? j + 1 : end; l.leaf(T_DOCTYPE, i, doctype_end); return doctype_end; } if ( i + 9 <= end && text.charCodeAt(i + 2) === 91 && matches_ci(text, i + 3, 'cdata') && text.charCodeAt(i + 8) === 91 ) { const close = text.indexOf(']]>', i + 9); const cdata_end = close === -1 || close + 3 > end ? end : close + 3; l.leaf(T_CDATA, i, cdata_end); return cdata_end; } } else if (c1 === 63) { // ', i + 2); const pi_end = close === -1 || close + 2 > end ? end : close + 2; l.leaf(T_PROCESSING_INSTRUCTION, i, pi_end); return pi_end; } const after_tag = lex_markup_tag(l, i, end, mode, cache); // rawtext elements — opening tags only; a self-closing slash is ignored // (per HTML parsing, `