import { readEntityReference } from './entity-references.ts' export type LinePosition = 'first' | 'later' type OpenHtmlBlock = { closer: RegExp | undefined; construct: string } type HtmlBlockCondition = { closer: RegExp | undefined; construct: string | undefined; interrupts: boolean; start: RegExp } const htmlConstructNames = { cdata: 'a CDATA section', comment: 'an HTML comment', declaration: 'an HTML declaration', processingInstruction: 'an HTML processing instruction', } const controlCharacterRange = '\\u0000-\\u001f\\u007f' const autolinkSource = `[A-Za-z][A-Za-z0-9+.-]{1,31}:[^\\s<>${controlCharacterRange}]*` const nullCharacterSource = '\\u0000' const tagNameSource = '[A-Za-z][A-Za-z0-9-]*' const htmlSpaceSource = '[ \\t\\n]' const attributeSource = `(?:${htmlSpaceSource}+[A-Za-z_:][A-Za-z0-9_.:-]*(?:${htmlSpaceSource}*=${htmlSpaceSource}*(?:[^ \\t\\n"'=<>\`]+|'[^']*'|"[^"]*"))?)` const htmlTagSource = `(?:<${tagNameSource}${attributeSource}*${htmlSpaceSource}*/?>|)` const autolink = new RegExp(`^(?:${autolinkSource})$`) const bracketedAutolink = new RegExp(`<(?:${autolinkSource})>`, 'y') const controlCharacter = new RegExp(`[${controlCharacterRange}]`) const htmlTag = new RegExp(htmlTagSource, 'y') const nullCharacter = new RegExp(nullCharacterSource) const tagName = new RegExp(`^`). const inlineHtmlConstructs = [ { name: htmlConstructNames.cdata, opener: /' }, { name: htmlConstructNames.comment, opener: /|-->|--)/y, terminator: '-->' }, { name: htmlConstructNames.declaration, opener: /' }, { name: htmlConstructNames.processingInstruction, opener: /<\?/y, terminator: '?>' }, ] // CommonMark 0.31.2, HTML blocks: the tag names start condition 6 lists. const blockTagNames = 'address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul' const completeTag = new RegExp(`^${htmlTagSource}[ \\t]*$`) const htmlBlockConditions: HtmlBlockCondition[] = [ { closer: /<\/(?:pre|script|style|textarea)>/i, construct: undefined, interrupts: true, start: /^<(?:pre|script|style|textarea)(?:[ \t>]|$)/i }, { closer: /-->/, construct: htmlConstructNames.comment, interrupts: true, start: /^