From 9941d583a07dd0ec8c7740783ca8665f52331f3d Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 16 May 2022 21:25:05 -0400 Subject: Parse5 update (#2140) * Update build-libs.js * Add a test for build-libs.js * Update parse5 * Rebuild parse5 * Update build-libs.js to generate consistent path names * Rebuild --- ext/lib/parse5.js | 12753 +++++++++++++++++++++++++++------------------------- 1 file changed, 6600 insertions(+), 6153 deletions(-) (limited to 'ext/lib') diff --git a/ext/lib/parse5.js b/ext/lib/parse5.js index 1519dedc..72e1bbf1 100644 --- a/ext/lib/parse5.js +++ b/ext/lib/parse5.js @@ -1,13 +1,12 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.parse5 = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i publicId.startsWith(prefix)); } - //API -exports.isConforming = function(token) { - return ( - token.name === VALID_DOCTYPE_NAME && +function isConforming(token) { + return (token.name === VALID_DOCTYPE_NAME && token.publicId === null && - (token.systemId === null || token.systemId === VALID_SYSTEM_ID) - ); -}; - -exports.getDocumentMode = function(token) { + (token.systemId === null || token.systemId === VALID_SYSTEM_ID)); +} +exports.isConforming = isConforming; +function getDocumentMode(token) { if (token.name !== VALID_DOCTYPE_NAME) { - return DOCUMENT_MODE.QUIRKS; + return html_js_1.DOCUMENT_MODE.QUIRKS; } - - const systemId = token.systemId; - + const { systemId } = token; if (systemId && systemId.toLowerCase() === QUIRKS_MODE_SYSTEM_ID) { - return DOCUMENT_MODE.QUIRKS; + return html_js_1.DOCUMENT_MODE.QUIRKS; } - - let publicId = token.publicId; - + let { publicId } = token; if (publicId !== null) { publicId = publicId.toLowerCase(); - - if (QUIRKS_MODE_PUBLIC_IDS.indexOf(publicId) > -1) { - return DOCUMENT_MODE.QUIRKS; + if (QUIRKS_MODE_PUBLIC_IDS.has(publicId)) { + return html_js_1.DOCUMENT_MODE.QUIRKS; } - let prefixes = systemId === null ? QUIRKS_MODE_NO_SYSTEM_ID_PUBLIC_ID_PREFIXES : QUIRKS_MODE_PUBLIC_ID_PREFIXES; - if (hasPrefix(publicId, prefixes)) { - return DOCUMENT_MODE.QUIRKS; + return html_js_1.DOCUMENT_MODE.QUIRKS; } - prefixes = systemId === null ? LIMITED_QUIRKS_PUBLIC_ID_PREFIXES : LIMITED_QUIRKS_WITH_SYSTEM_ID_PUBLIC_ID_PREFIXES; - if (hasPrefix(publicId, prefixes)) { - return DOCUMENT_MODE.LIMITED_QUIRKS; - } - } - - return DOCUMENT_MODE.NO_QUIRKS; -}; - -exports.serializeContent = function(name, publicId, systemId) { - let str = '!DOCTYPE '; - - if (name) { - str += name; - } - - if (publicId) { - str += ' PUBLIC ' + enquoteDoctypeId(publicId); - } else if (systemId) { - str += ' SYSTEM'; - } - - if (systemId !== null) { - str += ' ' + enquoteDoctypeId(systemId); - } - - return str; -}; - -},{"./html":4}],2:[function(require,module,exports){ -'use strict'; - -module.exports = { - controlCharacterInInputStream: 'control-character-in-input-stream', - noncharacterInInputStream: 'noncharacter-in-input-stream', - surrogateInInputStream: 'surrogate-in-input-stream', - nonVoidHtmlElementStartTagWithTrailingSolidus: 'non-void-html-element-start-tag-with-trailing-solidus', - endTagWithAttributes: 'end-tag-with-attributes', - endTagWithTrailingSolidus: 'end-tag-with-trailing-solidus', - unexpectedSolidusInTag: 'unexpected-solidus-in-tag', - unexpectedNullCharacter: 'unexpected-null-character', - unexpectedQuestionMarkInsteadOfTagName: 'unexpected-question-mark-instead-of-tag-name', - invalidFirstCharacterOfTagName: 'invalid-first-character-of-tag-name', - unexpectedEqualsSignBeforeAttributeName: 'unexpected-equals-sign-before-attribute-name', - missingEndTagName: 'missing-end-tag-name', - unexpectedCharacterInAttributeName: 'unexpected-character-in-attribute-name', - unknownNamedCharacterReference: 'unknown-named-character-reference', - missingSemicolonAfterCharacterReference: 'missing-semicolon-after-character-reference', - unexpectedCharacterAfterDoctypeSystemIdentifier: 'unexpected-character-after-doctype-system-identifier', - unexpectedCharacterInUnquotedAttributeValue: 'unexpected-character-in-unquoted-attribute-value', - eofBeforeTagName: 'eof-before-tag-name', - eofInTag: 'eof-in-tag', - missingAttributeValue: 'missing-attribute-value', - missingWhitespaceBetweenAttributes: 'missing-whitespace-between-attributes', - missingWhitespaceAfterDoctypePublicKeyword: 'missing-whitespace-after-doctype-public-keyword', - missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers: - 'missing-whitespace-between-doctype-public-and-system-identifiers', - missingWhitespaceAfterDoctypeSystemKeyword: 'missing-whitespace-after-doctype-system-keyword', - missingQuoteBeforeDoctypePublicIdentifier: 'missing-quote-before-doctype-public-identifier', - missingQuoteBeforeDoctypeSystemIdentifier: 'missing-quote-before-doctype-system-identifier', - missingDoctypePublicIdentifier: 'missing-doctype-public-identifier', - missingDoctypeSystemIdentifier: 'missing-doctype-system-identifier', - abruptDoctypePublicIdentifier: 'abrupt-doctype-public-identifier', - abruptDoctypeSystemIdentifier: 'abrupt-doctype-system-identifier', - cdataInHtmlContent: 'cdata-in-html-content', - incorrectlyOpenedComment: 'incorrectly-opened-comment', - eofInScriptHtmlCommentLikeText: 'eof-in-script-html-comment-like-text', - eofInDoctype: 'eof-in-doctype', - nestedComment: 'nested-comment', - abruptClosingOfEmptyComment: 'abrupt-closing-of-empty-comment', - eofInComment: 'eof-in-comment', - incorrectlyClosedComment: 'incorrectly-closed-comment', - eofInCdata: 'eof-in-cdata', - absenceOfDigitsInNumericCharacterReference: 'absence-of-digits-in-numeric-character-reference', - nullCharacterReference: 'null-character-reference', - surrogateCharacterReference: 'surrogate-character-reference', - characterReferenceOutsideUnicodeRange: 'character-reference-outside-unicode-range', - controlCharacterReference: 'control-character-reference', - noncharacterCharacterReference: 'noncharacter-character-reference', - missingWhitespaceBeforeDoctypeName: 'missing-whitespace-before-doctype-name', - missingDoctypeName: 'missing-doctype-name', - invalidCharacterSequenceAfterDoctypeName: 'invalid-character-sequence-after-doctype-name', - duplicateAttribute: 'duplicate-attribute', - nonConformingDoctype: 'non-conforming-doctype', - missingDoctype: 'missing-doctype', - misplacedDoctype: 'misplaced-doctype', - endTagWithoutMatchingOpenElement: 'end-tag-without-matching-open-element', - closingOfElementWithOpenChildElements: 'closing-of-element-with-open-child-elements', - disallowedContentInNoscriptInHead: 'disallowed-content-in-noscript-in-head', - openElementsLeftAfterEof: 'open-elements-left-after-eof', - abandonedHeadElementChild: 'abandoned-head-element-child', - misplacedStartTagForHeadElement: 'misplaced-start-tag-for-head-element', - nestedNoscriptInHead: 'nested-noscript-in-head', - eofInElementThatCanContainOnlyText: 'eof-in-element-that-can-contain-only-text' -}; + return html_js_1.DOCUMENT_MODE.LIMITED_QUIRKS; + } + } + return html_js_1.DOCUMENT_MODE.NO_QUIRKS; +} +exports.getDocumentMode = getDocumentMode; + +},{"./html.js":4}],2:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ERR = void 0; +var ERR; +(function (ERR) { + ERR["controlCharacterInInputStream"] = "control-character-in-input-stream"; + ERR["noncharacterInInputStream"] = "noncharacter-in-input-stream"; + ERR["surrogateInInputStream"] = "surrogate-in-input-stream"; + ERR["nonVoidHtmlElementStartTagWithTrailingSolidus"] = "non-void-html-element-start-tag-with-trailing-solidus"; + ERR["endTagWithAttributes"] = "end-tag-with-attributes"; + ERR["endTagWithTrailingSolidus"] = "end-tag-with-trailing-solidus"; + ERR["unexpectedSolidusInTag"] = "unexpected-solidus-in-tag"; + ERR["unexpectedNullCharacter"] = "unexpected-null-character"; + ERR["unexpectedQuestionMarkInsteadOfTagName"] = "unexpected-question-mark-instead-of-tag-name"; + ERR["invalidFirstCharacterOfTagName"] = "invalid-first-character-of-tag-name"; + ERR["unexpectedEqualsSignBeforeAttributeName"] = "unexpected-equals-sign-before-attribute-name"; + ERR["missingEndTagName"] = "missing-end-tag-name"; + ERR["unexpectedCharacterInAttributeName"] = "unexpected-character-in-attribute-name"; + ERR["unknownNamedCharacterReference"] = "unknown-named-character-reference"; + ERR["missingSemicolonAfterCharacterReference"] = "missing-semicolon-after-character-reference"; + ERR["unexpectedCharacterAfterDoctypeSystemIdentifier"] = "unexpected-character-after-doctype-system-identifier"; + ERR["unexpectedCharacterInUnquotedAttributeValue"] = "unexpected-character-in-unquoted-attribute-value"; + ERR["eofBeforeTagName"] = "eof-before-tag-name"; + ERR["eofInTag"] = "eof-in-tag"; + ERR["missingAttributeValue"] = "missing-attribute-value"; + ERR["missingWhitespaceBetweenAttributes"] = "missing-whitespace-between-attributes"; + ERR["missingWhitespaceAfterDoctypePublicKeyword"] = "missing-whitespace-after-doctype-public-keyword"; + ERR["missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers"] = "missing-whitespace-between-doctype-public-and-system-identifiers"; + ERR["missingWhitespaceAfterDoctypeSystemKeyword"] = "missing-whitespace-after-doctype-system-keyword"; + ERR["missingQuoteBeforeDoctypePublicIdentifier"] = "missing-quote-before-doctype-public-identifier"; + ERR["missingQuoteBeforeDoctypeSystemIdentifier"] = "missing-quote-before-doctype-system-identifier"; + ERR["missingDoctypePublicIdentifier"] = "missing-doctype-public-identifier"; + ERR["missingDoctypeSystemIdentifier"] = "missing-doctype-system-identifier"; + ERR["abruptDoctypePublicIdentifier"] = "abrupt-doctype-public-identifier"; + ERR["abruptDoctypeSystemIdentifier"] = "abrupt-doctype-system-identifier"; + ERR["cdataInHtmlContent"] = "cdata-in-html-content"; + ERR["incorrectlyOpenedComment"] = "incorrectly-opened-comment"; + ERR["eofInScriptHtmlCommentLikeText"] = "eof-in-script-html-comment-like-text"; + ERR["eofInDoctype"] = "eof-in-doctype"; + ERR["nestedComment"] = "nested-comment"; + ERR["abruptClosingOfEmptyComment"] = "abrupt-closing-of-empty-comment"; + ERR["eofInComment"] = "eof-in-comment"; + ERR["incorrectlyClosedComment"] = "incorrectly-closed-comment"; + ERR["eofInCdata"] = "eof-in-cdata"; + ERR["absenceOfDigitsInNumericCharacterReference"] = "absence-of-digits-in-numeric-character-reference"; + ERR["nullCharacterReference"] = "null-character-reference"; + ERR["surrogateCharacterReference"] = "surrogate-character-reference"; + ERR["characterReferenceOutsideUnicodeRange"] = "character-reference-outside-unicode-range"; + ERR["controlCharacterReference"] = "control-character-reference"; + ERR["noncharacterCharacterReference"] = "noncharacter-character-reference"; + ERR["missingWhitespaceBeforeDoctypeName"] = "missing-whitespace-before-doctype-name"; + ERR["missingDoctypeName"] = "missing-doctype-name"; + ERR["invalidCharacterSequenceAfterDoctypeName"] = "invalid-character-sequence-after-doctype-name"; + ERR["duplicateAttribute"] = "duplicate-attribute"; + ERR["nonConformingDoctype"] = "non-conforming-doctype"; + ERR["missingDoctype"] = "missing-doctype"; + ERR["misplacedDoctype"] = "misplaced-doctype"; + ERR["endTagWithoutMatchingOpenElement"] = "end-tag-without-matching-open-element"; + ERR["closingOfElementWithOpenChildElements"] = "closing-of-element-with-open-child-elements"; + ERR["disallowedContentInNoscriptInHead"] = "disallowed-content-in-noscript-in-head"; + ERR["openElementsLeftAfterEof"] = "open-elements-left-after-eof"; + ERR["abandonedHeadElementChild"] = "abandoned-head-element-child"; + ERR["misplacedStartTagForHeadElement"] = "misplaced-start-tag-for-head-element"; + ERR["nestedNoscriptInHead"] = "nested-noscript-in-head"; + ERR["eofInElementThatCanContainOnlyText"] = "eof-in-element-that-can-contain-only-text"; +})(ERR = exports.ERR || (exports.ERR = {})); },{}],3:[function(require,module,exports){ -'use strict'; - -const Tokenizer = require('../tokenizer'); -const HTML = require('./html'); - -//Aliases -const $ = HTML.TAG_NAMES; -const NS = HTML.NAMESPACES; -const ATTRS = HTML.ATTRS; - +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isIntegrationPoint = exports.adjustTokenSVGTagName = exports.adjustTokenXMLAttrs = exports.adjustTokenSVGAttrs = exports.adjustTokenMathMLAttrs = exports.causesExit = exports.SVG_TAG_NAMES_ADJUSTMENT_MAP = void 0; +const html_js_1 = require("./html.js"); //MIME types const MIME_TYPES = { TEXT_HTML: 'text/html', - APPLICATION_XML: 'application/xhtml+xml' + APPLICATION_XML: 'application/xhtml+xml', }; - //Attributes const DEFINITION_URL_ATTR = 'definitionurl'; const ADJUSTED_DEFINITION_URL_ATTR = 'definitionURL'; -const SVG_ATTRS_ADJUSTMENT_MAP = { - attributename: 'attributeName', - attributetype: 'attributeType', - basefrequency: 'baseFrequency', - baseprofile: 'baseProfile', - calcmode: 'calcMode', - clippathunits: 'clipPathUnits', - diffuseconstant: 'diffuseConstant', - edgemode: 'edgeMode', - filterunits: 'filterUnits', - glyphref: 'glyphRef', - gradienttransform: 'gradientTransform', - gradientunits: 'gradientUnits', - kernelmatrix: 'kernelMatrix', - kernelunitlength: 'kernelUnitLength', - keypoints: 'keyPoints', - keysplines: 'keySplines', - keytimes: 'keyTimes', - lengthadjust: 'lengthAdjust', - limitingconeangle: 'limitingConeAngle', - markerheight: 'markerHeight', - markerunits: 'markerUnits', - markerwidth: 'markerWidth', - maskcontentunits: 'maskContentUnits', - maskunits: 'maskUnits', - numoctaves: 'numOctaves', - pathlength: 'pathLength', - patterncontentunits: 'patternContentUnits', - patterntransform: 'patternTransform', - patternunits: 'patternUnits', - pointsatx: 'pointsAtX', - pointsaty: 'pointsAtY', - pointsatz: 'pointsAtZ', - preservealpha: 'preserveAlpha', - preserveaspectratio: 'preserveAspectRatio', - primitiveunits: 'primitiveUnits', - refx: 'refX', - refy: 'refY', - repeatcount: 'repeatCount', - repeatdur: 'repeatDur', - requiredextensions: 'requiredExtensions', - requiredfeatures: 'requiredFeatures', - specularconstant: 'specularConstant', - specularexponent: 'specularExponent', - spreadmethod: 'spreadMethod', - startoffset: 'startOffset', - stddeviation: 'stdDeviation', - stitchtiles: 'stitchTiles', - surfacescale: 'surfaceScale', - systemlanguage: 'systemLanguage', - tablevalues: 'tableValues', - targetx: 'targetX', - targety: 'targetY', - textlength: 'textLength', - viewbox: 'viewBox', - viewtarget: 'viewTarget', - xchannelselector: 'xChannelSelector', - ychannelselector: 'yChannelSelector', - zoomandpan: 'zoomAndPan' -}; - -const XML_ATTRS_ADJUSTMENT_MAP = { - 'xlink:actuate': { prefix: 'xlink', name: 'actuate', namespace: NS.XLINK }, - 'xlink:arcrole': { prefix: 'xlink', name: 'arcrole', namespace: NS.XLINK }, - 'xlink:href': { prefix: 'xlink', name: 'href', namespace: NS.XLINK }, - 'xlink:role': { prefix: 'xlink', name: 'role', namespace: NS.XLINK }, - 'xlink:show': { prefix: 'xlink', name: 'show', namespace: NS.XLINK }, - 'xlink:title': { prefix: 'xlink', name: 'title', namespace: NS.XLINK }, - 'xlink:type': { prefix: 'xlink', name: 'type', namespace: NS.XLINK }, - 'xml:base': { prefix: 'xml', name: 'base', namespace: NS.XML }, - 'xml:lang': { prefix: 'xml', name: 'lang', namespace: NS.XML }, - 'xml:space': { prefix: 'xml', name: 'space', namespace: NS.XML }, - xmlns: { prefix: '', name: 'xmlns', namespace: NS.XMLNS }, - 'xmlns:xlink': { prefix: 'xmlns', name: 'xlink', namespace: NS.XMLNS } -}; - +const SVG_ATTRS_ADJUSTMENT_MAP = new Map([ + 'attributeName', + 'attributeType', + 'baseFrequency', + 'baseProfile', + 'calcMode', + 'clipPathUnits', + 'diffuseConstant', + 'edgeMode', + 'filterUnits', + 'glyphRef', + 'gradientTransform', + 'gradientUnits', + 'kernelMatrix', + 'kernelUnitLength', + 'keyPoints', + 'keySplines', + 'keyTimes', + 'lengthAdjust', + 'limitingConeAngle', + 'markerHeight', + 'markerUnits', + 'markerWidth', + 'maskContentUnits', + 'maskUnits', + 'numOctaves', + 'pathLength', + 'patternContentUnits', + 'patternTransform', + 'patternUnits', + 'pointsAtX', + 'pointsAtY', + 'pointsAtZ', + 'preserveAlpha', + 'preserveAspectRatio', + 'primitiveUnits', + 'refX', + 'refY', + 'repeatCount', + 'repeatDur', + 'requiredExtensions', + 'requiredFeatures', + 'specularConstant', + 'specularExponent', + 'spreadMethod', + 'startOffset', + 'stdDeviation', + 'stitchTiles', + 'surfaceScale', + 'systemLanguage', + 'tableValues', + 'targetX', + 'targetY', + 'textLength', + 'viewBox', + 'viewTarget', + 'xChannelSelector', + 'yChannelSelector', + 'zoomAndPan', +].map((attr) => [attr.toLowerCase(), attr])); +const XML_ATTRS_ADJUSTMENT_MAP = new Map([ + ['xlink:actuate', { prefix: 'xlink', name: 'actuate', namespace: html_js_1.NS.XLINK }], + ['xlink:arcrole', { prefix: 'xlink', name: 'arcrole', namespace: html_js_1.NS.XLINK }], + ['xlink:href', { prefix: 'xlink', name: 'href', namespace: html_js_1.NS.XLINK }], + ['xlink:role', { prefix: 'xlink', name: 'role', namespace: html_js_1.NS.XLINK }], + ['xlink:show', { prefix: 'xlink', name: 'show', namespace: html_js_1.NS.XLINK }], + ['xlink:title', { prefix: 'xlink', name: 'title', namespace: html_js_1.NS.XLINK }], + ['xlink:type', { prefix: 'xlink', name: 'type', namespace: html_js_1.NS.XLINK }], + ['xml:base', { prefix: 'xml', name: 'base', namespace: html_js_1.NS.XML }], + ['xml:lang', { prefix: 'xml', name: 'lang', namespace: html_js_1.NS.XML }], + ['xml:space', { prefix: 'xml', name: 'space', namespace: html_js_1.NS.XML }], + ['xmlns', { prefix: '', name: 'xmlns', namespace: html_js_1.NS.XMLNS }], + ['xmlns:xlink', { prefix: 'xmlns', name: 'xlink', namespace: html_js_1.NS.XMLNS }], +]); //SVG tag names adjustment map -const SVG_TAG_NAMES_ADJUSTMENT_MAP = (exports.SVG_TAG_NAMES_ADJUSTMENT_MAP = { - altglyph: 'altGlyph', - altglyphdef: 'altGlyphDef', - altglyphitem: 'altGlyphItem', - animatecolor: 'animateColor', - animatemotion: 'animateMotion', - animatetransform: 'animateTransform', - clippath: 'clipPath', - feblend: 'feBlend', - fecolormatrix: 'feColorMatrix', - fecomponenttransfer: 'feComponentTransfer', - fecomposite: 'feComposite', - feconvolvematrix: 'feConvolveMatrix', - fediffuselighting: 'feDiffuseLighting', - fedisplacementmap: 'feDisplacementMap', - fedistantlight: 'feDistantLight', - feflood: 'feFlood', - fefunca: 'feFuncA', - fefuncb: 'feFuncB', - fefuncg: 'feFuncG', - fefuncr: 'feFuncR', - fegaussianblur: 'feGaussianBlur', - feimage: 'feImage', - femerge: 'feMerge', - femergenode: 'feMergeNode', - femorphology: 'feMorphology', - feoffset: 'feOffset', - fepointlight: 'fePointLight', - fespecularlighting: 'feSpecularLighting', - fespotlight: 'feSpotLight', - fetile: 'feTile', - feturbulence: 'feTurbulence', - foreignobject: 'foreignObject', - glyphref: 'glyphRef', - lineargradient: 'linearGradient', - radialgradient: 'radialGradient', - textpath: 'textPath' -}); - +exports.SVG_TAG_NAMES_ADJUSTMENT_MAP = new Map([ + 'altGlyph', + 'altGlyphDef', + 'altGlyphItem', + 'animateColor', + 'animateMotion', + 'animateTransform', + 'clipPath', + 'feBlend', + 'feColorMatrix', + 'feComponentTransfer', + 'feComposite', + 'feConvolveMatrix', + 'feDiffuseLighting', + 'feDisplacementMap', + 'feDistantLight', + 'feFlood', + 'feFuncA', + 'feFuncB', + 'feFuncG', + 'feFuncR', + 'feGaussianBlur', + 'feImage', + 'feMerge', + 'feMergeNode', + 'feMorphology', + 'feOffset', + 'fePointLight', + 'feSpecularLighting', + 'feSpotLight', + 'feTile', + 'feTurbulence', + 'foreignObject', + 'glyphRef', + 'linearGradient', + 'radialGradient', + 'textPath', +].map((tn) => [tn.toLowerCase(), tn])); //Tags that causes exit from foreign content -const EXITS_FOREIGN_CONTENT = { - [$.B]: true, - [$.BIG]: true, - [$.BLOCKQUOTE]: true, - [$.BODY]: true, - [$.BR]: true, - [$.CENTER]: true, - [$.CODE]: true, - [$.DD]: true, - [$.DIV]: true, - [$.DL]: true, - [$.DT]: true, - [$.EM]: true, - [$.EMBED]: true, - [$.H1]: true, - [$.H2]: true, - [$.H3]: true, - [$.H4]: true, - [$.H5]: true, - [$.H6]: true, - [$.HEAD]: true, - [$.HR]: true, - [$.I]: true, - [$.IMG]: true, - [$.LI]: true, - [$.LISTING]: true, - [$.MENU]: true, - [$.META]: true, - [$.NOBR]: true, - [$.OL]: true, - [$.P]: true, - [$.PRE]: true, - [$.RUBY]: true, - [$.S]: true, - [$.SMALL]: true, - [$.SPAN]: true, - [$.STRONG]: true, - [$.STRIKE]: true, - [$.SUB]: true, - [$.SUP]: true, - [$.TABLE]: true, - [$.TT]: true, - [$.U]: true, - [$.UL]: true, - [$.VAR]: true -}; - +const EXITS_FOREIGN_CONTENT = new Set([ + html_js_1.TAG_ID.B, + html_js_1.TAG_ID.BIG, + html_js_1.TAG_ID.BLOCKQUOTE, + html_js_1.TAG_ID.BODY, + html_js_1.TAG_ID.BR, + html_js_1.TAG_ID.CENTER, + html_js_1.TAG_ID.CODE, + html_js_1.TAG_ID.DD, + html_js_1.TAG_ID.DIV, + html_js_1.TAG_ID.DL, + html_js_1.TAG_ID.DT, + html_js_1.TAG_ID.EM, + html_js_1.TAG_ID.EMBED, + html_js_1.TAG_ID.H1, + html_js_1.TAG_ID.H2, + html_js_1.TAG_ID.H3, + html_js_1.TAG_ID.H4, + html_js_1.TAG_ID.H5, + html_js_1.TAG_ID.H6, + html_js_1.TAG_ID.HEAD, + html_js_1.TAG_ID.HR, + html_js_1.TAG_ID.I, + html_js_1.TAG_ID.IMG, + html_js_1.TAG_ID.LI, + html_js_1.TAG_ID.LISTING, + html_js_1.TAG_ID.MENU, + html_js_1.TAG_ID.META, + html_js_1.TAG_ID.NOBR, + html_js_1.TAG_ID.OL, + html_js_1.TAG_ID.P, + html_js_1.TAG_ID.PRE, + html_js_1.TAG_ID.RUBY, + html_js_1.TAG_ID.S, + html_js_1.TAG_ID.SMALL, + html_js_1.TAG_ID.SPAN, + html_js_1.TAG_ID.STRONG, + html_js_1.TAG_ID.STRIKE, + html_js_1.TAG_ID.SUB, + html_js_1.TAG_ID.SUP, + html_js_1.TAG_ID.TABLE, + html_js_1.TAG_ID.TT, + html_js_1.TAG_ID.U, + html_js_1.TAG_ID.UL, + html_js_1.TAG_ID.VAR, +]); //Check exit from foreign content -exports.causesExit = function(startTagToken) { - const tn = startTagToken.tagName; - const isFontWithAttrs = - tn === $.FONT && - (Tokenizer.getTokenAttr(startTagToken, ATTRS.COLOR) !== null || - Tokenizer.getTokenAttr(startTagToken, ATTRS.SIZE) !== null || - Tokenizer.getTokenAttr(startTagToken, ATTRS.FACE) !== null); - - return isFontWithAttrs ? true : EXITS_FOREIGN_CONTENT[tn]; -}; - +function causesExit(startTagToken) { + const tn = startTagToken.tagID; + const isFontWithAttrs = tn === html_js_1.TAG_ID.FONT && + startTagToken.attrs.some(({ name }) => name === html_js_1.ATTRS.COLOR || name === html_js_1.ATTRS.SIZE || name === html_js_1.ATTRS.FACE); + return isFontWithAttrs || EXITS_FOREIGN_CONTENT.has(tn); +} +exports.causesExit = causesExit; //Token adjustments -exports.adjustTokenMathMLAttrs = function(token) { +function adjustTokenMathMLAttrs(token) { for (let i = 0; i < token.attrs.length; i++) { if (token.attrs[i].name === DEFINITION_URL_ATTR) { token.attrs[i].name = ADJUSTED_DEFINITION_URL_ATTR; break; } } -}; - -exports.adjustTokenSVGAttrs = function(token) { +} +exports.adjustTokenMathMLAttrs = adjustTokenMathMLAttrs; +function adjustTokenSVGAttrs(token) { for (let i = 0; i < token.attrs.length; i++) { - const adjustedAttrName = SVG_ATTRS_ADJUSTMENT_MAP[token.attrs[i].name]; - - if (adjustedAttrName) { + const adjustedAttrName = SVG_ATTRS_ADJUSTMENT_MAP.get(token.attrs[i].name); + if (adjustedAttrName != null) { token.attrs[i].name = adjustedAttrName; } } -}; - -exports.adjustTokenXMLAttrs = function(token) { +} +exports.adjustTokenSVGAttrs = adjustTokenSVGAttrs; +function adjustTokenXMLAttrs(token) { for (let i = 0; i < token.attrs.length; i++) { - const adjustedAttrEntry = XML_ATTRS_ADJUSTMENT_MAP[token.attrs[i].name]; - + const adjustedAttrEntry = XML_ATTRS_ADJUSTMENT_MAP.get(token.attrs[i].name); if (adjustedAttrEntry) { token.attrs[i].prefix = adjustedAttrEntry.prefix; token.attrs[i].name = adjustedAttrEntry.name; token.attrs[i].namespace = adjustedAttrEntry.namespace; } } -}; - -exports.adjustTokenSVGTagName = function(token) { - const adjustedTagName = SVG_TAG_NAMES_ADJUSTMENT_MAP[token.tagName]; - - if (adjustedTagName) { +} +exports.adjustTokenXMLAttrs = adjustTokenXMLAttrs; +function adjustTokenSVGTagName(token) { + const adjustedTagName = exports.SVG_TAG_NAMES_ADJUSTMENT_MAP.get(token.tagName); + if (adjustedTagName != null) { token.tagName = adjustedTagName; + token.tagID = (0, html_js_1.getTagID)(token.tagName); } -}; - +} +exports.adjustTokenSVGTagName = adjustTokenSVGTagName; //Integration points function isMathMLTextIntegrationPoint(tn, ns) { - return ns === NS.MATHML && (tn === $.MI || tn === $.MO || tn === $.MN || tn === $.MS || tn === $.MTEXT); + return ns === html_js_1.NS.MATHML && (tn === html_js_1.TAG_ID.MI || tn === html_js_1.TAG_ID.MO || tn === html_js_1.TAG_ID.MN || tn === html_js_1.TAG_ID.MS || tn === html_js_1.TAG_ID.MTEXT); } - function isHtmlIntegrationPoint(tn, ns, attrs) { - if (ns === NS.MATHML && tn === $.ANNOTATION_XML) { + if (ns === html_js_1.NS.MATHML && tn === html_js_1.TAG_ID.ANNOTATION_XML) { for (let i = 0; i < attrs.length; i++) { - if (attrs[i].name === ATTRS.ENCODING) { + if (attrs[i].name === html_js_1.ATTRS.ENCODING) { const value = attrs[i].value.toLowerCase(); - return value === MIME_TYPES.TEXT_HTML || value === MIME_TYPES.APPLICATION_XML; } } } - - return ns === NS.SVG && (tn === $.FOREIGN_OBJECT || tn === $.DESC || tn === $.TITLE); + return ns === html_js_1.NS.SVG && (tn === html_js_1.TAG_ID.FOREIGN_OBJECT || tn === html_js_1.TAG_ID.DESC || tn === html_js_1.TAG_ID.TITLE); +} +function isIntegrationPoint(tn, ns, attrs, foreignNS) { + return (((!foreignNS || foreignNS === html_js_1.NS.HTML) && isHtmlIntegrationPoint(tn, ns, attrs)) || + ((!foreignNS || foreignNS === html_js_1.NS.MATHML) && isMathMLTextIntegrationPoint(tn, ns))); +} +exports.isIntegrationPoint = isIntegrationPoint; + +},{"./html.js":4}],4:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.hasUnescapedText = exports.isNumberedHeader = exports.SPECIAL_ELEMENTS = exports.getTagID = exports.TAG_ID = exports.TAG_NAMES = exports.DOCUMENT_MODE = exports.ATTRS = exports.NS = void 0; +/** All valid namespaces in HTML. */ +var NS; +(function (NS) { + NS["HTML"] = "http://www.w3.org/1999/xhtml"; + NS["MATHML"] = "http://www.w3.org/1998/Math/MathML"; + NS["SVG"] = "http://www.w3.org/2000/svg"; + NS["XLINK"] = "http://www.w3.org/1999/xlink"; + NS["XML"] = "http://www.w3.org/XML/1998/namespace"; + NS["XMLNS"] = "http://www.w3.org/2000/xmlns/"; +})(NS = exports.NS || (exports.NS = {})); +var ATTRS; +(function (ATTRS) { + ATTRS["TYPE"] = "type"; + ATTRS["ACTION"] = "action"; + ATTRS["ENCODING"] = "encoding"; + ATTRS["PROMPT"] = "prompt"; + ATTRS["NAME"] = "name"; + ATTRS["COLOR"] = "color"; + ATTRS["FACE"] = "face"; + ATTRS["SIZE"] = "size"; +})(ATTRS = exports.ATTRS || (exports.ATTRS = {})); +/** + * The mode of the document. + * + * @see {@link https://dom.spec.whatwg.org/#concept-document-limited-quirks} + */ +var DOCUMENT_MODE; +(function (DOCUMENT_MODE) { + DOCUMENT_MODE["NO_QUIRKS"] = "no-quirks"; + DOCUMENT_MODE["QUIRKS"] = "quirks"; + DOCUMENT_MODE["LIMITED_QUIRKS"] = "limited-quirks"; +})(DOCUMENT_MODE = exports.DOCUMENT_MODE || (exports.DOCUMENT_MODE = {})); +var TAG_NAMES; +(function (TAG_NAMES) { + TAG_NAMES["A"] = "a"; + TAG_NAMES["ADDRESS"] = "address"; + TAG_NAMES["ANNOTATION_XML"] = "annotation-xml"; + TAG_NAMES["APPLET"] = "applet"; + TAG_NAMES["AREA"] = "area"; + TAG_NAMES["ARTICLE"] = "article"; + TAG_NAMES["ASIDE"] = "aside"; + TAG_NAMES["B"] = "b"; + TAG_NAMES["BASE"] = "base"; + TAG_NAMES["BASEFONT"] = "basefont"; + TAG_NAMES["BGSOUND"] = "bgsound"; + TAG_NAMES["BIG"] = "big"; + TAG_NAMES["BLOCKQUOTE"] = "blockquote"; + TAG_NAMES["BODY"] = "body"; + TAG_NAMES["BR"] = "br"; + TAG_NAMES["BUTTON"] = "button"; + TAG_NAMES["CAPTION"] = "caption"; + TAG_NAMES["CENTER"] = "center"; + TAG_NAMES["CODE"] = "code"; + TAG_NAMES["COL"] = "col"; + TAG_NAMES["COLGROUP"] = "colgroup"; + TAG_NAMES["DD"] = "dd"; + TAG_NAMES["DESC"] = "desc"; + TAG_NAMES["DETAILS"] = "details"; + TAG_NAMES["DIALOG"] = "dialog"; + TAG_NAMES["DIR"] = "dir"; + TAG_NAMES["DIV"] = "div"; + TAG_NAMES["DL"] = "dl"; + TAG_NAMES["DT"] = "dt"; + TAG_NAMES["EM"] = "em"; + TAG_NAMES["EMBED"] = "embed"; + TAG_NAMES["FIELDSET"] = "fieldset"; + TAG_NAMES["FIGCAPTION"] = "figcaption"; + TAG_NAMES["FIGURE"] = "figure"; + TAG_NAMES["FONT"] = "font"; + TAG_NAMES["FOOTER"] = "footer"; + TAG_NAMES["FOREIGN_OBJECT"] = "foreignObject"; + TAG_NAMES["FORM"] = "form"; + TAG_NAMES["FRAME"] = "frame"; + TAG_NAMES["FRAMESET"] = "frameset"; + TAG_NAMES["H1"] = "h1"; + TAG_NAMES["H2"] = "h2"; + TAG_NAMES["H3"] = "h3"; + TAG_NAMES["H4"] = "h4"; + TAG_NAMES["H5"] = "h5"; + TAG_NAMES["H6"] = "h6"; + TAG_NAMES["HEAD"] = "head"; + TAG_NAMES["HEADER"] = "header"; + TAG_NAMES["HGROUP"] = "hgroup"; + TAG_NAMES["HR"] = "hr"; + TAG_NAMES["HTML"] = "html"; + TAG_NAMES["I"] = "i"; + TAG_NAMES["IMG"] = "img"; + TAG_NAMES["IMAGE"] = "image"; + TAG_NAMES["INPUT"] = "input"; + TAG_NAMES["IFRAME"] = "iframe"; + TAG_NAMES["KEYGEN"] = "keygen"; + TAG_NAMES["LABEL"] = "label"; + TAG_NAMES["LI"] = "li"; + TAG_NAMES["LINK"] = "link"; + TAG_NAMES["LISTING"] = "listing"; + TAG_NAMES["MAIN"] = "main"; + TAG_NAMES["MALIGNMARK"] = "malignmark"; + TAG_NAMES["MARQUEE"] = "marquee"; + TAG_NAMES["MATH"] = "math"; + TAG_NAMES["MENU"] = "menu"; + TAG_NAMES["META"] = "meta"; + TAG_NAMES["MGLYPH"] = "mglyph"; + TAG_NAMES["MI"] = "mi"; + TAG_NAMES["MO"] = "mo"; + TAG_NAMES["MN"] = "mn"; + TAG_NAMES["MS"] = "ms"; + TAG_NAMES["MTEXT"] = "mtext"; + TAG_NAMES["NAV"] = "nav"; + TAG_NAMES["NOBR"] = "nobr"; + TAG_NAMES["NOFRAMES"] = "noframes"; + TAG_NAMES["NOEMBED"] = "noembed"; + TAG_NAMES["NOSCRIPT"] = "noscript"; + TAG_NAMES["OBJECT"] = "object"; + TAG_NAMES["OL"] = "ol"; + TAG_NAMES["OPTGROUP"] = "optgroup"; + TAG_NAMES["OPTION"] = "option"; + TAG_NAMES["P"] = "p"; + TAG_NAMES["PARAM"] = "param"; + TAG_NAMES["PLAINTEXT"] = "plaintext"; + TAG_NAMES["PRE"] = "pre"; + TAG_NAMES["RB"] = "rb"; + TAG_NAMES["RP"] = "rp"; + TAG_NAMES["RT"] = "rt"; + TAG_NAMES["RTC"] = "rtc"; + TAG_NAMES["RUBY"] = "ruby"; + TAG_NAMES["S"] = "s"; + TAG_NAMES["SCRIPT"] = "script"; + TAG_NAMES["SECTION"] = "section"; + TAG_NAMES["SELECT"] = "select"; + TAG_NAMES["SOURCE"] = "source"; + TAG_NAMES["SMALL"] = "small"; + TAG_NAMES["SPAN"] = "span"; + TAG_NAMES["STRIKE"] = "strike"; + TAG_NAMES["STRONG"] = "strong"; + TAG_NAMES["STYLE"] = "style"; + TAG_NAMES["SUB"] = "sub"; + TAG_NAMES["SUMMARY"] = "summary"; + TAG_NAMES["SUP"] = "sup"; + TAG_NAMES["TABLE"] = "table"; + TAG_NAMES["TBODY"] = "tbody"; + TAG_NAMES["TEMPLATE"] = "template"; + TAG_NAMES["TEXTAREA"] = "textarea"; + TAG_NAMES["TFOOT"] = "tfoot"; + TAG_NAMES["TD"] = "td"; + TAG_NAMES["TH"] = "th"; + TAG_NAMES["THEAD"] = "thead"; + TAG_NAMES["TITLE"] = "title"; + TAG_NAMES["TR"] = "tr"; + TAG_NAMES["TRACK"] = "track"; + TAG_NAMES["TT"] = "tt"; + TAG_NAMES["U"] = "u"; + TAG_NAMES["UL"] = "ul"; + TAG_NAMES["SVG"] = "svg"; + TAG_NAMES["VAR"] = "var"; + TAG_NAMES["WBR"] = "wbr"; + TAG_NAMES["XMP"] = "xmp"; +})(TAG_NAMES = exports.TAG_NAMES || (exports.TAG_NAMES = {})); +/** + * Tag IDs are numeric IDs for known tag names. + * + * We use tag IDs to improve the performance of tag name comparisons. + */ +var TAG_ID; +(function (TAG_ID) { + TAG_ID[TAG_ID["UNKNOWN"] = 0] = "UNKNOWN"; + TAG_ID[TAG_ID["A"] = 1] = "A"; + TAG_ID[TAG_ID["ADDRESS"] = 2] = "ADDRESS"; + TAG_ID[TAG_ID["ANNOTATION_XML"] = 3] = "ANNOTATION_XML"; + TAG_ID[TAG_ID["APPLET"] = 4] = "APPLET"; + TAG_ID[TAG_ID["AREA"] = 5] = "AREA"; + TAG_ID[TAG_ID["ARTICLE"] = 6] = "ARTICLE"; + TAG_ID[TAG_ID["ASIDE"] = 7] = "ASIDE"; + TAG_ID[TAG_ID["B"] = 8] = "B"; + TAG_ID[TAG_ID["BASE"] = 9] = "BASE"; + TAG_ID[TAG_ID["BASEFONT"] = 10] = "BASEFONT"; + TAG_ID[TAG_ID["BGSOUND"] = 11] = "BGSOUND"; + TAG_ID[TAG_ID["BIG"] = 12] = "BIG"; + TAG_ID[TAG_ID["BLOCKQUOTE"] = 13] = "BLOCKQUOTE"; + TAG_ID[TAG_ID["BODY"] = 14] = "BODY"; + TAG_ID[TAG_ID["BR"] = 15] = "BR"; + TAG_ID[TAG_ID["BUTTON"] = 16] = "BUTTON"; + TAG_ID[TAG_ID["CAPTION"] = 17] = "CAPTION"; + TAG_ID[TAG_ID["CENTER"] = 18] = "CENTER"; + TAG_ID[TAG_ID["CODE"] = 19] = "CODE"; + TAG_ID[TAG_ID["COL"] = 20] = "COL"; + TAG_ID[TAG_ID["COLGROUP"] = 21] = "COLGROUP"; + TAG_ID[TAG_ID["DD"] = 22] = "DD"; + TAG_ID[TAG_ID["DESC"] = 23] = "DESC"; + TAG_ID[TAG_ID["DETAILS"] = 24] = "DETAILS"; + TAG_ID[TAG_ID["DIALOG"] = 25] = "DIALOG"; + TAG_ID[TAG_ID["DIR"] = 26] = "DIR"; + TAG_ID[TAG_ID["DIV"] = 27] = "DIV"; + TAG_ID[TAG_ID["DL"] = 28] = "DL"; + TAG_ID[TAG_ID["DT"] = 29] = "DT"; + TAG_ID[TAG_ID["EM"] = 30] = "EM"; + TAG_ID[TAG_ID["EMBED"] = 31] = "EMBED"; + TAG_ID[TAG_ID["FIELDSET"] = 32] = "FIELDSET"; + TAG_ID[TAG_ID["FIGCAPTION"] = 33] = "FIGCAPTION"; + TAG_ID[TAG_ID["FIGURE"] = 34] = "FIGURE"; + TAG_ID[TAG_ID["FONT"] = 35] = "FONT"; + TAG_ID[TAG_ID["FOOTER"] = 36] = "FOOTER"; + TAG_ID[TAG_ID["FOREIGN_OBJECT"] = 37] = "FOREIGN_OBJECT"; + TAG_ID[TAG_ID["FORM"] = 38] = "FORM"; + TAG_ID[TAG_ID["FRAME"] = 39] = "FRAME"; + TAG_ID[TAG_ID["FRAMESET"] = 40] = "FRAMESET"; + TAG_ID[TAG_ID["H1"] = 41] = "H1"; + TAG_ID[TAG_ID["H2"] = 42] = "H2"; + TAG_ID[TAG_ID["H3"] = 43] = "H3"; + TAG_ID[TAG_ID["H4"] = 44] = "H4"; + TAG_ID[TAG_ID["H5"] = 45] = "H5"; + TAG_ID[TAG_ID["H6"] = 46] = "H6"; + TAG_ID[TAG_ID["HEAD"] = 47] = "HEAD"; + TAG_ID[TAG_ID["HEADER"] = 48] = "HEADER"; + TAG_ID[TAG_ID["HGROUP"] = 49] = "HGROUP"; + TAG_ID[TAG_ID["HR"] = 50] = "HR"; + TAG_ID[TAG_ID["HTML"] = 51] = "HTML"; + TAG_ID[TAG_ID["I"] = 52] = "I"; + TAG_ID[TAG_ID["IMG"] = 53] = "IMG"; + TAG_ID[TAG_ID["IMAGE"] = 54] = "IMAGE"; + TAG_ID[TAG_ID["INPUT"] = 55] = "INPUT"; + TAG_ID[TAG_ID["IFRAME"] = 56] = "IFRAME"; + TAG_ID[TAG_ID["KEYGEN"] = 57] = "KEYGEN"; + TAG_ID[TAG_ID["LABEL"] = 58] = "LABEL"; + TAG_ID[TAG_ID["LI"] = 59] = "LI"; + TAG_ID[TAG_ID["LINK"] = 60] = "LINK"; + TAG_ID[TAG_ID["LISTING"] = 61] = "LISTING"; + TAG_ID[TAG_ID["MAIN"] = 62] = "MAIN"; + TAG_ID[TAG_ID["MALIGNMARK"] = 63] = "MALIGNMARK"; + TAG_ID[TAG_ID["MARQUEE"] = 64] = "MARQUEE"; + TAG_ID[TAG_ID["MATH"] = 65] = "MATH"; + TAG_ID[TAG_ID["MENU"] = 66] = "MENU"; + TAG_ID[TAG_ID["META"] = 67] = "META"; + TAG_ID[TAG_ID["MGLYPH"] = 68] = "MGLYPH"; + TAG_ID[TAG_ID["MI"] = 69] = "MI"; + TAG_ID[TAG_ID["MO"] = 70] = "MO"; + TAG_ID[TAG_ID["MN"] = 71] = "MN"; + TAG_ID[TAG_ID["MS"] = 72] = "MS"; + TAG_ID[TAG_ID["MTEXT"] = 73] = "MTEXT"; + TAG_ID[TAG_ID["NAV"] = 74] = "NAV"; + TAG_ID[TAG_ID["NOBR"] = 75] = "NOBR"; + TAG_ID[TAG_ID["NOFRAMES"] = 76] = "NOFRAMES"; + TAG_ID[TAG_ID["NOEMBED"] = 77] = "NOEMBED"; + TAG_ID[TAG_ID["NOSCRIPT"] = 78] = "NOSCRIPT"; + TAG_ID[TAG_ID["OBJECT"] = 79] = "OBJECT"; + TAG_ID[TAG_ID["OL"] = 80] = "OL"; + TAG_ID[TAG_ID["OPTGROUP"] = 81] = "OPTGROUP"; + TAG_ID[TAG_ID["OPTION"] = 82] = "OPTION"; + TAG_ID[TAG_ID["P"] = 83] = "P"; + TAG_ID[TAG_ID["PARAM"] = 84] = "PARAM"; + TAG_ID[TAG_ID["PLAINTEXT"] = 85] = "PLAINTEXT"; + TAG_ID[TAG_ID["PRE"] = 86] = "PRE"; + TAG_ID[TAG_ID["RB"] = 87] = "RB"; + TAG_ID[TAG_ID["RP"] = 88] = "RP"; + TAG_ID[TAG_ID["RT"] = 89] = "RT"; + TAG_ID[TAG_ID["RTC"] = 90] = "RTC"; + TAG_ID[TAG_ID["RUBY"] = 91] = "RUBY"; + TAG_ID[TAG_ID["S"] = 92] = "S"; + TAG_ID[TAG_ID["SCRIPT"] = 93] = "SCRIPT"; + TAG_ID[TAG_ID["SECTION"] = 94] = "SECTION"; + TAG_ID[TAG_ID["SELECT"] = 95] = "SELECT"; + TAG_ID[TAG_ID["SOURCE"] = 96] = "SOURCE"; + TAG_ID[TAG_ID["SMALL"] = 97] = "SMALL"; + TAG_ID[TAG_ID["SPAN"] = 98] = "SPAN"; + TAG_ID[TAG_ID["STRIKE"] = 99] = "STRIKE"; + TAG_ID[TAG_ID["STRONG"] = 100] = "STRONG"; + TAG_ID[TAG_ID["STYLE"] = 101] = "STYLE"; + TAG_ID[TAG_ID["SUB"] = 102] = "SUB"; + TAG_ID[TAG_ID["SUMMARY"] = 103] = "SUMMARY"; + TAG_ID[TAG_ID["SUP"] = 104] = "SUP"; + TAG_ID[TAG_ID["TABLE"] = 105] = "TABLE"; + TAG_ID[TAG_ID["TBODY"] = 106] = "TBODY"; + TAG_ID[TAG_ID["TEMPLATE"] = 107] = "TEMPLATE"; + TAG_ID[TAG_ID["TEXTAREA"] = 108] = "TEXTAREA"; + TAG_ID[TAG_ID["TFOOT"] = 109] = "TFOOT"; + TAG_ID[TAG_ID["TD"] = 110] = "TD"; + TAG_ID[TAG_ID["TH"] = 111] = "TH"; + TAG_ID[TAG_ID["THEAD"] = 112] = "THEAD"; + TAG_ID[TAG_ID["TITLE"] = 113] = "TITLE"; + TAG_ID[TAG_ID["TR"] = 114] = "TR"; + TAG_ID[TAG_ID["TRACK"] = 115] = "TRACK"; + TAG_ID[TAG_ID["TT"] = 116] = "TT"; + TAG_ID[TAG_ID["U"] = 117] = "U"; + TAG_ID[TAG_ID["UL"] = 118] = "UL"; + TAG_ID[TAG_ID["SVG"] = 119] = "SVG"; + TAG_ID[TAG_ID["VAR"] = 120] = "VAR"; + TAG_ID[TAG_ID["WBR"] = 121] = "WBR"; + TAG_ID[TAG_ID["XMP"] = 122] = "XMP"; +})(TAG_ID = exports.TAG_ID || (exports.TAG_ID = {})); +const TAG_NAME_TO_ID = new Map([ + [TAG_NAMES.A, TAG_ID.A], + [TAG_NAMES.ADDRESS, TAG_ID.ADDRESS], + [TAG_NAMES.ANNOTATION_XML, TAG_ID.ANNOTATION_XML], + [TAG_NAMES.APPLET, TAG_ID.APPLET], + [TAG_NAMES.AREA, TAG_ID.AREA], + [TAG_NAMES.ARTICLE, TAG_ID.ARTICLE], + [TAG_NAMES.ASIDE, TAG_ID.ASIDE], + [TAG_NAMES.B, TAG_ID.B], + [TAG_NAMES.BASE, TAG_ID.BASE], + [TAG_NAMES.BASEFONT, TAG_ID.BASEFONT], + [TAG_NAMES.BGSOUND, TAG_ID.BGSOUND], + [TAG_NAMES.BIG, TAG_ID.BIG], + [TAG_NAMES.BLOCKQUOTE, TAG_ID.BLOCKQUOTE], + [TAG_NAMES.BODY, TAG_ID.BODY], + [TAG_NAMES.BR, TAG_ID.BR], + [TAG_NAMES.BUTTON, TAG_ID.BUTTON], + [TAG_NAMES.CAPTION, TAG_ID.CAPTION], + [TAG_NAMES.CENTER, TAG_ID.CENTER], + [TAG_NAMES.CODE, TAG_ID.CODE], + [TAG_NAMES.COL, TAG_ID.COL], + [TAG_NAMES.COLGROUP, TAG_ID.COLGROUP], + [TAG_NAMES.DD, TAG_ID.DD], + [TAG_NAMES.DESC, TAG_ID.DESC], + [TAG_NAMES.DETAILS, TAG_ID.DETAILS], + [TAG_NAMES.DIALOG, TAG_ID.DIALOG], + [TAG_NAMES.DIR, TAG_ID.DIR], + [TAG_NAMES.DIV, TAG_ID.DIV], + [TAG_NAMES.DL, TAG_ID.DL], + [TAG_NAMES.DT, TAG_ID.DT], + [TAG_NAMES.EM, TAG_ID.EM], + [TAG_NAMES.EMBED, TAG_ID.EMBED], + [TAG_NAMES.FIELDSET, TAG_ID.FIELDSET], + [TAG_NAMES.FIGCAPTION, TAG_ID.FIGCAPTION], + [TAG_NAMES.FIGURE, TAG_ID.FIGURE], + [TAG_NAMES.FONT, TAG_ID.FONT], + [TAG_NAMES.FOOTER, TAG_ID.FOOTER], + [TAG_NAMES.FOREIGN_OBJECT, TAG_ID.FOREIGN_OBJECT], + [TAG_NAMES.FORM, TAG_ID.FORM], + [TAG_NAMES.FRAME, TAG_ID.FRAME], + [TAG_NAMES.FRAMESET, TAG_ID.FRAMESET], + [TAG_NAMES.H1, TAG_ID.H1], + [TAG_NAMES.H2, TAG_ID.H2], + [TAG_NAMES.H3, TAG_ID.H3], + [TAG_NAMES.H4, TAG_ID.H4], + [TAG_NAMES.H5, TAG_ID.H5], + [TAG_NAMES.H6, TAG_ID.H6], + [TAG_NAMES.HEAD, TAG_ID.HEAD], + [TAG_NAMES.HEADER, TAG_ID.HEADER], + [TAG_NAMES.HGROUP, TAG_ID.HGROUP], + [TAG_NAMES.HR, TAG_ID.HR], + [TAG_NAMES.HTML, TAG_ID.HTML], + [TAG_NAMES.I, TAG_ID.I], + [TAG_NAMES.IMG, TAG_ID.IMG], + [TAG_NAMES.IMAGE, TAG_ID.IMAGE], + [TAG_NAMES.INPUT, TAG_ID.INPUT], + [TAG_NAMES.IFRAME, TAG_ID.IFRAME], + [TAG_NAMES.KEYGEN, TAG_ID.KEYGEN], + [TAG_NAMES.LABEL, TAG_ID.LABEL], + [TAG_NAMES.LI, TAG_ID.LI], + [TAG_NAMES.LINK, TAG_ID.LINK], + [TAG_NAMES.LISTING, TAG_ID.LISTING], + [TAG_NAMES.MAIN, TAG_ID.MAIN], + [TAG_NAMES.MALIGNMARK, TAG_ID.MALIGNMARK], + [TAG_NAMES.MARQUEE, TAG_ID.MARQUEE], + [TAG_NAMES.MATH, TAG_ID.MATH], + [TAG_NAMES.MENU, TAG_ID.MENU], + [TAG_NAMES.META, TAG_ID.META], + [TAG_NAMES.MGLYPH, TAG_ID.MGLYPH], + [TAG_NAMES.MI, TAG_ID.MI], + [TAG_NAMES.MO, TAG_ID.MO], + [TAG_NAMES.MN, TAG_ID.MN], + [TAG_NAMES.MS, TAG_ID.MS], + [TAG_NAMES.MTEXT, TAG_ID.MTEXT], + [TAG_NAMES.NAV, TAG_ID.NAV], + [TAG_NAMES.NOBR, TAG_ID.NOBR], + [TAG_NAMES.NOFRAMES, TAG_ID.NOFRAMES], + [TAG_NAMES.NOEMBED, TAG_ID.NOEMBED], + [TAG_NAMES.NOSCRIPT, TAG_ID.NOSCRIPT], + [TAG_NAMES.OBJECT, TAG_ID.OBJECT], + [TAG_NAMES.OL, TAG_ID.OL], + [TAG_NAMES.OPTGROUP, TAG_ID.OPTGROUP], + [TAG_NAMES.OPTION, TAG_ID.OPTION], + [TAG_NAMES.P, TAG_ID.P], + [TAG_NAMES.PARAM, TAG_ID.PARAM], + [TAG_NAMES.PLAINTEXT, TAG_ID.PLAINTEXT], + [TAG_NAMES.PRE, TAG_ID.PRE], + [TAG_NAMES.RB, TAG_ID.RB], + [TAG_NAMES.RP, TAG_ID.RP], + [TAG_NAMES.RT, TAG_ID.RT], + [TAG_NAMES.RTC, TAG_ID.RTC], + [TAG_NAMES.RUBY, TAG_ID.RUBY], + [TAG_NAMES.S, TAG_ID.S], + [TAG_NAMES.SCRIPT, TAG_ID.SCRIPT], + [TAG_NAMES.SECTION, TAG_ID.SECTION], + [TAG_NAMES.SELECT, TAG_ID.SELECT], + [TAG_NAMES.SOURCE, TAG_ID.SOURCE], + [TAG_NAMES.SMALL, TAG_ID.SMALL], + [TAG_NAMES.SPAN, TAG_ID.SPAN], + [TAG_NAMES.STRIKE, TAG_ID.STRIKE], + [TAG_NAMES.STRONG, TAG_ID.STRONG], + [TAG_NAMES.STYLE, TAG_ID.STYLE], + [TAG_NAMES.SUB, TAG_ID.SUB], + [TAG_NAMES.SUMMARY, TAG_ID.SUMMARY], + [TAG_NAMES.SUP, TAG_ID.SUP], + [TAG_NAMES.TABLE, TAG_ID.TABLE], + [TAG_NAMES.TBODY, TAG_ID.TBODY], + [TAG_NAMES.TEMPLATE, TAG_ID.TEMPLATE], + [TAG_NAMES.TEXTAREA, TAG_ID.TEXTAREA], + [TAG_NAMES.TFOOT, TAG_ID.TFOOT], + [TAG_NAMES.TD, TAG_ID.TD], + [TAG_NAMES.TH, TAG_ID.TH], + [TAG_NAMES.THEAD, TAG_ID.THEAD], + [TAG_NAMES.TITLE, TAG_ID.TITLE], + [TAG_NAMES.TR, TAG_ID.TR], + [TAG_NAMES.TRACK, TAG_ID.TRACK], + [TAG_NAMES.TT, TAG_ID.TT], + [TAG_NAMES.U, TAG_ID.U], + [TAG_NAMES.UL, TAG_ID.UL], + [TAG_NAMES.SVG, TAG_ID.SVG], + [TAG_NAMES.VAR, TAG_ID.VAR], + [TAG_NAMES.WBR, TAG_ID.WBR], + [TAG_NAMES.XMP, TAG_ID.XMP], +]); +function getTagID(tagName) { + var _a; + return (_a = TAG_NAME_TO_ID.get(tagName)) !== null && _a !== void 0 ? _a : TAG_ID.UNKNOWN; } - -exports.isIntegrationPoint = function(tn, ns, attrs, foreignNS) { - if ((!foreignNS || foreignNS === NS.HTML) && isHtmlIntegrationPoint(tn, ns, attrs)) { - return true; - } - - if ((!foreignNS || foreignNS === NS.MATHML) && isMathMLTextIntegrationPoint(tn, ns)) { - return true; - } - - return false; -}; - -},{"../tokenizer":19,"./html":4}],4:[function(require,module,exports){ -'use strict'; - -const NS = (exports.NAMESPACES = { - HTML: 'http://www.w3.org/1999/xhtml', - MATHML: 'http://www.w3.org/1998/Math/MathML', - SVG: 'http://www.w3.org/2000/svg', - XLINK: 'http://www.w3.org/1999/xlink', - XML: 'http://www.w3.org/XML/1998/namespace', - XMLNS: 'http://www.w3.org/2000/xmlns/' -}); - -exports.ATTRS = { - TYPE: 'type', - ACTION: 'action', - ENCODING: 'encoding', - PROMPT: 'prompt', - NAME: 'name', - COLOR: 'color', - FACE: 'face', - SIZE: 'size' -}; - -exports.DOCUMENT_MODE = { - NO_QUIRKS: 'no-quirks', - QUIRKS: 'quirks', - LIMITED_QUIRKS: 'limited-quirks' -}; - -const $ = (exports.TAG_NAMES = { - A: 'a', - ADDRESS: 'address', - ANNOTATION_XML: 'annotation-xml', - APPLET: 'applet', - AREA: 'area', - ARTICLE: 'article', - ASIDE: 'aside', - - B: 'b', - BASE: 'base', - BASEFONT: 'basefont', - BGSOUND: 'bgsound', - BIG: 'big', - BLOCKQUOTE: 'blockquote', - BODY: 'body', - BR: 'br', - BUTTON: 'button', - - CAPTION: 'caption', - CENTER: 'center', - CODE: 'code', - COL: 'col', - COLGROUP: 'colgroup', - - DD: 'dd', - DESC: 'desc', - DETAILS: 'details', - DIALOG: 'dialog', - DIR: 'dir', - DIV: 'div', - DL: 'dl', - DT: 'dt', - - EM: 'em', - EMBED: 'embed', - - FIELDSET: 'fieldset', - FIGCAPTION: 'figcaption', - FIGURE: 'figure', - FONT: 'font', - FOOTER: 'footer', - FOREIGN_OBJECT: 'foreignObject', - FORM: 'form', - FRAME: 'frame', - FRAMESET: 'frameset', - - H1: 'h1', - H2: 'h2', - H3: 'h3', - H4: 'h4', - H5: 'h5', - H6: 'h6', - HEAD: 'head', - HEADER: 'header', - HGROUP: 'hgroup', - HR: 'hr', - HTML: 'html', - - I: 'i', - IMG: 'img', - IMAGE: 'image', - INPUT: 'input', - IFRAME: 'iframe', - - KEYGEN: 'keygen', - - LABEL: 'label', - LI: 'li', - LINK: 'link', - LISTING: 'listing', - - MAIN: 'main', - MALIGNMARK: 'malignmark', - MARQUEE: 'marquee', - MATH: 'math', - MENU: 'menu', - META: 'meta', - MGLYPH: 'mglyph', - MI: 'mi', - MO: 'mo', - MN: 'mn', - MS: 'ms', - MTEXT: 'mtext', - - NAV: 'nav', - NOBR: 'nobr', - NOFRAMES: 'noframes', - NOEMBED: 'noembed', - NOSCRIPT: 'noscript', - - OBJECT: 'object', - OL: 'ol', - OPTGROUP: 'optgroup', - OPTION: 'option', - - P: 'p', - PARAM: 'param', - PLAINTEXT: 'plaintext', - PRE: 'pre', - - RB: 'rb', - RP: 'rp', - RT: 'rt', - RTC: 'rtc', - RUBY: 'ruby', - - S: 's', - SCRIPT: 'script', - SECTION: 'section', - SELECT: 'select', - SOURCE: 'source', - SMALL: 'small', - SPAN: 'span', - STRIKE: 'strike', - STRONG: 'strong', - STYLE: 'style', - SUB: 'sub', - SUMMARY: 'summary', - SUP: 'sup', - - TABLE: 'table', - TBODY: 'tbody', - TEMPLATE: 'template', - TEXTAREA: 'textarea', - TFOOT: 'tfoot', - TD: 'td', - TH: 'th', - THEAD: 'thead', - TITLE: 'title', - TR: 'tr', - TRACK: 'track', - TT: 'tt', - - U: 'u', - UL: 'ul', - - SVG: 'svg', - - VAR: 'var', - - WBR: 'wbr', - - XMP: 'xmp' -}); - +exports.getTagID = getTagID; +const $ = TAG_ID; exports.SPECIAL_ELEMENTS = { - [NS.HTML]: { - [$.ADDRESS]: true, - [$.APPLET]: true, - [$.AREA]: true, - [$.ARTICLE]: true, - [$.ASIDE]: true, - [$.BASE]: true, - [$.BASEFONT]: true, - [$.BGSOUND]: true, - [$.BLOCKQUOTE]: true, - [$.BODY]: true, - [$.BR]: true, - [$.BUTTON]: true, - [$.CAPTION]: true, - [$.CENTER]: true, - [$.COL]: true, - [$.COLGROUP]: true, - [$.DD]: true, - [$.DETAILS]: true, - [$.DIR]: true, - [$.DIV]: true, - [$.DL]: true, - [$.DT]: true, - [$.EMBED]: true, - [$.FIELDSET]: true, - [$.FIGCAPTION]: true, - [$.FIGURE]: true, - [$.FOOTER]: true, - [$.FORM]: true, - [$.FRAME]: true, - [$.FRAMESET]: true, - [$.H1]: true, - [$.H2]: true, - [$.H3]: true, - [$.H4]: true, - [$.H5]: true, - [$.H6]: true, - [$.HEAD]: true, - [$.HEADER]: true, - [$.HGROUP]: true, - [$.HR]: true, - [$.HTML]: true, - [$.IFRAME]: true, - [$.IMG]: true, - [$.INPUT]: true, - [$.LI]: true, - [$.LINK]: true, - [$.LISTING]: true, - [$.MAIN]: true, - [$.MARQUEE]: true, - [$.MENU]: true, - [$.META]: true, - [$.NAV]: true, - [$.NOEMBED]: true, - [$.NOFRAMES]: true, - [$.NOSCRIPT]: true, - [$.OBJECT]: true, - [$.OL]: true, - [$.P]: true, - [$.PARAM]: true, - [$.PLAINTEXT]: true, - [$.PRE]: true, - [$.SCRIPT]: true, - [$.SECTION]: true, - [$.SELECT]: true, - [$.SOURCE]: true, - [$.STYLE]: true, - [$.SUMMARY]: true, - [$.TABLE]: true, - [$.TBODY]: true, - [$.TD]: true, - [$.TEMPLATE]: true, - [$.TEXTAREA]: true, - [$.TFOOT]: true, - [$.TH]: true, - [$.THEAD]: true, - [$.TITLE]: true, - [$.TR]: true, - [$.TRACK]: true, - [$.UL]: true, - [$.WBR]: true, - [$.XMP]: true - }, - [NS.MATHML]: { - [$.MI]: true, - [$.MO]: true, - [$.MN]: true, - [$.MS]: true, - [$.MTEXT]: true, - [$.ANNOTATION_XML]: true - }, - [NS.SVG]: { - [$.TITLE]: true, - [$.FOREIGN_OBJECT]: true, - [$.DESC]: true - } + [NS.HTML]: new Set([ + $.ADDRESS, + $.APPLET, + $.AREA, + $.ARTICLE, + $.ASIDE, + $.BASE, + $.BASEFONT, + $.BGSOUND, + $.BLOCKQUOTE, + $.BODY, + $.BR, + $.BUTTON, + $.CAPTION, + $.CENTER, + $.COL, + $.COLGROUP, + $.DD, + $.DETAILS, + $.DIR, + $.DIV, + $.DL, + $.DT, + $.EMBED, + $.FIELDSET, + $.FIGCAPTION, + $.FIGURE, + $.FOOTER, + $.FORM, + $.FRAME, + $.FRAMESET, + $.H1, + $.H2, + $.H3, + $.H4, + $.H5, + $.H6, + $.HEAD, + $.HEADER, + $.HGROUP, + $.HR, + $.HTML, + $.IFRAME, + $.IMG, + $.INPUT, + $.LI, + $.LINK, + $.LISTING, + $.MAIN, + $.MARQUEE, + $.MENU, + $.META, + $.NAV, + $.NOEMBED, + $.NOFRAMES, + $.NOSCRIPT, + $.OBJECT, + $.OL, + $.P, + $.PARAM, + $.PLAINTEXT, + $.PRE, + $.SCRIPT, + $.SECTION, + $.SELECT, + $.SOURCE, + $.STYLE, + $.SUMMARY, + $.TABLE, + $.TBODY, + $.TD, + $.TEMPLATE, + $.TEXTAREA, + $.TFOOT, + $.TH, + $.THEAD, + $.TITLE, + $.TR, + $.TRACK, + $.UL, + $.WBR, + $.XMP, + ]), + [NS.MATHML]: new Set([$.MI, $.MO, $.MN, $.MS, $.MTEXT, $.ANNOTATION_XML]), + [NS.SVG]: new Set([$.TITLE, $.FOREIGN_OBJECT, $.DESC]), + [NS.XLINK]: new Set(), + [NS.XML]: new Set(), + [NS.XMLNS]: new Set(), }; +function isNumberedHeader(tn) { + return tn === $.H1 || tn === $.H2 || tn === $.H3 || tn === $.H4 || tn === $.H5 || tn === $.H6; +} +exports.isNumberedHeader = isNumberedHeader; +const UNESCAPED_TEXT = new Set([ + TAG_NAMES.STYLE, + TAG_NAMES.SCRIPT, + TAG_NAMES.XMP, + TAG_NAMES.IFRAME, + TAG_NAMES.NOEMBED, + TAG_NAMES.NOFRAMES, + TAG_NAMES.PLAINTEXT, +]); +function hasUnescapedText(tn, scriptingEnabled) { + return UNESCAPED_TEXT.has(tn) || (scriptingEnabled && tn === TAG_NAMES.NOSCRIPT); +} +exports.hasUnescapedText = hasUnescapedText; },{}],5:[function(require,module,exports){ -'use strict'; - -const UNDEFINED_CODE_POINTS = [ - 0xfffe, - 0xffff, - 0x1fffe, - 0x1ffff, - 0x2fffe, - 0x2ffff, - 0x3fffe, - 0x3ffff, - 0x4fffe, - 0x4ffff, - 0x5fffe, - 0x5ffff, - 0x6fffe, - 0x6ffff, - 0x7fffe, - 0x7ffff, - 0x8fffe, - 0x8ffff, - 0x9fffe, - 0x9ffff, - 0xafffe, - 0xaffff, - 0xbfffe, - 0xbffff, - 0xcfffe, - 0xcffff, - 0xdfffe, - 0xdffff, - 0xefffe, - 0xeffff, - 0xffffe, - 0xfffff, - 0x10fffe, - 0x10ffff -]; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getTokenAttr = exports.TokenType = void 0; +var TokenType; +(function (TokenType) { + TokenType[TokenType["CHARACTER"] = 0] = "CHARACTER"; + TokenType[TokenType["NULL_CHARACTER"] = 1] = "NULL_CHARACTER"; + TokenType[TokenType["WHITESPACE_CHARACTER"] = 2] = "WHITESPACE_CHARACTER"; + TokenType[TokenType["START_TAG"] = 3] = "START_TAG"; + TokenType[TokenType["END_TAG"] = 4] = "END_TAG"; + TokenType[TokenType["COMMENT"] = 5] = "COMMENT"; + TokenType[TokenType["DOCTYPE"] = 6] = "DOCTYPE"; + TokenType[TokenType["EOF"] = 7] = "EOF"; + TokenType[TokenType["HIBERNATION"] = 8] = "HIBERNATION"; +})(TokenType = exports.TokenType || (exports.TokenType = {})); +function getTokenAttr(token, attrName) { + for (let i = token.attrs.length - 1; i >= 0; i--) { + if (token.attrs[i].name === attrName) { + return token.attrs[i].value; + } + } + return null; +} +exports.getTokenAttr = getTokenAttr; +},{}],6:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isUndefinedCodePoint = exports.isControlCodePoint = exports.getSurrogatePairCodePoint = exports.isSurrogatePair = exports.isSurrogate = exports.SEQUENCES = exports.CODE_POINTS = exports.REPLACEMENT_CHARACTER = void 0; +const UNDEFINED_CODE_POINTS = new Set([ + 65534, 65535, 131070, 131071, 196606, 196607, 262142, 262143, 327678, 327679, 393214, + 393215, 458750, 458751, 524286, 524287, 589822, 589823, 655358, 655359, 720894, + 720895, 786430, 786431, 851966, 851967, 917502, 917503, 983038, 983039, 1048574, + 1048575, 1114110, 1114111, +]); exports.REPLACEMENT_CHARACTER = '\uFFFD'; - -exports.CODE_POINTS = { - EOF: -1, - NULL: 0x00, - TABULATION: 0x09, - CARRIAGE_RETURN: 0x0d, - LINE_FEED: 0x0a, - FORM_FEED: 0x0c, - SPACE: 0x20, - EXCLAMATION_MARK: 0x21, - QUOTATION_MARK: 0x22, - NUMBER_SIGN: 0x23, - AMPERSAND: 0x26, - APOSTROPHE: 0x27, - HYPHEN_MINUS: 0x2d, - SOLIDUS: 0x2f, - DIGIT_0: 0x30, - DIGIT_9: 0x39, - SEMICOLON: 0x3b, - LESS_THAN_SIGN: 0x3c, - EQUALS_SIGN: 0x3d, - GREATER_THAN_SIGN: 0x3e, - QUESTION_MARK: 0x3f, - LATIN_CAPITAL_A: 0x41, - LATIN_CAPITAL_F: 0x46, - LATIN_CAPITAL_X: 0x58, - LATIN_CAPITAL_Z: 0x5a, - RIGHT_SQUARE_BRACKET: 0x5d, - GRAVE_ACCENT: 0x60, - LATIN_SMALL_A: 0x61, - LATIN_SMALL_F: 0x66, - LATIN_SMALL_X: 0x78, - LATIN_SMALL_Z: 0x7a, - REPLACEMENT_CHARACTER: 0xfffd -}; - -exports.CODE_POINT_SEQUENCES = { - DASH_DASH_STRING: [0x2d, 0x2d], //-- - DOCTYPE_STRING: [0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45], //DOCTYPE - CDATA_START_STRING: [0x5b, 0x43, 0x44, 0x41, 0x54, 0x41, 0x5b], //[CDATA[ - SCRIPT_STRING: [0x73, 0x63, 0x72, 0x69, 0x70, 0x74], //script - PUBLIC_STRING: [0x50, 0x55, 0x42, 0x4c, 0x49, 0x43], //PUBLIC - SYSTEM_STRING: [0x53, 0x59, 0x53, 0x54, 0x45, 0x4d] //SYSTEM +var CODE_POINTS; +(function (CODE_POINTS) { + CODE_POINTS[CODE_POINTS["EOF"] = -1] = "EOF"; + CODE_POINTS[CODE_POINTS["NULL"] = 0] = "NULL"; + CODE_POINTS[CODE_POINTS["TABULATION"] = 9] = "TABULATION"; + CODE_POINTS[CODE_POINTS["CARRIAGE_RETURN"] = 13] = "CARRIAGE_RETURN"; + CODE_POINTS[CODE_POINTS["LINE_FEED"] = 10] = "LINE_FEED"; + CODE_POINTS[CODE_POINTS["FORM_FEED"] = 12] = "FORM_FEED"; + CODE_POINTS[CODE_POINTS["SPACE"] = 32] = "SPACE"; + CODE_POINTS[CODE_POINTS["EXCLAMATION_MARK"] = 33] = "EXCLAMATION_MARK"; + CODE_POINTS[CODE_POINTS["QUOTATION_MARK"] = 34] = "QUOTATION_MARK"; + CODE_POINTS[CODE_POINTS["NUMBER_SIGN"] = 35] = "NUMBER_SIGN"; + CODE_POINTS[CODE_POINTS["AMPERSAND"] = 38] = "AMPERSAND"; + CODE_POINTS[CODE_POINTS["APOSTROPHE"] = 39] = "APOSTROPHE"; + CODE_POINTS[CODE_POINTS["HYPHEN_MINUS"] = 45] = "HYPHEN_MINUS"; + CODE_POINTS[CODE_POINTS["SOLIDUS"] = 47] = "SOLIDUS"; + CODE_POINTS[CODE_POINTS["DIGIT_0"] = 48] = "DIGIT_0"; + CODE_POINTS[CODE_POINTS["DIGIT_9"] = 57] = "DIGIT_9"; + CODE_POINTS[CODE_POINTS["SEMICOLON"] = 59] = "SEMICOLON"; + CODE_POINTS[CODE_POINTS["LESS_THAN_SIGN"] = 60] = "LESS_THAN_SIGN"; + CODE_POINTS[CODE_POINTS["EQUALS_SIGN"] = 61] = "EQUALS_SIGN"; + CODE_POINTS[CODE_POINTS["GREATER_THAN_SIGN"] = 62] = "GREATER_THAN_SIGN"; + CODE_POINTS[CODE_POINTS["QUESTION_MARK"] = 63] = "QUESTION_MARK"; + CODE_POINTS[CODE_POINTS["LATIN_CAPITAL_A"] = 65] = "LATIN_CAPITAL_A"; + CODE_POINTS[CODE_POINTS["LATIN_CAPITAL_F"] = 70] = "LATIN_CAPITAL_F"; + CODE_POINTS[CODE_POINTS["LATIN_CAPITAL_X"] = 88] = "LATIN_CAPITAL_X"; + CODE_POINTS[CODE_POINTS["LATIN_CAPITAL_Z"] = 90] = "LATIN_CAPITAL_Z"; + CODE_POINTS[CODE_POINTS["RIGHT_SQUARE_BRACKET"] = 93] = "RIGHT_SQUARE_BRACKET"; + CODE_POINTS[CODE_POINTS["GRAVE_ACCENT"] = 96] = "GRAVE_ACCENT"; + CODE_POINTS[CODE_POINTS["LATIN_SMALL_A"] = 97] = "LATIN_SMALL_A"; + CODE_POINTS[CODE_POINTS["LATIN_SMALL_F"] = 102] = "LATIN_SMALL_F"; + CODE_POINTS[CODE_POINTS["LATIN_SMALL_X"] = 120] = "LATIN_SMALL_X"; + CODE_POINTS[CODE_POINTS["LATIN_SMALL_Z"] = 122] = "LATIN_SMALL_Z"; + CODE_POINTS[CODE_POINTS["REPLACEMENT_CHARACTER"] = 65533] = "REPLACEMENT_CHARACTER"; +})(CODE_POINTS = exports.CODE_POINTS || (exports.CODE_POINTS = {})); +exports.SEQUENCES = { + DASH_DASH: '--', + CDATA_START: '[CDATA[', + DOCTYPE: 'doctype', + SCRIPT: 'script', + PUBLIC: 'public', + SYSTEM: 'system', }; - //Surrogates -exports.isSurrogate = function(cp) { - return cp >= 0xd800 && cp <= 0xdfff; -}; - -exports.isSurrogatePair = function(cp) { - return cp >= 0xdc00 && cp <= 0xdfff; -}; - -exports.getSurrogatePairCodePoint = function(cp1, cp2) { - return (cp1 - 0xd800) * 0x400 + 0x2400 + cp2; -}; - +function isSurrogate(cp) { + return cp >= 55296 && cp <= 57343; +} +exports.isSurrogate = isSurrogate; +function isSurrogatePair(cp) { + return cp >= 56320 && cp <= 57343; +} +exports.isSurrogatePair = isSurrogatePair; +function getSurrogatePairCodePoint(cp1, cp2) { + return (cp1 - 55296) * 1024 + 9216 + cp2; +} +exports.getSurrogatePairCodePoint = getSurrogatePairCodePoint; //NOTE: excluding NULL and ASCII whitespace -exports.isControlCodePoint = function(cp) { - return ( - (cp !== 0x20 && cp !== 0x0a && cp !== 0x0d && cp !== 0x09 && cp !== 0x0c && cp >= 0x01 && cp <= 0x1f) || - (cp >= 0x7f && cp <= 0x9f) - ); -}; - -exports.isUndefinedCodePoint = function(cp) { - return (cp >= 0xfdd0 && cp <= 0xfdef) || UNDEFINED_CODE_POINTS.indexOf(cp) > -1; -}; - -},{}],6:[function(require,module,exports){ -'use strict'; - -const Mixin = require('../../utils/mixin'); - -class ErrorReportingMixinBase extends Mixin { - constructor(host, opts) { - super(host); - - this.posTracker = null; - this.onParseError = opts.onParseError; - } - - _setErrorLocation(err) { - err.startLine = err.endLine = this.posTracker.line; - err.startCol = err.endCol = this.posTracker.col; - err.startOffset = err.endOffset = this.posTracker.offset; - } - - _reportError(code) { - const err = { - code: code, - startLine: -1, - startCol: -1, - startOffset: -1, - endLine: -1, - endCol: -1, - endOffset: -1 - }; - - this._setErrorLocation(err); - this.onParseError(err); - } - - _getOverriddenMethods(mxn) { - return { - _err(code) { - mxn._reportError(code); - } - }; +function isControlCodePoint(cp) { + return ((cp !== 0x20 && cp !== 0x0a && cp !== 0x0d && cp !== 0x09 && cp !== 0x0c && cp >= 0x01 && cp <= 0x1f) || + (cp >= 0x7f && cp <= 0x9f)); +} +exports.isControlCodePoint = isControlCodePoint; +function isUndefinedCodePoint(cp) { + return (cp >= 64976 && cp <= 65007) || UNDEFINED_CODE_POINTS.has(cp); +} +exports.isUndefinedCodePoint = isUndefinedCodePoint; + +},{}],7:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.parseFragment = exports.parse = exports.TokenizerMode = exports.Tokenizer = exports.Token = exports.html = exports.foreignContent = exports.serializeOuter = exports.serialize = exports.Parser = exports.defaultTreeAdapter = void 0; +const index_js_1 = require("./parser/index.js"); +var default_js_1 = require("./tree-adapters/default.js"); +Object.defineProperty(exports, "defaultTreeAdapter", { enumerable: true, get: function () { return default_js_1.defaultTreeAdapter; } }); +var index_js_2 = require("./parser/index.js"); +Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return index_js_2.Parser; } }); +var index_js_3 = require("./serializer/index.js"); +Object.defineProperty(exports, "serialize", { enumerable: true, get: function () { return index_js_3.serialize; } }); +Object.defineProperty(exports, "serializeOuter", { enumerable: true, get: function () { return index_js_3.serializeOuter; } }); +/** @internal */ +exports.foreignContent = require("./common/foreign-content.js"); +/** @internal */ +exports.html = require("./common/html.js"); +/** @internal */ +exports.Token = require("./common/token.js"); +/** @internal */ +var index_js_4 = require("./tokenizer/index.js"); +Object.defineProperty(exports, "Tokenizer", { enumerable: true, get: function () { return index_js_4.Tokenizer; } }); +Object.defineProperty(exports, "TokenizerMode", { enumerable: true, get: function () { return index_js_4.TokenizerMode; } }); +// Shorthands +/** + * Parses an HTML string. + * + * @param html Input HTML string. + * @param options Parsing options. + * @returns Document + * + * @example + * + * ```js + * const parse5 = require('parse5'); + * + * const document = parse5.parse('Hi there!'); + * + * console.log(document.childNodes[1].tagName); //> 'html' + *``` + */ +function parse(html, options) { + return index_js_1.Parser.parse(html, options); +} +exports.parse = parse; +function parseFragment(fragmentContext, html, options) { + if (typeof fragmentContext === 'string') { + options = html; + html = fragmentContext; + fragmentContext = null; } + const parser = index_js_1.Parser.getFragmentParser(fragmentContext, options); + parser.tokenizer.write(html, true); + return parser.getFragment(); } +exports.parseFragment = parseFragment; -module.exports = ErrorReportingMixinBase; - -},{"../../utils/mixin":24}],7:[function(require,module,exports){ -'use strict'; - -const ErrorReportingMixinBase = require('./mixin-base'); -const ErrorReportingTokenizerMixin = require('./tokenizer-mixin'); -const LocationInfoTokenizerMixin = require('../location-info/tokenizer-mixin'); -const Mixin = require('../../utils/mixin'); - -class ErrorReportingParserMixin extends ErrorReportingMixinBase { - constructor(parser, opts) { - super(parser, opts); - - this.opts = opts; - this.ctLoc = null; - this.locBeforeToken = false; +},{"./common/foreign-content.js":3,"./common/html.js":4,"./common/token.js":5,"./parser/index.js":9,"./serializer/index.js":11,"./tokenizer/index.js":12,"./tree-adapters/default.js":14}],8:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.FormattingElementList = exports.EntryType = void 0; +//Const +const NOAH_ARK_CAPACITY = 3; +var EntryType; +(function (EntryType) { + EntryType[EntryType["Marker"] = 0] = "Marker"; + EntryType[EntryType["Element"] = 1] = "Element"; +})(EntryType = exports.EntryType || (exports.EntryType = {})); +const MARKER = { type: EntryType.Marker }; +//List of formatting elements +class FormattingElementList { + constructor(treeAdapter) { + this.treeAdapter = treeAdapter; + this.entries = []; + this.bookmark = null; } - - _setErrorLocation(err) { - if (this.ctLoc) { - err.startLine = this.ctLoc.startLine; - err.startCol = this.ctLoc.startCol; - err.startOffset = this.ctLoc.startOffset; - - err.endLine = this.locBeforeToken ? this.ctLoc.startLine : this.ctLoc.endLine; - err.endCol = this.locBeforeToken ? this.ctLoc.startCol : this.ctLoc.endCol; - err.endOffset = this.locBeforeToken ? this.ctLoc.startOffset : this.ctLoc.endOffset; + //Noah Ark's condition + //OPTIMIZATION: at first we try to find possible candidates for exclusion using + //lightweight heuristics without thorough attributes check. + _getNoahArkConditionCandidates(newElement, neAttrs) { + const candidates = []; + const neAttrsLength = neAttrs.length; + const neTagName = this.treeAdapter.getTagName(newElement); + const neNamespaceURI = this.treeAdapter.getNamespaceURI(newElement); + for (let i = 0; i < this.entries.length; i++) { + const entry = this.entries[i]; + if (entry.type === EntryType.Marker) { + break; + } + const { element } = entry; + if (this.treeAdapter.getTagName(element) === neTagName && + this.treeAdapter.getNamespaceURI(element) === neNamespaceURI) { + const elementAttrs = this.treeAdapter.getAttrList(element); + if (elementAttrs.length === neAttrsLength) { + candidates.push({ idx: i, attrs: elementAttrs }); + } + } } + return candidates; } - - _getOverriddenMethods(mxn, orig) { - return { - _bootstrap(document, fragmentContext) { - orig._bootstrap.call(this, document, fragmentContext); - - Mixin.install(this.tokenizer, ErrorReportingTokenizerMixin, mxn.opts); - Mixin.install(this.tokenizer, LocationInfoTokenizerMixin); - }, - - _processInputToken(token) { - mxn.ctLoc = token.location; - - orig._processInputToken.call(this, token); - }, - - _err(code, options) { - mxn.locBeforeToken = options && options.beforeToken; - mxn._reportError(code); + _ensureNoahArkCondition(newElement) { + if (this.entries.length < NOAH_ARK_CAPACITY) + return; + const neAttrs = this.treeAdapter.getAttrList(newElement); + const candidates = this._getNoahArkConditionCandidates(newElement, neAttrs); + if (candidates.length < NOAH_ARK_CAPACITY) + return; + //NOTE: build attrs map for the new element, so we can perform fast lookups + const neAttrsMap = new Map(neAttrs.map((neAttr) => [neAttr.name, neAttr.value])); + let validCandidates = 0; + //NOTE: remove bottommost candidates, until Noah's Ark condition will not be met + for (let i = 0; i < candidates.length; i++) { + const candidate = candidates[i]; + // We know that `candidate.attrs.length === neAttrs.length` + if (candidate.attrs.every((cAttr) => neAttrsMap.get(cAttr.name) === cAttr.value)) { + validCandidates += 1; + if (validCandidates >= NOAH_ARK_CAPACITY) { + this.entries.splice(candidate.idx, 1); + } } - }; + } } -} - -module.exports = ErrorReportingParserMixin; - -},{"../../utils/mixin":24,"../location-info/tokenizer-mixin":12,"./mixin-base":6,"./tokenizer-mixin":9}],8:[function(require,module,exports){ -'use strict'; - -const ErrorReportingMixinBase = require('./mixin-base'); -const PositionTrackingPreprocessorMixin = require('../position-tracking/preprocessor-mixin'); -const Mixin = require('../../utils/mixin'); - -class ErrorReportingPreprocessorMixin extends ErrorReportingMixinBase { - constructor(preprocessor, opts) { - super(preprocessor, opts); - - this.posTracker = Mixin.install(preprocessor, PositionTrackingPreprocessorMixin); - this.lastErrOffset = -1; + //Mutations + insertMarker() { + this.entries.unshift(MARKER); } - - _reportError(code) { - //NOTE: avoid reporting error twice on advance/retreat - if (this.lastErrOffset !== this.posTracker.offset) { - this.lastErrOffset = this.posTracker.offset; - super._reportError(code); + pushElement(element, token) { + this._ensureNoahArkCondition(element); + this.entries.unshift({ + type: EntryType.Element, + element, + token, + }); + } + insertElementAfterBookmark(element, token) { + const bookmarkIdx = this.entries.indexOf(this.bookmark); + this.entries.splice(bookmarkIdx, 0, { + type: EntryType.Element, + element, + token, + }); + } + removeEntry(entry) { + const entryIndex = this.entries.indexOf(entry); + if (entryIndex >= 0) { + this.entries.splice(entryIndex, 1); } } -} - -module.exports = ErrorReportingPreprocessorMixin; - -},{"../../utils/mixin":24,"../position-tracking/preprocessor-mixin":13,"./mixin-base":6}],9:[function(require,module,exports){ -'use strict'; - -const ErrorReportingMixinBase = require('./mixin-base'); -const ErrorReportingPreprocessorMixin = require('./preprocessor-mixin'); -const Mixin = require('../../utils/mixin'); - -class ErrorReportingTokenizerMixin extends ErrorReportingMixinBase { - constructor(tokenizer, opts) { - super(tokenizer, opts); - - const preprocessorMixin = Mixin.install(tokenizer.preprocessor, ErrorReportingPreprocessorMixin, opts); - - this.posTracker = preprocessorMixin.posTracker; + clearToLastMarker() { + const markerIdx = this.entries.indexOf(MARKER); + if (markerIdx >= 0) { + this.entries.splice(0, markerIdx + 1); + } + else { + this.entries.length = 0; + } } -} - -module.exports = ErrorReportingTokenizerMixin; - -},{"../../utils/mixin":24,"./mixin-base":6,"./preprocessor-mixin":8}],10:[function(require,module,exports){ -'use strict'; - -const Mixin = require('../../utils/mixin'); - -class LocationInfoOpenElementStackMixin extends Mixin { - constructor(stack, opts) { - super(stack); - - this.onItemPop = opts.onItemPop; + //Search + getElementEntryInScopeWithTagName(tagName) { + const entry = this.entries.find((entry) => entry.type === EntryType.Marker || this.treeAdapter.getTagName(entry.element) === tagName); + return entry && entry.type === EntryType.Element ? entry : null; } - - _getOverriddenMethods(mxn, orig) { - return { - pop() { - mxn.onItemPop(this.current); - orig.pop.call(this); - }, - - popAllUpToHtmlElement() { - for (let i = this.stackTop; i > 0; i--) { - mxn.onItemPop(this.items[i]); - } - - orig.popAllUpToHtmlElement.call(this); - }, - - remove(element) { - mxn.onItemPop(this.current); - orig.remove.call(this, element); - } - }; - } -} - -module.exports = LocationInfoOpenElementStackMixin; - -},{"../../utils/mixin":24}],11:[function(require,module,exports){ -'use strict'; - -const Mixin = require('../../utils/mixin'); -const Tokenizer = require('../../tokenizer'); -const LocationInfoTokenizerMixin = require('./tokenizer-mixin'); -const LocationInfoOpenElementStackMixin = require('./open-element-stack-mixin'); -const HTML = require('../../common/html'); - -//Aliases -const $ = HTML.TAG_NAMES; - -class LocationInfoParserMixin extends Mixin { - constructor(parser) { - super(parser); - - this.parser = parser; - this.treeAdapter = this.parser.treeAdapter; - this.posTracker = null; - this.lastStartTagToken = null; - this.lastFosterParentingLocation = null; - this.currentToken = null; - } - - _setStartLocation(element) { - let loc = null; - - if (this.lastStartTagToken) { - loc = Object.assign({}, this.lastStartTagToken.location); - loc.startTag = this.lastStartTagToken.location; - } - - this.treeAdapter.setNodeSourceCodeLocation(element, loc); - } - - _setEndLocation(element, closingToken) { - const loc = this.treeAdapter.getNodeSourceCodeLocation(element); - - if (loc) { - if (closingToken.location) { - const ctLoc = closingToken.location; - const tn = this.treeAdapter.getTagName(element); - - // NOTE: For cases like

- First 'p' closes without a closing - // tag and for cases like

- 'p' closes without a closing tag. - const isClosingEndTag = closingToken.type === Tokenizer.END_TAG_TOKEN && tn === closingToken.tagName; - const endLoc = {}; - if (isClosingEndTag) { - endLoc.endTag = Object.assign({}, ctLoc); - endLoc.endLine = ctLoc.endLine; - endLoc.endCol = ctLoc.endCol; - endLoc.endOffset = ctLoc.endOffset; - } else { - endLoc.endLine = ctLoc.startLine; - endLoc.endCol = ctLoc.startCol; - endLoc.endOffset = ctLoc.startOffset; - } - - this.treeAdapter.updateNodeSourceCodeLocation(element, endLoc); - } - } - } - - _getOverriddenMethods(mxn, orig) { - return { - _bootstrap(document, fragmentContext) { - orig._bootstrap.call(this, document, fragmentContext); - - mxn.lastStartTagToken = null; - mxn.lastFosterParentingLocation = null; - mxn.currentToken = null; - - const tokenizerMixin = Mixin.install(this.tokenizer, LocationInfoTokenizerMixin); - - mxn.posTracker = tokenizerMixin.posTracker; - - Mixin.install(this.openElements, LocationInfoOpenElementStackMixin, { - onItemPop: function(element) { - mxn._setEndLocation(element, mxn.currentToken); - } - }); - }, - - _runParsingLoop(scriptHandler) { - orig._runParsingLoop.call(this, scriptHandler); - - // NOTE: generate location info for elements - // that remains on open element stack - for (let i = this.openElements.stackTop; i >= 0; i--) { - mxn._setEndLocation(this.openElements.items[i], mxn.currentToken); - } - }, - - //Token processing - _processTokenInForeignContent(token) { - mxn.currentToken = token; - orig._processTokenInForeignContent.call(this, token); - }, - - _processToken(token) { - mxn.currentToken = token; - orig._processToken.call(this, token); - - //NOTE: and are never popped from the stack, so we need to updated - //their end location explicitly. - const requireExplicitUpdate = - token.type === Tokenizer.END_TAG_TOKEN && - (token.tagName === $.HTML || (token.tagName === $.BODY && this.openElements.hasInScope($.BODY))); - - if (requireExplicitUpdate) { - for (let i = this.openElements.stackTop; i >= 0; i--) { - const element = this.openElements.items[i]; - - if (this.treeAdapter.getTagName(element) === token.tagName) { - mxn._setEndLocation(element, token); - break; - } - } - } - }, - - //Doctype - _setDocumentType(token) { - orig._setDocumentType.call(this, token); - - const documentChildren = this.treeAdapter.getChildNodes(this.document); - const cnLength = documentChildren.length; - - for (let i = 0; i < cnLength; i++) { - const node = documentChildren[i]; - - if (this.treeAdapter.isDocumentTypeNode(node)) { - this.treeAdapter.setNodeSourceCodeLocation(node, token.location); - break; - } - } - }, - - //Elements - _attachElementToTree(element) { - //NOTE: _attachElementToTree is called from _appendElement, _insertElement and _insertTemplate methods. - //So we will use token location stored in this methods for the element. - mxn._setStartLocation(element); - mxn.lastStartTagToken = null; - orig._attachElementToTree.call(this, element); - }, - - _appendElement(token, namespaceURI) { - mxn.lastStartTagToken = token; - orig._appendElement.call(this, token, namespaceURI); - }, - - _insertElement(token, namespaceURI) { - mxn.lastStartTagToken = token; - orig._insertElement.call(this, token, namespaceURI); - }, - - _insertTemplate(token) { - mxn.lastStartTagToken = token; - orig._insertTemplate.call(this, token); - - const tmplContent = this.treeAdapter.getTemplateContent(this.openElements.current); - - this.treeAdapter.setNodeSourceCodeLocation(tmplContent, null); - }, - - _insertFakeRootElement() { - orig._insertFakeRootElement.call(this); - this.treeAdapter.setNodeSourceCodeLocation(this.openElements.current, null); - }, - - //Comments - _appendCommentNode(token, parent) { - orig._appendCommentNode.call(this, token, parent); - - const children = this.treeAdapter.getChildNodes(parent); - const commentNode = children[children.length - 1]; - - this.treeAdapter.setNodeSourceCodeLocation(commentNode, token.location); - }, - - //Text - _findFosterParentingLocation() { - //NOTE: store last foster parenting location, so we will be able to find inserted text - //in case of foster parenting - mxn.lastFosterParentingLocation = orig._findFosterParentingLocation.call(this); - - return mxn.lastFosterParentingLocation; - }, - - _insertCharacters(token) { - orig._insertCharacters.call(this, token); - - const hasFosterParent = this._shouldFosterParentOnInsertion(); - - const parent = - (hasFosterParent && mxn.lastFosterParentingLocation.parent) || - this.openElements.currentTmplContent || - this.openElements.current; - - const siblings = this.treeAdapter.getChildNodes(parent); - - const textNodeIdx = - hasFosterParent && mxn.lastFosterParentingLocation.beforeElement - ? siblings.indexOf(mxn.lastFosterParentingLocation.beforeElement) - 1 - : siblings.length - 1; - - const textNode = siblings[textNodeIdx]; - - //NOTE: if we have location assigned by another token, then just update end position - const tnLoc = this.treeAdapter.getNodeSourceCodeLocation(textNode); - - if (tnLoc) { - const { endLine, endCol, endOffset } = token.location; - this.treeAdapter.updateNodeSourceCodeLocation(textNode, { endLine, endCol, endOffset }); - } else { - this.treeAdapter.setNodeSourceCodeLocation(textNode, token.location); - } - } - }; - } -} - -module.exports = LocationInfoParserMixin; - -},{"../../common/html":4,"../../tokenizer":19,"../../utils/mixin":24,"./open-element-stack-mixin":10,"./tokenizer-mixin":12}],12:[function(require,module,exports){ -'use strict'; - -const Mixin = require('../../utils/mixin'); -const Tokenizer = require('../../tokenizer'); -const PositionTrackingPreprocessorMixin = require('../position-tracking/preprocessor-mixin'); - -class LocationInfoTokenizerMixin extends Mixin { - constructor(tokenizer) { - super(tokenizer); - - this.tokenizer = tokenizer; - this.posTracker = Mixin.install(tokenizer.preprocessor, PositionTrackingPreprocessorMixin); - this.currentAttrLocation = null; - this.ctLoc = null; - } - - _getCurrentLocation() { - return { - startLine: this.posTracker.line, - startCol: this.posTracker.col, - startOffset: this.posTracker.offset, - endLine: -1, - endCol: -1, - endOffset: -1 - }; - } - - _attachCurrentAttrLocationInfo() { - this.currentAttrLocation.endLine = this.posTracker.line; - this.currentAttrLocation.endCol = this.posTracker.col; - this.currentAttrLocation.endOffset = this.posTracker.offset; - - const currentToken = this.tokenizer.currentToken; - const currentAttr = this.tokenizer.currentAttr; - - if (!currentToken.location.attrs) { - currentToken.location.attrs = Object.create(null); - } - - currentToken.location.attrs[currentAttr.name] = this.currentAttrLocation; - } - - _getOverriddenMethods(mxn, orig) { - const methods = { - _createStartTagToken() { - orig._createStartTagToken.call(this); - this.currentToken.location = mxn.ctLoc; - }, - - _createEndTagToken() { - orig._createEndTagToken.call(this); - this.currentToken.location = mxn.ctLoc; - }, - - _createCommentToken() { - orig._createCommentToken.call(this); - this.currentToken.location = mxn.ctLoc; - }, - - _createDoctypeToken(initialName) { - orig._createDoctypeToken.call(this, initialName); - this.currentToken.location = mxn.ctLoc; - }, - - _createCharacterToken(type, ch) { - orig._createCharacterToken.call(this, type, ch); - this.currentCharacterToken.location = mxn.ctLoc; - }, - - _createEOFToken() { - orig._createEOFToken.call(this); - this.currentToken.location = mxn._getCurrentLocation(); - }, - - _createAttr(attrNameFirstCh) { - orig._createAttr.call(this, attrNameFirstCh); - mxn.currentAttrLocation = mxn._getCurrentLocation(); - }, - - _leaveAttrName(toState) { - orig._leaveAttrName.call(this, toState); - mxn._attachCurrentAttrLocationInfo(); - }, - - _leaveAttrValue(toState) { - orig._leaveAttrValue.call(this, toState); - mxn._attachCurrentAttrLocationInfo(); - }, - - _emitCurrentToken() { - const ctLoc = this.currentToken.location; - - //NOTE: if we have pending character token make it's end location equal to the - //current token's start location. - if (this.currentCharacterToken) { - this.currentCharacterToken.location.endLine = ctLoc.startLine; - this.currentCharacterToken.location.endCol = ctLoc.startCol; - this.currentCharacterToken.location.endOffset = ctLoc.startOffset; - } - - if (this.currentToken.type === Tokenizer.EOF_TOKEN) { - ctLoc.endLine = ctLoc.startLine; - ctLoc.endCol = ctLoc.startCol; - ctLoc.endOffset = ctLoc.startOffset; - } else { - ctLoc.endLine = mxn.posTracker.line; - ctLoc.endCol = mxn.posTracker.col + 1; - ctLoc.endOffset = mxn.posTracker.offset + 1; - } - - orig._emitCurrentToken.call(this); - }, - - _emitCurrentCharacterToken() { - const ctLoc = this.currentCharacterToken && this.currentCharacterToken.location; - - //NOTE: if we have character token and it's location wasn't set in the _emitCurrentToken(), - //then set it's location at the current preprocessor position. - //We don't need to increment preprocessor position, since character token - //emission is always forced by the start of the next character token here. - //So, we already have advanced position. - if (ctLoc && ctLoc.endOffset === -1) { - ctLoc.endLine = mxn.posTracker.line; - ctLoc.endCol = mxn.posTracker.col; - ctLoc.endOffset = mxn.posTracker.offset; - } - - orig._emitCurrentCharacterToken.call(this); - } - }; - - //NOTE: patch initial states for each mode to obtain token start position - Object.keys(Tokenizer.MODE).forEach(modeName => { - const state = Tokenizer.MODE[modeName]; - - methods[state] = function(cp) { - mxn.ctLoc = mxn._getCurrentLocation(); - orig[state].call(this, cp); - }; - }); - - return methods; - } -} - -module.exports = LocationInfoTokenizerMixin; - -},{"../../tokenizer":19,"../../utils/mixin":24,"../position-tracking/preprocessor-mixin":13}],13:[function(require,module,exports){ -'use strict'; - -const Mixin = require('../../utils/mixin'); - -class PositionTrackingPreprocessorMixin extends Mixin { - constructor(preprocessor) { - super(preprocessor); - - this.preprocessor = preprocessor; - this.isEol = false; - this.lineStartPos = 0; - this.droppedBufferSize = 0; - - this.offset = 0; - this.col = 0; - this.line = 1; - } - - _getOverriddenMethods(mxn, orig) { - return { - advance() { - const pos = this.pos + 1; - const ch = this.html[pos]; - - //NOTE: LF should be in the last column of the line - if (mxn.isEol) { - mxn.isEol = false; - mxn.line++; - mxn.lineStartPos = pos; - } - - if (ch === '\n' || (ch === '\r' && this.html[pos + 1] !== '\n')) { - mxn.isEol = true; - } - - mxn.col = pos - mxn.lineStartPos + 1; - mxn.offset = mxn.droppedBufferSize + pos; - - return orig.advance.call(this); - }, - - retreat() { - orig.retreat.call(this); - - mxn.isEol = false; - mxn.col = this.pos - mxn.lineStartPos + 1; - }, - - dropParsedChunk() { - const prevPos = this.pos; - - orig.dropParsedChunk.call(this); - - const reduction = prevPos - this.pos; - - mxn.lineStartPos -= reduction; - mxn.droppedBufferSize += reduction; - mxn.offset = mxn.droppedBufferSize + this.pos; - } - }; - } -} - -module.exports = PositionTrackingPreprocessorMixin; - -},{"../../utils/mixin":24}],14:[function(require,module,exports){ -'use strict'; - -const Parser = require('./parser'); -const Serializer = require('./serializer'); - -// Shorthands -exports.parse = function parse(html, options) { - const parser = new Parser(options); - - return parser.parse(html); -}; - -exports.parseFragment = function parseFragment(fragmentContext, html, options) { - if (typeof fragmentContext === 'string') { - options = html; - html = fragmentContext; - fragmentContext = null; - } - - const parser = new Parser(options); - - return parser.parseFragment(html, fragmentContext); -}; - -exports.serialize = function(node, options) { - const serializer = new Serializer(node, options); - - return serializer.serialize(); -}; - -},{"./parser":16,"./serializer":18}],15:[function(require,module,exports){ -'use strict'; - -//Const -const NOAH_ARK_CAPACITY = 3; - -//List of formatting elements -class FormattingElementList { - constructor(treeAdapter) { - this.length = 0; - this.entries = []; - this.treeAdapter = treeAdapter; - this.bookmark = null; - } - - //Noah Ark's condition - //OPTIMIZATION: at first we try to find possible candidates for exclusion using - //lightweight heuristics without thorough attributes check. - _getNoahArkConditionCandidates(newElement) { - const candidates = []; - - if (this.length >= NOAH_ARK_CAPACITY) { - const neAttrsLength = this.treeAdapter.getAttrList(newElement).length; - const neTagName = this.treeAdapter.getTagName(newElement); - const neNamespaceURI = this.treeAdapter.getNamespaceURI(newElement); - - for (let i = this.length - 1; i >= 0; i--) { - const entry = this.entries[i]; - - if (entry.type === FormattingElementList.MARKER_ENTRY) { - break; - } - - const element = entry.element; - const elementAttrs = this.treeAdapter.getAttrList(element); - - const isCandidate = - this.treeAdapter.getTagName(element) === neTagName && - this.treeAdapter.getNamespaceURI(element) === neNamespaceURI && - elementAttrs.length === neAttrsLength; - - if (isCandidate) { - candidates.push({ idx: i, attrs: elementAttrs }); - } - } - } - - return candidates.length < NOAH_ARK_CAPACITY ? [] : candidates; - } - - _ensureNoahArkCondition(newElement) { - const candidates = this._getNoahArkConditionCandidates(newElement); - let cLength = candidates.length; - - if (cLength) { - const neAttrs = this.treeAdapter.getAttrList(newElement); - const neAttrsLength = neAttrs.length; - const neAttrsMap = Object.create(null); - - //NOTE: build attrs map for the new element so we can perform fast lookups - for (let i = 0; i < neAttrsLength; i++) { - const neAttr = neAttrs[i]; - - neAttrsMap[neAttr.name] = neAttr.value; - } - - for (let i = 0; i < neAttrsLength; i++) { - for (let j = 0; j < cLength; j++) { - const cAttr = candidates[j].attrs[i]; - - if (neAttrsMap[cAttr.name] !== cAttr.value) { - candidates.splice(j, 1); - cLength--; - } - - if (candidates.length < NOAH_ARK_CAPACITY) { - return; - } - } - } - - //NOTE: remove bottommost candidates until Noah's Ark condition will not be met - for (let i = cLength - 1; i >= NOAH_ARK_CAPACITY - 1; i--) { - this.entries.splice(candidates[i].idx, 1); - this.length--; - } - } - } - - //Mutations - insertMarker() { - this.entries.push({ type: FormattingElementList.MARKER_ENTRY }); - this.length++; - } - - pushElement(element, token) { - this._ensureNoahArkCondition(element); - - this.entries.push({ - type: FormattingElementList.ELEMENT_ENTRY, - element: element, - token: token - }); - - this.length++; - } - - insertElementAfterBookmark(element, token) { - let bookmarkIdx = this.length - 1; - - for (; bookmarkIdx >= 0; bookmarkIdx--) { - if (this.entries[bookmarkIdx] === this.bookmark) { - break; - } - } - - this.entries.splice(bookmarkIdx + 1, 0, { - type: FormattingElementList.ELEMENT_ENTRY, - element: element, - token: token - }); - - this.length++; - } - - removeEntry(entry) { - for (let i = this.length - 1; i >= 0; i--) { - if (this.entries[i] === entry) { - this.entries.splice(i, 1); - this.length--; - break; - } - } - } - - clearToLastMarker() { - while (this.length) { - const entry = this.entries.pop(); - - this.length--; - - if (entry.type === FormattingElementList.MARKER_ENTRY) { - break; - } - } - } - - //Search - getElementEntryInScopeWithTagName(tagName) { - for (let i = this.length - 1; i >= 0; i--) { - const entry = this.entries[i]; - - if (entry.type === FormattingElementList.MARKER_ENTRY) { - return null; - } - - if (this.treeAdapter.getTagName(entry.element) === tagName) { - return entry; - } - } - - return null; - } - - getElementEntry(element) { - for (let i = this.length - 1; i >= 0; i--) { - const entry = this.entries[i]; - - if (entry.type === FormattingElementList.ELEMENT_ENTRY && entry.element === element) { - return entry; - } - } - - return null; - } -} - -//Entry types -FormattingElementList.MARKER_ENTRY = 'MARKER_ENTRY'; -FormattingElementList.ELEMENT_ENTRY = 'ELEMENT_ENTRY'; - -module.exports = FormattingElementList; - -},{}],16:[function(require,module,exports){ -'use strict'; - -const Tokenizer = require('../tokenizer'); -const OpenElementStack = require('./open-element-stack'); -const FormattingElementList = require('./formatting-element-list'); -const LocationInfoParserMixin = require('../extensions/location-info/parser-mixin'); -const ErrorReportingParserMixin = require('../extensions/error-reporting/parser-mixin'); -const Mixin = require('../utils/mixin'); -const defaultTreeAdapter = require('../tree-adapters/default'); -const mergeOptions = require('../utils/merge-options'); -const doctype = require('../common/doctype'); -const foreignContent = require('../common/foreign-content'); -const ERR = require('../common/error-codes'); -const unicode = require('../common/unicode'); -const HTML = require('../common/html'); - -//Aliases -const $ = HTML.TAG_NAMES; -const NS = HTML.NAMESPACES; -const ATTRS = HTML.ATTRS; - -const DEFAULT_OPTIONS = { - scriptingEnabled: true, - sourceCodeLocationInfo: false, - onParseError: null, - treeAdapter: defaultTreeAdapter -}; - + getElementEntry(element) { + return this.entries.find((entry) => entry.type === EntryType.Element && entry.element === element); + } +} +exports.FormattingElementList = FormattingElementList; + +},{}],9:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Parser = void 0; +const index_js_1 = require("../tokenizer/index.js"); +const open_element_stack_js_1 = require("./open-element-stack.js"); +const formatting_element_list_js_1 = require("./formatting-element-list.js"); +const default_js_1 = require("../tree-adapters/default.js"); +const doctype = require("../common/doctype.js"); +const foreignContent = require("../common/foreign-content.js"); +const error_codes_js_1 = require("../common/error-codes.js"); +const unicode = require("../common/unicode.js"); +const html_js_1 = require("../common/html.js"); +const token_js_1 = require("../common/token.js"); //Misc constants const HIDDEN_INPUT_TYPE = 'hidden'; - //Adoption agency loops iteration count const AA_OUTER_LOOP_ITER = 8; const AA_INNER_LOOP_ITER = 3; - //Insertion modes -const INITIAL_MODE = 'INITIAL_MODE'; -const BEFORE_HTML_MODE = 'BEFORE_HTML_MODE'; -const BEFORE_HEAD_MODE = 'BEFORE_HEAD_MODE'; -const IN_HEAD_MODE = 'IN_HEAD_MODE'; -const IN_HEAD_NO_SCRIPT_MODE = 'IN_HEAD_NO_SCRIPT_MODE'; -const AFTER_HEAD_MODE = 'AFTER_HEAD_MODE'; -const IN_BODY_MODE = 'IN_BODY_MODE'; -const TEXT_MODE = 'TEXT_MODE'; -const IN_TABLE_MODE = 'IN_TABLE_MODE'; -const IN_TABLE_TEXT_MODE = 'IN_TABLE_TEXT_MODE'; -const IN_CAPTION_MODE = 'IN_CAPTION_MODE'; -const IN_COLUMN_GROUP_MODE = 'IN_COLUMN_GROUP_MODE'; -const IN_TABLE_BODY_MODE = 'IN_TABLE_BODY_MODE'; -const IN_ROW_MODE = 'IN_ROW_MODE'; -const IN_CELL_MODE = 'IN_CELL_MODE'; -const IN_SELECT_MODE = 'IN_SELECT_MODE'; -const IN_SELECT_IN_TABLE_MODE = 'IN_SELECT_IN_TABLE_MODE'; -const IN_TEMPLATE_MODE = 'IN_TEMPLATE_MODE'; -const AFTER_BODY_MODE = 'AFTER_BODY_MODE'; -const IN_FRAMESET_MODE = 'IN_FRAMESET_MODE'; -const AFTER_FRAMESET_MODE = 'AFTER_FRAMESET_MODE'; -const AFTER_AFTER_BODY_MODE = 'AFTER_AFTER_BODY_MODE'; -const AFTER_AFTER_FRAMESET_MODE = 'AFTER_AFTER_FRAMESET_MODE'; - -//Insertion mode reset map -const INSERTION_MODE_RESET_MAP = { - [$.TR]: IN_ROW_MODE, - [$.TBODY]: IN_TABLE_BODY_MODE, - [$.THEAD]: IN_TABLE_BODY_MODE, - [$.TFOOT]: IN_TABLE_BODY_MODE, - [$.CAPTION]: IN_CAPTION_MODE, - [$.COLGROUP]: IN_COLUMN_GROUP_MODE, - [$.TABLE]: IN_TABLE_MODE, - [$.BODY]: IN_BODY_MODE, - [$.FRAMESET]: IN_FRAMESET_MODE +var InsertionMode; +(function (InsertionMode) { + InsertionMode[InsertionMode["INITIAL"] = 0] = "INITIAL"; + InsertionMode[InsertionMode["BEFORE_HTML"] = 1] = "BEFORE_HTML"; + InsertionMode[InsertionMode["BEFORE_HEAD"] = 2] = "BEFORE_HEAD"; + InsertionMode[InsertionMode["IN_HEAD"] = 3] = "IN_HEAD"; + InsertionMode[InsertionMode["IN_HEAD_NO_SCRIPT"] = 4] = "IN_HEAD_NO_SCRIPT"; + InsertionMode[InsertionMode["AFTER_HEAD"] = 5] = "AFTER_HEAD"; + InsertionMode[InsertionMode["IN_BODY"] = 6] = "IN_BODY"; + InsertionMode[InsertionMode["TEXT"] = 7] = "TEXT"; + InsertionMode[InsertionMode["IN_TABLE"] = 8] = "IN_TABLE"; + InsertionMode[InsertionMode["IN_TABLE_TEXT"] = 9] = "IN_TABLE_TEXT"; + InsertionMode[InsertionMode["IN_CAPTION"] = 10] = "IN_CAPTION"; + InsertionMode[InsertionMode["IN_COLUMN_GROUP"] = 11] = "IN_COLUMN_GROUP"; + InsertionMode[InsertionMode["IN_TABLE_BODY"] = 12] = "IN_TABLE_BODY"; + InsertionMode[InsertionMode["IN_ROW"] = 13] = "IN_ROW"; + InsertionMode[InsertionMode["IN_CELL"] = 14] = "IN_CELL"; + InsertionMode[InsertionMode["IN_SELECT"] = 15] = "IN_SELECT"; + InsertionMode[InsertionMode["IN_SELECT_IN_TABLE"] = 16] = "IN_SELECT_IN_TABLE"; + InsertionMode[InsertionMode["IN_TEMPLATE"] = 17] = "IN_TEMPLATE"; + InsertionMode[InsertionMode["AFTER_BODY"] = 18] = "AFTER_BODY"; + InsertionMode[InsertionMode["IN_FRAMESET"] = 19] = "IN_FRAMESET"; + InsertionMode[InsertionMode["AFTER_FRAMESET"] = 20] = "AFTER_FRAMESET"; + InsertionMode[InsertionMode["AFTER_AFTER_BODY"] = 21] = "AFTER_AFTER_BODY"; + InsertionMode[InsertionMode["AFTER_AFTER_FRAMESET"] = 22] = "AFTER_AFTER_FRAMESET"; +})(InsertionMode || (InsertionMode = {})); +const BASE_LOC = { + startLine: -1, + startCol: -1, + startOffset: -1, + endLine: -1, + endCol: -1, + endOffset: -1, }; - -//Template insertion mode switch map -const TEMPLATE_INSERTION_MODE_SWITCH_MAP = { - [$.CAPTION]: IN_TABLE_MODE, - [$.COLGROUP]: IN_TABLE_MODE, - [$.TBODY]: IN_TABLE_MODE, - [$.TFOOT]: IN_TABLE_MODE, - [$.THEAD]: IN_TABLE_MODE, - [$.COL]: IN_COLUMN_GROUP_MODE, - [$.TR]: IN_TABLE_BODY_MODE, - [$.TD]: IN_ROW_MODE, - [$.TH]: IN_ROW_MODE -}; - -//Token handlers map for insertion modes -const TOKEN_HANDLERS = { - [INITIAL_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: tokenInInitialMode, - [Tokenizer.NULL_CHARACTER_TOKEN]: tokenInInitialMode, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: ignoreToken, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: doctypeInInitialMode, - [Tokenizer.START_TAG_TOKEN]: tokenInInitialMode, - [Tokenizer.END_TAG_TOKEN]: tokenInInitialMode, - [Tokenizer.EOF_TOKEN]: tokenInInitialMode - }, - [BEFORE_HTML_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: tokenBeforeHtml, - [Tokenizer.NULL_CHARACTER_TOKEN]: tokenBeforeHtml, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: ignoreToken, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: startTagBeforeHtml, - [Tokenizer.END_TAG_TOKEN]: endTagBeforeHtml, - [Tokenizer.EOF_TOKEN]: tokenBeforeHtml - }, - [BEFORE_HEAD_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: tokenBeforeHead, - [Tokenizer.NULL_CHARACTER_TOKEN]: tokenBeforeHead, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: ignoreToken, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: misplacedDoctype, - [Tokenizer.START_TAG_TOKEN]: startTagBeforeHead, - [Tokenizer.END_TAG_TOKEN]: endTagBeforeHead, - [Tokenizer.EOF_TOKEN]: tokenBeforeHead - }, - [IN_HEAD_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: tokenInHead, - [Tokenizer.NULL_CHARACTER_TOKEN]: tokenInHead, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: insertCharacters, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: misplacedDoctype, - [Tokenizer.START_TAG_TOKEN]: startTagInHead, - [Tokenizer.END_TAG_TOKEN]: endTagInHead, - [Tokenizer.EOF_TOKEN]: tokenInHead - }, - [IN_HEAD_NO_SCRIPT_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: tokenInHeadNoScript, - [Tokenizer.NULL_CHARACTER_TOKEN]: tokenInHeadNoScript, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: insertCharacters, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: misplacedDoctype, - [Tokenizer.START_TAG_TOKEN]: startTagInHeadNoScript, - [Tokenizer.END_TAG_TOKEN]: endTagInHeadNoScript, - [Tokenizer.EOF_TOKEN]: tokenInHeadNoScript - }, - [AFTER_HEAD_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: tokenAfterHead, - [Tokenizer.NULL_CHARACTER_TOKEN]: tokenAfterHead, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: insertCharacters, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: misplacedDoctype, - [Tokenizer.START_TAG_TOKEN]: startTagAfterHead, - [Tokenizer.END_TAG_TOKEN]: endTagAfterHead, - [Tokenizer.EOF_TOKEN]: tokenAfterHead - }, - [IN_BODY_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: characterInBody, - [Tokenizer.NULL_CHARACTER_TOKEN]: ignoreToken, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: whitespaceCharacterInBody, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: startTagInBody, - [Tokenizer.END_TAG_TOKEN]: endTagInBody, - [Tokenizer.EOF_TOKEN]: eofInBody - }, - [TEXT_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: insertCharacters, - [Tokenizer.NULL_CHARACTER_TOKEN]: insertCharacters, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: insertCharacters, - [Tokenizer.COMMENT_TOKEN]: ignoreToken, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: ignoreToken, - [Tokenizer.END_TAG_TOKEN]: endTagInText, - [Tokenizer.EOF_TOKEN]: eofInText - }, - [IN_TABLE_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: characterInTable, - [Tokenizer.NULL_CHARACTER_TOKEN]: characterInTable, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: characterInTable, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: startTagInTable, - [Tokenizer.END_TAG_TOKEN]: endTagInTable, - [Tokenizer.EOF_TOKEN]: eofInBody - }, - [IN_TABLE_TEXT_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: characterInTableText, - [Tokenizer.NULL_CHARACTER_TOKEN]: ignoreToken, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: whitespaceCharacterInTableText, - [Tokenizer.COMMENT_TOKEN]: tokenInTableText, - [Tokenizer.DOCTYPE_TOKEN]: tokenInTableText, - [Tokenizer.START_TAG_TOKEN]: tokenInTableText, - [Tokenizer.END_TAG_TOKEN]: tokenInTableText, - [Tokenizer.EOF_TOKEN]: tokenInTableText - }, - [IN_CAPTION_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: characterInBody, - [Tokenizer.NULL_CHARACTER_TOKEN]: ignoreToken, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: whitespaceCharacterInBody, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: startTagInCaption, - [Tokenizer.END_TAG_TOKEN]: endTagInCaption, - [Tokenizer.EOF_TOKEN]: eofInBody - }, - [IN_COLUMN_GROUP_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: tokenInColumnGroup, - [Tokenizer.NULL_CHARACTER_TOKEN]: tokenInColumnGroup, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: insertCharacters, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: startTagInColumnGroup, - [Tokenizer.END_TAG_TOKEN]: endTagInColumnGroup, - [Tokenizer.EOF_TOKEN]: eofInBody - }, - [IN_TABLE_BODY_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: characterInTable, - [Tokenizer.NULL_CHARACTER_TOKEN]: characterInTable, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: characterInTable, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: startTagInTableBody, - [Tokenizer.END_TAG_TOKEN]: endTagInTableBody, - [Tokenizer.EOF_TOKEN]: eofInBody - }, - [IN_ROW_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: characterInTable, - [Tokenizer.NULL_CHARACTER_TOKEN]: characterInTable, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: characterInTable, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: startTagInRow, - [Tokenizer.END_TAG_TOKEN]: endTagInRow, - [Tokenizer.EOF_TOKEN]: eofInBody - }, - [IN_CELL_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: characterInBody, - [Tokenizer.NULL_CHARACTER_TOKEN]: ignoreToken, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: whitespaceCharacterInBody, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: startTagInCell, - [Tokenizer.END_TAG_TOKEN]: endTagInCell, - [Tokenizer.EOF_TOKEN]: eofInBody - }, - [IN_SELECT_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: insertCharacters, - [Tokenizer.NULL_CHARACTER_TOKEN]: ignoreToken, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: insertCharacters, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: startTagInSelect, - [Tokenizer.END_TAG_TOKEN]: endTagInSelect, - [Tokenizer.EOF_TOKEN]: eofInBody - }, - [IN_SELECT_IN_TABLE_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: insertCharacters, - [Tokenizer.NULL_CHARACTER_TOKEN]: ignoreToken, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: insertCharacters, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: startTagInSelectInTable, - [Tokenizer.END_TAG_TOKEN]: endTagInSelectInTable, - [Tokenizer.EOF_TOKEN]: eofInBody - }, - [IN_TEMPLATE_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: characterInBody, - [Tokenizer.NULL_CHARACTER_TOKEN]: ignoreToken, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: whitespaceCharacterInBody, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: startTagInTemplate, - [Tokenizer.END_TAG_TOKEN]: endTagInTemplate, - [Tokenizer.EOF_TOKEN]: eofInTemplate - }, - [AFTER_BODY_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: tokenAfterBody, - [Tokenizer.NULL_CHARACTER_TOKEN]: tokenAfterBody, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: whitespaceCharacterInBody, - [Tokenizer.COMMENT_TOKEN]: appendCommentToRootHtmlElement, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: startTagAfterBody, - [Tokenizer.END_TAG_TOKEN]: endTagAfterBody, - [Tokenizer.EOF_TOKEN]: stopParsing - }, - [IN_FRAMESET_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: ignoreToken, - [Tokenizer.NULL_CHARACTER_TOKEN]: ignoreToken, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: insertCharacters, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: startTagInFrameset, - [Tokenizer.END_TAG_TOKEN]: endTagInFrameset, - [Tokenizer.EOF_TOKEN]: stopParsing - }, - [AFTER_FRAMESET_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: ignoreToken, - [Tokenizer.NULL_CHARACTER_TOKEN]: ignoreToken, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: insertCharacters, - [Tokenizer.COMMENT_TOKEN]: appendComment, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: startTagAfterFrameset, - [Tokenizer.END_TAG_TOKEN]: endTagAfterFrameset, - [Tokenizer.EOF_TOKEN]: stopParsing - }, - [AFTER_AFTER_BODY_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: tokenAfterAfterBody, - [Tokenizer.NULL_CHARACTER_TOKEN]: tokenAfterAfterBody, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: whitespaceCharacterInBody, - [Tokenizer.COMMENT_TOKEN]: appendCommentToDocument, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: startTagAfterAfterBody, - [Tokenizer.END_TAG_TOKEN]: tokenAfterAfterBody, - [Tokenizer.EOF_TOKEN]: stopParsing - }, - [AFTER_AFTER_FRAMESET_MODE]: { - [Tokenizer.CHARACTER_TOKEN]: ignoreToken, - [Tokenizer.NULL_CHARACTER_TOKEN]: ignoreToken, - [Tokenizer.WHITESPACE_CHARACTER_TOKEN]: whitespaceCharacterInBody, - [Tokenizer.COMMENT_TOKEN]: appendCommentToDocument, - [Tokenizer.DOCTYPE_TOKEN]: ignoreToken, - [Tokenizer.START_TAG_TOKEN]: startTagAfterAfterFrameset, - [Tokenizer.END_TAG_TOKEN]: ignoreToken, - [Tokenizer.EOF_TOKEN]: stopParsing - } +const TABLE_STRUCTURE_TAGS = new Set([html_js_1.TAG_ID.TABLE, html_js_1.TAG_ID.TBODY, html_js_1.TAG_ID.TFOOT, html_js_1.TAG_ID.THEAD, html_js_1.TAG_ID.TR]); +const defaultParserOptions = { + scriptingEnabled: true, + sourceCodeLocationInfo: false, + treeAdapter: default_js_1.defaultTreeAdapter, + onParseError: null, }; - //Parser class Parser { - constructor(options) { - this.options = mergeOptions(DEFAULT_OPTIONS, options); - - this.treeAdapter = this.options.treeAdapter; - this.pendingScript = null; - - if (this.options.sourceCodeLocationInfo) { - Mixin.install(this, LocationInfoParserMixin); - } - - if (this.options.onParseError) { - Mixin.install(this, ErrorReportingParserMixin, { onParseError: this.options.onParseError }); - } - } - - // API - parse(html) { - const document = this.treeAdapter.createDocument(); - - this._bootstrap(document, null); - this.tokenizer.write(html, true); - this._runParsingLoop(null); - - return document; - } - - parseFragment(html, fragmentContext) { - //NOTE: use