1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163 |
- "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
- 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,
- };
- 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, document, fragmentContext = null, scriptHandler = null) {
- this.fragmentContext = fragmentContext;
- this.scriptHandler = scriptHandler;
- this.currentToken = null;
- this.stopped = false;
- this.insertionMode = InsertionMode.INITIAL;
- this.originalInsertionMode = InsertionMode.INITIAL;
- this.headElement = null;
- this.formElement = null;
- /** Indicates that the current node is not an element in the HTML namespace */
- this.currentNotInHTML = false;
- /**
- * The template insertion mode stack is maintained from the left.
- * Ie. the topmost element will always have index 0.
- */
- this.tmplInsertionModeStack = [];
- this.pendingCharacterTokens = [];
- this.hasNonWhitespacePendingCharacterToken = false;
- this.framesetOk = true;
- this.skipNextNewLine = false;
- this.fosterParentingEnabled = false;
- this.options = Object.assign(Object.assign({}, defaultParserOptions), options);
- this.treeAdapter = this.options.treeAdapter;
- this.onParseError = this.options.onParseError;
- // Always enable location info if we report parse errors.
- if (this.onParseError) {
- this.options.sourceCodeLocationInfo = true;
- }
- this.document = document !== null && document !== void 0 ? document : this.treeAdapter.createDocument();
- this.tokenizer = new index_js_1.Tokenizer(this.options, this);
- this.activeFormattingElements = new formatting_element_list_js_1.FormattingElementList(this.treeAdapter);
- this.fragmentContextID = fragmentContext ? (0, html_js_1.getTagID)(this.treeAdapter.getTagName(fragmentContext)) : html_js_1.TAG_ID.UNKNOWN;
- this._setContextModes(fragmentContext !== null && fragmentContext !== void 0 ? fragmentContext : this.document, this.fragmentContextID);
- this.openElements = new open_element_stack_js_1.OpenElementStack(this.document, this.treeAdapter, this);
- }
- // API
- static parse(html, options) {
- const parser = new this(options);
- parser.tokenizer.write(html, true);
- return parser.document;
- }
- static getFragmentParser(fragmentContext, options) {
- const opts = Object.assign(Object.assign({}, defaultParserOptions), options);
- //NOTE: use a <template> element as the fragment context if no context element was provided,
- //so we will parse in a "forgiving" manner
- fragmentContext !== null && fragmentContext !== void 0 ? fragmentContext : (fragmentContext = opts.treeAdapter.createElement(html_js_1.TAG_NAMES.TEMPLATE, html_js_1.NS.HTML, []));
- //NOTE: create a fake element which will be used as the `document` for fragment parsing.
- //This is important for jsdom, where a new `document` cannot be created. This led to
- //fragment parsing messing with the main `document`.
- const documentMock = opts.treeAdapter.createElement('documentmock', html_js_1.NS.HTML, []);
- const parser = new this(opts, documentMock, fragmentContext);
- if (parser.fragmentContextID === html_js_1.TAG_ID.TEMPLATE) {
- parser.tmplInsertionModeStack.unshift(InsertionMode.IN_TEMPLATE);
- }
- parser._initTokenizerForFragmentParsing();
- parser._insertFakeRootElement();
- parser._resetInsertionMode();
- parser._findFormInFragmentContext();
- return parser;
- }
- getFragment() {
- const rootElement = this.treeAdapter.getFirstChild(this.document);
- const fragment = this.treeAdapter.createDocumentFragment();
- this._adoptNodes(rootElement, fragment);
- return fragment;
- }
- //Errors
- _err(token, code, beforeToken) {
- var _a;
- if (!this.onParseError)
- return;
- const loc = (_a = token.location) !== null && _a !== void 0 ? _a : BASE_LOC;
- const err = {
- code,
- startLine: loc.startLine,
- startCol: loc.startCol,
- startOffset: loc.startOffset,
- endLine: beforeToken ? loc.startLine : loc.endLine,
- endCol: beforeToken ? loc.startCol : loc.endCol,
- endOffset: beforeToken ? loc.startOffset : loc.endOffset,
- };
- this.onParseError(err);
- }
- //Stack events
- onItemPush(node, tid, isTop) {
- var _a, _b;
- (_b = (_a = this.treeAdapter).onItemPush) === null || _b === void 0 ? void 0 : _b.call(_a, node);
- if (isTop && this.openElements.stackTop > 0)
- this._setContextModes(node, tid);
- }
- onItemPop(node, isTop) {
- var _a, _b;
- if (this.options.sourceCodeLocationInfo) {
- this._setEndLocation(node, this.currentToken);
- }
- (_b = (_a = this.treeAdapter).onItemPop) === null || _b === void 0 ? void 0 : _b.call(_a, node, this.openElements.current);
- if (isTop) {
- let current;
- let currentTagId;
- if (this.openElements.stackTop === 0 && this.fragmentContext) {
- current = this.fragmentContext;
- currentTagId = this.fragmentContextID;
- }
- else {
- ({ current, currentTagId } = this.openElements);
- }
- this._setContextModes(current, currentTagId);
- }
- }
- _setContextModes(current, tid) {
- const isHTML = current === this.document || this.treeAdapter.getNamespaceURI(current) === html_js_1.NS.HTML;
- this.currentNotInHTML = !isHTML;
- this.tokenizer.inForeignNode = !isHTML && !this._isIntegrationPoint(tid, current);
- }
- _switchToTextParsing(currentToken, nextTokenizerState) {
- this._insertElement(currentToken, html_js_1.NS.HTML);
- this.tokenizer.state = nextTokenizerState;
- this.originalInsertionMode = this.insertionMode;
- this.insertionMode = InsertionMode.TEXT;
- }
- switchToPlaintextParsing() {
- this.insertionMode = InsertionMode.TEXT;
- this.originalInsertionMode = InsertionMode.IN_BODY;
- this.tokenizer.state = index_js_1.TokenizerMode.PLAINTEXT;
- }
- //Fragment parsing
- _getAdjustedCurrentElement() {
- return this.openElements.stackTop === 0 && this.fragmentContext
- ? this.fragmentContext
- : this.openElements.current;
- }
- _findFormInFragmentContext() {
- let node = this.fragmentContext;
- while (node) {
- if (this.treeAdapter.getTagName(node) === html_js_1.TAG_NAMES.FORM) {
- this.formElement = node;
- break;
- }
- node = this.treeAdapter.getParentNode(node);
- }
- }
- _initTokenizerForFragmentParsing() {
- if (!this.fragmentContext || this.treeAdapter.getNamespaceURI(this.fragmentContext) !== html_js_1.NS.HTML) {
- return;
- }
- switch (this.fragmentContextID) {
- case html_js_1.TAG_ID.TITLE:
- case html_js_1.TAG_ID.TEXTAREA: {
- this.tokenizer.state = index_js_1.TokenizerMode.RCDATA;
- break;
- }
- case html_js_1.TAG_ID.STYLE:
- case html_js_1.TAG_ID.XMP:
- case html_js_1.TAG_ID.IFRAME:
- case html_js_1.TAG_ID.NOEMBED:
- case html_js_1.TAG_ID.NOFRAMES:
- case html_js_1.TAG_ID.NOSCRIPT: {
- this.tokenizer.state = index_js_1.TokenizerMode.RAWTEXT;
- break;
- }
- case html_js_1.TAG_ID.SCRIPT: {
- this.tokenizer.state = index_js_1.TokenizerMode.SCRIPT_DATA;
- break;
- }
- case html_js_1.TAG_ID.PLAINTEXT: {
- this.tokenizer.state = index_js_1.TokenizerMode.PLAINTEXT;
- break;
- }
- default:
- // Do nothing
- }
- }
- //Tree mutation
- _setDocumentType(token) {
- const name = token.name || '';
- const publicId = token.publicId || '';
- const systemId = token.systemId || '';
- this.treeAdapter.setDocumentType(this.document, name, publicId, systemId);
- if (token.location) {
- const documentChildren = this.treeAdapter.getChildNodes(this.document);
- const docTypeNode = documentChildren.find((node) => this.treeAdapter.isDocumentTypeNode(node));
- if (docTypeNode) {
- this.treeAdapter.setNodeSourceCodeLocation(docTypeNode, token.location);
- }
- }
- }
- _attachElementToTree(element, location) {
- if (this.options.sourceCodeLocationInfo) {
- const loc = location && Object.assign(Object.assign({}, location), { startTag: location });
- this.treeAdapter.setNodeSourceCodeLocation(element, loc);
- }
- if (this._shouldFosterParentOnInsertion()) {
- this._fosterParentElement(element);
- }
- else {
- const parent = this.openElements.currentTmplContentOrNode;
- this.treeAdapter.appendChild(parent, element);
- }
- }
- _appendElement(token, namespaceURI) {
- const element = this.treeAdapter.createElement(token.tagName, namespaceURI, token.attrs);
- this._attachElementToTree(element, token.location);
- }
- _insertElement(token, namespaceURI) {
- const element = this.treeAdapter.createElement(token.tagName, namespaceURI, token.attrs);
- this._attachElementToTree(element, token.location);
- this.openElements.push(element, token.tagID);
- }
- _insertFakeElement(tagName, tagID) {
- const element = this.treeAdapter.createElement(tagName, html_js_1.NS.HTML, []);
- this._attachElementToTree(element, null);
- this.openElements.push(element, tagID);
- }
- _insertTemplate(token) {
- const tmpl = this.treeAdapter.createElement(token.tagName, html_js_1.NS.HTML, token.attrs);
- const content = this.treeAdapter.createDocumentFragment();
- this.treeAdapter.setTemplateContent(tmpl, content);
- this._attachElementToTree(tmpl, token.location);
- this.openElements.push(tmpl, token.tagID);
- if (this.options.sourceCodeLocationInfo)
- this.treeAdapter.setNodeSourceCodeLocation(content, null);
- }
- _insertFakeRootElement() {
- const element = this.treeAdapter.createElement(html_js_1.TAG_NAMES.HTML, html_js_1.NS.HTML, []);
- if (this.options.sourceCodeLocationInfo)
- this.treeAdapter.setNodeSourceCodeLocation(element, null);
- this.treeAdapter.appendChild(this.openElements.current, element);
- this.openElements.push(element, html_js_1.TAG_ID.HTML);
- }
- _appendCommentNode(token, parent) {
- const commentNode = this.treeAdapter.createCommentNode(token.data);
- this.treeAdapter.appendChild(parent, commentNode);
- if (this.options.sourceCodeLocationInfo) {
- this.treeAdapter.setNodeSourceCodeLocation(commentNode, token.location);
- }
- }
- _insertCharacters(token) {
- let parent;
- let beforeElement;
- if (this._shouldFosterParentOnInsertion()) {
- ({ parent, beforeElement } = this._findFosterParentingLocation());
- if (beforeElement) {
- this.treeAdapter.insertTextBefore(parent, token.chars, beforeElement);
- }
- else {
- this.treeAdapter.insertText(parent, token.chars);
- }
- }
- else {
- parent = this.openElements.currentTmplContentOrNode;
- this.treeAdapter.insertText(parent, token.chars);
- }
- if (!token.location)
- return;
- const siblings = this.treeAdapter.getChildNodes(parent);
- const textNodeIdx = beforeElement ? siblings.lastIndexOf(beforeElement) : siblings.length;
- const textNode = siblings[textNodeIdx - 1];
- //NOTE: if we have a location assigned by another token, then just update the end position
- const tnLoc = this.treeAdapter.getNodeSourceCodeLocation(textNode);
- if (tnLoc) {
- const { endLine, endCol, endOffset } = token.location;
- this.treeAdapter.updateNodeSourceCodeLocation(textNode, { endLine, endCol, endOffset });
- }
- else if (this.options.sourceCodeLocationInfo) {
- this.treeAdapter.setNodeSourceCodeLocation(textNode, token.location);
- }
- }
- _adoptNodes(donor, recipient) {
- for (let child = this.treeAdapter.getFirstChild(donor); child; child = this.treeAdapter.getFirstChild(donor)) {
- this.treeAdapter.detachNode(child);
- this.treeAdapter.appendChild(recipient, child);
- }
- }
- _setEndLocation(element, closingToken) {
- if (this.treeAdapter.getNodeSourceCodeLocation(element) && closingToken.location) {
- const ctLoc = closingToken.location;
- const tn = this.treeAdapter.getTagName(element);
- const endLoc =
- // NOTE: For cases like <p> <p> </p> - First 'p' closes without a closing
- // tag and for cases like <td> <p> </td> - 'p' closes without a closing tag.
- closingToken.type === token_js_1.TokenType.END_TAG && tn === closingToken.tagName
- ? {
- endTag: Object.assign({}, ctLoc),
- endLine: ctLoc.endLine,
- endCol: ctLoc.endCol,
- endOffset: ctLoc.endOffset,
- }
- : {
- endLine: ctLoc.startLine,
- endCol: ctLoc.startCol,
- endOffset: ctLoc.startOffset,
- };
- this.treeAdapter.updateNodeSourceCodeLocation(element, endLoc);
- }
- }
- //Token processing
- shouldProcessStartTagTokenInForeignContent(token) {
- // Check that neither current === document, or ns === NS.HTML
- if (!this.currentNotInHTML)
- return false;
- let current;
- let currentTagId;
- if (this.openElements.stackTop === 0 && this.fragmentContext) {
- current = this.fragmentContext;
- currentTagId = this.fragmentContextID;
- }
- else {
- ({ current, currentTagId } = this.openElements);
- }
- if (token.tagID === html_js_1.TAG_ID.SVG &&
- this.treeAdapter.getTagName(current) === html_js_1.TAG_NAMES.ANNOTATION_XML &&
- this.treeAdapter.getNamespaceURI(current) === html_js_1.NS.MATHML) {
- return false;
- }
- return (
- // Check that `current` is not an integration point for HTML or MathML elements.
- this.tokenizer.inForeignNode ||
- // If it _is_ an integration point, then we might have to check that it is not an HTML
- // integration point.
- ((token.tagID === html_js_1.TAG_ID.MGLYPH || token.tagID === html_js_1.TAG_ID.MALIGNMARK) &&
- !this._isIntegrationPoint(currentTagId, current, html_js_1.NS.HTML)));
- }
- _processToken(token) {
- switch (token.type) {
- case token_js_1.TokenType.CHARACTER: {
- this.onCharacter(token);
- break;
- }
- case token_js_1.TokenType.NULL_CHARACTER: {
- this.onNullCharacter(token);
- break;
- }
- case token_js_1.TokenType.COMMENT: {
- this.onComment(token);
- break;
- }
- case token_js_1.TokenType.DOCTYPE: {
- this.onDoctype(token);
- break;
- }
- case token_js_1.TokenType.START_TAG: {
- this._processStartTag(token);
- break;
- }
- case token_js_1.TokenType.END_TAG: {
- this.onEndTag(token);
- break;
- }
- case token_js_1.TokenType.EOF: {
- this.onEof(token);
- break;
- }
- case token_js_1.TokenType.WHITESPACE_CHARACTER: {
- this.onWhitespaceCharacter(token);
- break;
- }
- }
- }
- //Integration points
- _isIntegrationPoint(tid, element, foreignNS) {
- const ns = this.treeAdapter.getNamespaceURI(element);
- const attrs = this.treeAdapter.getAttrList(element);
- return foreignContent.isIntegrationPoint(tid, ns, attrs, foreignNS);
- }
- //Active formatting elements reconstruction
- _reconstructActiveFormattingElements() {
- const listLength = this.activeFormattingElements.entries.length;
- if (listLength) {
- const endIndex = this.activeFormattingElements.entries.findIndex((entry) => entry.type === formatting_element_list_js_1.EntryType.Marker || this.openElements.contains(entry.element));
- const unopenIdx = endIndex < 0 ? listLength - 1 : endIndex - 1;
- for (let i = unopenIdx; i >= 0; i--) {
- const entry = this.activeFormattingElements.entries[i];
- this._insertElement(entry.token, this.treeAdapter.getNamespaceURI(entry.element));
- entry.element = this.openElements.current;
- }
- }
- }
- //Close elements
- _closeTableCell() {
- this.openElements.generateImpliedEndTags();
- this.openElements.popUntilTableCellPopped();
- this.activeFormattingElements.clearToLastMarker();
- this.insertionMode = InsertionMode.IN_ROW;
- }
- _closePElement() {
- this.openElements.generateImpliedEndTagsWithExclusion(html_js_1.TAG_ID.P);
- this.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.P);
- }
- //Insertion modes
- _resetInsertionMode() {
- for (let i = this.openElements.stackTop; i >= 0; i--) {
- //Insertion mode reset map
- switch (i === 0 && this.fragmentContext ? this.fragmentContextID : this.openElements.tagIDs[i]) {
- case html_js_1.TAG_ID.TR: {
- this.insertionMode = InsertionMode.IN_ROW;
- return;
- }
- case html_js_1.TAG_ID.TBODY:
- case html_js_1.TAG_ID.THEAD:
- case html_js_1.TAG_ID.TFOOT: {
- this.insertionMode = InsertionMode.IN_TABLE_BODY;
- return;
- }
- case html_js_1.TAG_ID.CAPTION: {
- this.insertionMode = InsertionMode.IN_CAPTION;
- return;
- }
- case html_js_1.TAG_ID.COLGROUP: {
- this.insertionMode = InsertionMode.IN_COLUMN_GROUP;
- return;
- }
- case html_js_1.TAG_ID.TABLE: {
- this.insertionMode = InsertionMode.IN_TABLE;
- return;
- }
- case html_js_1.TAG_ID.BODY: {
- this.insertionMode = InsertionMode.IN_BODY;
- return;
- }
- case html_js_1.TAG_ID.FRAMESET: {
- this.insertionMode = InsertionMode.IN_FRAMESET;
- return;
- }
- case html_js_1.TAG_ID.SELECT: {
- this._resetInsertionModeForSelect(i);
- return;
- }
- case html_js_1.TAG_ID.TEMPLATE: {
- this.insertionMode = this.tmplInsertionModeStack[0];
- return;
- }
- case html_js_1.TAG_ID.HTML: {
- this.insertionMode = this.headElement ? InsertionMode.AFTER_HEAD : InsertionMode.BEFORE_HEAD;
- return;
- }
- case html_js_1.TAG_ID.TD:
- case html_js_1.TAG_ID.TH: {
- if (i > 0) {
- this.insertionMode = InsertionMode.IN_CELL;
- return;
- }
- break;
- }
- case html_js_1.TAG_ID.HEAD: {
- if (i > 0) {
- this.insertionMode = InsertionMode.IN_HEAD;
- return;
- }
- break;
- }
- }
- }
- this.insertionMode = InsertionMode.IN_BODY;
- }
- _resetInsertionModeForSelect(selectIdx) {
- if (selectIdx > 0) {
- for (let i = selectIdx - 1; i > 0; i--) {
- const tn = this.openElements.tagIDs[i];
- if (tn === html_js_1.TAG_ID.TEMPLATE) {
- break;
- }
- else if (tn === html_js_1.TAG_ID.TABLE) {
- this.insertionMode = InsertionMode.IN_SELECT_IN_TABLE;
- return;
- }
- }
- }
- this.insertionMode = InsertionMode.IN_SELECT;
- }
- //Foster parenting
- _isElementCausesFosterParenting(tn) {
- return TABLE_STRUCTURE_TAGS.has(tn);
- }
- _shouldFosterParentOnInsertion() {
- return this.fosterParentingEnabled && this._isElementCausesFosterParenting(this.openElements.currentTagId);
- }
- _findFosterParentingLocation() {
- for (let i = this.openElements.stackTop; i >= 0; i--) {
- const openElement = this.openElements.items[i];
- switch (this.openElements.tagIDs[i]) {
- case html_js_1.TAG_ID.TEMPLATE: {
- if (this.treeAdapter.getNamespaceURI(openElement) === html_js_1.NS.HTML) {
- return { parent: this.treeAdapter.getTemplateContent(openElement), beforeElement: null };
- }
- break;
- }
- case html_js_1.TAG_ID.TABLE: {
- const parent = this.treeAdapter.getParentNode(openElement);
- if (parent) {
- return { parent, beforeElement: openElement };
- }
- return { parent: this.openElements.items[i - 1], beforeElement: null };
- }
- default:
- // Do nothing
- }
- }
- return { parent: this.openElements.items[0], beforeElement: null };
- }
- _fosterParentElement(element) {
- const location = this._findFosterParentingLocation();
- if (location.beforeElement) {
- this.treeAdapter.insertBefore(location.parent, element, location.beforeElement);
- }
- else {
- this.treeAdapter.appendChild(location.parent, element);
- }
- }
- //Special elements
- _isSpecialElement(element, id) {
- const ns = this.treeAdapter.getNamespaceURI(element);
- return html_js_1.SPECIAL_ELEMENTS[ns].has(id);
- }
- onCharacter(token) {
- this.skipNextNewLine = false;
- if (this.tokenizer.inForeignNode) {
- characterInForeignContent(this, token);
- return;
- }
- switch (this.insertionMode) {
- case InsertionMode.INITIAL: {
- tokenInInitialMode(this, token);
- break;
- }
- case InsertionMode.BEFORE_HTML: {
- tokenBeforeHtml(this, token);
- break;
- }
- case InsertionMode.BEFORE_HEAD: {
- tokenBeforeHead(this, token);
- break;
- }
- case InsertionMode.IN_HEAD: {
- tokenInHead(this, token);
- break;
- }
- case InsertionMode.IN_HEAD_NO_SCRIPT: {
- tokenInHeadNoScript(this, token);
- break;
- }
- case InsertionMode.AFTER_HEAD: {
- tokenAfterHead(this, token);
- break;
- }
- case InsertionMode.IN_BODY:
- case InsertionMode.IN_CAPTION:
- case InsertionMode.IN_CELL:
- case InsertionMode.IN_TEMPLATE: {
- characterInBody(this, token);
- break;
- }
- case InsertionMode.TEXT:
- case InsertionMode.IN_SELECT:
- case InsertionMode.IN_SELECT_IN_TABLE: {
- this._insertCharacters(token);
- break;
- }
- case InsertionMode.IN_TABLE:
- case InsertionMode.IN_TABLE_BODY:
- case InsertionMode.IN_ROW: {
- characterInTable(this, token);
- break;
- }
- case InsertionMode.IN_TABLE_TEXT: {
- characterInTableText(this, token);
- break;
- }
- case InsertionMode.IN_COLUMN_GROUP: {
- tokenInColumnGroup(this, token);
- break;
- }
- case InsertionMode.AFTER_BODY: {
- tokenAfterBody(this, token);
- break;
- }
- case InsertionMode.AFTER_AFTER_BODY: {
- tokenAfterAfterBody(this, token);
- break;
- }
- default:
- // Do nothing
- }
- }
- onNullCharacter(token) {
- this.skipNextNewLine = false;
- if (this.tokenizer.inForeignNode) {
- nullCharacterInForeignContent(this, token);
- return;
- }
- switch (this.insertionMode) {
- case InsertionMode.INITIAL: {
- tokenInInitialMode(this, token);
- break;
- }
- case InsertionMode.BEFORE_HTML: {
- tokenBeforeHtml(this, token);
- break;
- }
- case InsertionMode.BEFORE_HEAD: {
- tokenBeforeHead(this, token);
- break;
- }
- case InsertionMode.IN_HEAD: {
- tokenInHead(this, token);
- break;
- }
- case InsertionMode.IN_HEAD_NO_SCRIPT: {
- tokenInHeadNoScript(this, token);
- break;
- }
- case InsertionMode.AFTER_HEAD: {
- tokenAfterHead(this, token);
- break;
- }
- case InsertionMode.TEXT: {
- this._insertCharacters(token);
- break;
- }
- case InsertionMode.IN_TABLE:
- case InsertionMode.IN_TABLE_BODY:
- case InsertionMode.IN_ROW: {
- characterInTable(this, token);
- break;
- }
- case InsertionMode.IN_COLUMN_GROUP: {
- tokenInColumnGroup(this, token);
- break;
- }
- case InsertionMode.AFTER_BODY: {
- tokenAfterBody(this, token);
- break;
- }
- case InsertionMode.AFTER_AFTER_BODY: {
- tokenAfterAfterBody(this, token);
- break;
- }
- default:
- // Do nothing
- }
- }
- onComment(token) {
- this.skipNextNewLine = false;
- if (this.currentNotInHTML) {
- appendComment(this, token);
- return;
- }
- switch (this.insertionMode) {
- case InsertionMode.INITIAL:
- case InsertionMode.BEFORE_HTML:
- case InsertionMode.BEFORE_HEAD:
- case InsertionMode.IN_HEAD:
- case InsertionMode.IN_HEAD_NO_SCRIPT:
- case InsertionMode.AFTER_HEAD:
- case InsertionMode.IN_BODY:
- case InsertionMode.IN_TABLE:
- case InsertionMode.IN_CAPTION:
- case InsertionMode.IN_COLUMN_GROUP:
- case InsertionMode.IN_TABLE_BODY:
- case InsertionMode.IN_ROW:
- case InsertionMode.IN_CELL:
- case InsertionMode.IN_SELECT:
- case InsertionMode.IN_SELECT_IN_TABLE:
- case InsertionMode.IN_TEMPLATE:
- case InsertionMode.IN_FRAMESET:
- case InsertionMode.AFTER_FRAMESET: {
- appendComment(this, token);
- break;
- }
- case InsertionMode.IN_TABLE_TEXT: {
- tokenInTableText(this, token);
- break;
- }
- case InsertionMode.AFTER_BODY: {
- appendCommentToRootHtmlElement(this, token);
- break;
- }
- case InsertionMode.AFTER_AFTER_BODY:
- case InsertionMode.AFTER_AFTER_FRAMESET: {
- appendCommentToDocument(this, token);
- break;
- }
- default:
- // Do nothing
- }
- }
- onDoctype(token) {
- this.skipNextNewLine = false;
- switch (this.insertionMode) {
- case InsertionMode.INITIAL: {
- doctypeInInitialMode(this, token);
- break;
- }
- case InsertionMode.BEFORE_HEAD:
- case InsertionMode.IN_HEAD:
- case InsertionMode.IN_HEAD_NO_SCRIPT:
- case InsertionMode.AFTER_HEAD: {
- this._err(token, error_codes_js_1.ERR.misplacedDoctype);
- break;
- }
- case InsertionMode.IN_TABLE_TEXT: {
- tokenInTableText(this, token);
- break;
- }
- default:
- // Do nothing
- }
- }
- onStartTag(token) {
- this.skipNextNewLine = false;
- this.currentToken = token;
- this._processStartTag(token);
- if (token.selfClosing && !token.ackSelfClosing) {
- this._err(token, error_codes_js_1.ERR.nonVoidHtmlElementStartTagWithTrailingSolidus);
- }
- }
- /**
- * Processes a given start tag.
- *
- * `onStartTag` checks if a self-closing tag was recognized. When a token
- * is moved inbetween multiple insertion modes, this check for self-closing
- * could lead to false positives. To avoid this, `_processStartTag` is used
- * for nested calls.
- *
- * @param token The token to process.
- */
- _processStartTag(token) {
- if (this.shouldProcessStartTagTokenInForeignContent(token)) {
- startTagInForeignContent(this, token);
- }
- else {
- this._startTagOutsideForeignContent(token);
- }
- }
- _startTagOutsideForeignContent(token) {
- switch (this.insertionMode) {
- case InsertionMode.INITIAL: {
- tokenInInitialMode(this, token);
- break;
- }
- case InsertionMode.BEFORE_HTML: {
- startTagBeforeHtml(this, token);
- break;
- }
- case InsertionMode.BEFORE_HEAD: {
- startTagBeforeHead(this, token);
- break;
- }
- case InsertionMode.IN_HEAD: {
- startTagInHead(this, token);
- break;
- }
- case InsertionMode.IN_HEAD_NO_SCRIPT: {
- startTagInHeadNoScript(this, token);
- break;
- }
- case InsertionMode.AFTER_HEAD: {
- startTagAfterHead(this, token);
- break;
- }
- case InsertionMode.IN_BODY: {
- startTagInBody(this, token);
- break;
- }
- case InsertionMode.IN_TABLE: {
- startTagInTable(this, token);
- break;
- }
- case InsertionMode.IN_TABLE_TEXT: {
- tokenInTableText(this, token);
- break;
- }
- case InsertionMode.IN_CAPTION: {
- startTagInCaption(this, token);
- break;
- }
- case InsertionMode.IN_COLUMN_GROUP: {
- startTagInColumnGroup(this, token);
- break;
- }
- case InsertionMode.IN_TABLE_BODY: {
- startTagInTableBody(this, token);
- break;
- }
- case InsertionMode.IN_ROW: {
- startTagInRow(this, token);
- break;
- }
- case InsertionMode.IN_CELL: {
- startTagInCell(this, token);
- break;
- }
- case InsertionMode.IN_SELECT: {
- startTagInSelect(this, token);
- break;
- }
- case InsertionMode.IN_SELECT_IN_TABLE: {
- startTagInSelectInTable(this, token);
- break;
- }
- case InsertionMode.IN_TEMPLATE: {
- startTagInTemplate(this, token);
- break;
- }
- case InsertionMode.AFTER_BODY: {
- startTagAfterBody(this, token);
- break;
- }
- case InsertionMode.IN_FRAMESET: {
- startTagInFrameset(this, token);
- break;
- }
- case InsertionMode.AFTER_FRAMESET: {
- startTagAfterFrameset(this, token);
- break;
- }
- case InsertionMode.AFTER_AFTER_BODY: {
- startTagAfterAfterBody(this, token);
- break;
- }
- case InsertionMode.AFTER_AFTER_FRAMESET: {
- startTagAfterAfterFrameset(this, token);
- break;
- }
- default:
- // Do nothing
- }
- }
- onEndTag(token) {
- this.skipNextNewLine = false;
- this.currentToken = token;
- if (this.currentNotInHTML) {
- endTagInForeignContent(this, token);
- }
- else {
- this._endTagOutsideForeignContent(token);
- }
- }
- _endTagOutsideForeignContent(token) {
- switch (this.insertionMode) {
- case InsertionMode.INITIAL: {
- tokenInInitialMode(this, token);
- break;
- }
- case InsertionMode.BEFORE_HTML: {
- endTagBeforeHtml(this, token);
- break;
- }
- case InsertionMode.BEFORE_HEAD: {
- endTagBeforeHead(this, token);
- break;
- }
- case InsertionMode.IN_HEAD: {
- endTagInHead(this, token);
- break;
- }
- case InsertionMode.IN_HEAD_NO_SCRIPT: {
- endTagInHeadNoScript(this, token);
- break;
- }
- case InsertionMode.AFTER_HEAD: {
- endTagAfterHead(this, token);
- break;
- }
- case InsertionMode.IN_BODY: {
- endTagInBody(this, token);
- break;
- }
- case InsertionMode.TEXT: {
- endTagInText(this, token);
- break;
- }
- case InsertionMode.IN_TABLE: {
- endTagInTable(this, token);
- break;
- }
- case InsertionMode.IN_TABLE_TEXT: {
- tokenInTableText(this, token);
- break;
- }
- case InsertionMode.IN_CAPTION: {
- endTagInCaption(this, token);
- break;
- }
- case InsertionMode.IN_COLUMN_GROUP: {
- endTagInColumnGroup(this, token);
- break;
- }
- case InsertionMode.IN_TABLE_BODY: {
- endTagInTableBody(this, token);
- break;
- }
- case InsertionMode.IN_ROW: {
- endTagInRow(this, token);
- break;
- }
- case InsertionMode.IN_CELL: {
- endTagInCell(this, token);
- break;
- }
- case InsertionMode.IN_SELECT: {
- endTagInSelect(this, token);
- break;
- }
- case InsertionMode.IN_SELECT_IN_TABLE: {
- endTagInSelectInTable(this, token);
- break;
- }
- case InsertionMode.IN_TEMPLATE: {
- endTagInTemplate(this, token);
- break;
- }
- case InsertionMode.AFTER_BODY: {
- endTagAfterBody(this, token);
- break;
- }
- case InsertionMode.IN_FRAMESET: {
- endTagInFrameset(this, token);
- break;
- }
- case InsertionMode.AFTER_FRAMESET: {
- endTagAfterFrameset(this, token);
- break;
- }
- case InsertionMode.AFTER_AFTER_BODY: {
- tokenAfterAfterBody(this, token);
- break;
- }
- default:
- // Do nothing
- }
- }
- onEof(token) {
- switch (this.insertionMode) {
- case InsertionMode.INITIAL: {
- tokenInInitialMode(this, token);
- break;
- }
- case InsertionMode.BEFORE_HTML: {
- tokenBeforeHtml(this, token);
- break;
- }
- case InsertionMode.BEFORE_HEAD: {
- tokenBeforeHead(this, token);
- break;
- }
- case InsertionMode.IN_HEAD: {
- tokenInHead(this, token);
- break;
- }
- case InsertionMode.IN_HEAD_NO_SCRIPT: {
- tokenInHeadNoScript(this, token);
- break;
- }
- case InsertionMode.AFTER_HEAD: {
- tokenAfterHead(this, token);
- break;
- }
- case InsertionMode.IN_BODY:
- case InsertionMode.IN_TABLE:
- case InsertionMode.IN_CAPTION:
- case InsertionMode.IN_COLUMN_GROUP:
- case InsertionMode.IN_TABLE_BODY:
- case InsertionMode.IN_ROW:
- case InsertionMode.IN_CELL:
- case InsertionMode.IN_SELECT:
- case InsertionMode.IN_SELECT_IN_TABLE: {
- eofInBody(this, token);
- break;
- }
- case InsertionMode.TEXT: {
- eofInText(this, token);
- break;
- }
- case InsertionMode.IN_TABLE_TEXT: {
- tokenInTableText(this, token);
- break;
- }
- case InsertionMode.IN_TEMPLATE: {
- eofInTemplate(this, token);
- break;
- }
- case InsertionMode.AFTER_BODY:
- case InsertionMode.IN_FRAMESET:
- case InsertionMode.AFTER_FRAMESET:
- case InsertionMode.AFTER_AFTER_BODY:
- case InsertionMode.AFTER_AFTER_FRAMESET: {
- stopParsing(this, token);
- break;
- }
- default:
- // Do nothing
- }
- }
- onWhitespaceCharacter(token) {
- if (this.skipNextNewLine) {
- this.skipNextNewLine = false;
- if (token.chars.charCodeAt(0) === unicode.CODE_POINTS.LINE_FEED) {
- if (token.chars.length === 1) {
- return;
- }
- token.chars = token.chars.substr(1);
- }
- }
- if (this.tokenizer.inForeignNode) {
- this._insertCharacters(token);
- return;
- }
- switch (this.insertionMode) {
- case InsertionMode.IN_HEAD:
- case InsertionMode.IN_HEAD_NO_SCRIPT:
- case InsertionMode.AFTER_HEAD:
- case InsertionMode.TEXT:
- case InsertionMode.IN_COLUMN_GROUP:
- case InsertionMode.IN_SELECT:
- case InsertionMode.IN_SELECT_IN_TABLE:
- case InsertionMode.IN_FRAMESET:
- case InsertionMode.AFTER_FRAMESET: {
- this._insertCharacters(token);
- break;
- }
- case InsertionMode.IN_BODY:
- case InsertionMode.IN_CAPTION:
- case InsertionMode.IN_CELL:
- case InsertionMode.IN_TEMPLATE:
- case InsertionMode.AFTER_BODY:
- case InsertionMode.AFTER_AFTER_BODY:
- case InsertionMode.AFTER_AFTER_FRAMESET: {
- whitespaceCharacterInBody(this, token);
- break;
- }
- case InsertionMode.IN_TABLE:
- case InsertionMode.IN_TABLE_BODY:
- case InsertionMode.IN_ROW: {
- characterInTable(this, token);
- break;
- }
- case InsertionMode.IN_TABLE_TEXT: {
- whitespaceCharacterInTableText(this, token);
- break;
- }
- default:
- // Do nothing
- }
- }
- }
- exports.Parser = Parser;
- //Adoption agency algorithm
- //(see: http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construction.html#adoptionAgency)
- //------------------------------------------------------------------
- //Steps 5-8 of the algorithm
- function aaObtainFormattingElementEntry(p, token) {
- let formattingElementEntry = p.activeFormattingElements.getElementEntryInScopeWithTagName(token.tagName);
- if (formattingElementEntry) {
- if (!p.openElements.contains(formattingElementEntry.element)) {
- p.activeFormattingElements.removeEntry(formattingElementEntry);
- formattingElementEntry = null;
- }
- else if (!p.openElements.hasInScope(token.tagID)) {
- formattingElementEntry = null;
- }
- }
- else {
- genericEndTagInBody(p, token);
- }
- return formattingElementEntry;
- }
- //Steps 9 and 10 of the algorithm
- function aaObtainFurthestBlock(p, formattingElementEntry) {
- let furthestBlock = null;
- let idx = p.openElements.stackTop;
- for (; idx >= 0; idx--) {
- const element = p.openElements.items[idx];
- if (element === formattingElementEntry.element) {
- break;
- }
- if (p._isSpecialElement(element, p.openElements.tagIDs[idx])) {
- furthestBlock = element;
- }
- }
- if (!furthestBlock) {
- p.openElements.shortenToLength(idx < 0 ? 0 : idx);
- p.activeFormattingElements.removeEntry(formattingElementEntry);
- }
- return furthestBlock;
- }
- //Step 13 of the algorithm
- function aaInnerLoop(p, furthestBlock, formattingElement) {
- let lastElement = furthestBlock;
- let nextElement = p.openElements.getCommonAncestor(furthestBlock);
- for (let i = 0, element = nextElement; element !== formattingElement; i++, element = nextElement) {
- //NOTE: store the next element for the next loop iteration (it may be deleted from the stack by step 9.5)
- nextElement = p.openElements.getCommonAncestor(element);
- const elementEntry = p.activeFormattingElements.getElementEntry(element);
- const counterOverflow = elementEntry && i >= AA_INNER_LOOP_ITER;
- const shouldRemoveFromOpenElements = !elementEntry || counterOverflow;
- if (shouldRemoveFromOpenElements) {
- if (counterOverflow) {
- p.activeFormattingElements.removeEntry(elementEntry);
- }
- p.openElements.remove(element);
- }
- else {
- element = aaRecreateElementFromEntry(p, elementEntry);
- if (lastElement === furthestBlock) {
- p.activeFormattingElements.bookmark = elementEntry;
- }
- p.treeAdapter.detachNode(lastElement);
- p.treeAdapter.appendChild(element, lastElement);
- lastElement = element;
- }
- }
- return lastElement;
- }
- //Step 13.7 of the algorithm
- function aaRecreateElementFromEntry(p, elementEntry) {
- const ns = p.treeAdapter.getNamespaceURI(elementEntry.element);
- const newElement = p.treeAdapter.createElement(elementEntry.token.tagName, ns, elementEntry.token.attrs);
- p.openElements.replace(elementEntry.element, newElement);
- elementEntry.element = newElement;
- return newElement;
- }
- //Step 14 of the algorithm
- function aaInsertLastNodeInCommonAncestor(p, commonAncestor, lastElement) {
- const tn = p.treeAdapter.getTagName(commonAncestor);
- const tid = (0, html_js_1.getTagID)(tn);
- if (p._isElementCausesFosterParenting(tid)) {
- p._fosterParentElement(lastElement);
- }
- else {
- const ns = p.treeAdapter.getNamespaceURI(commonAncestor);
- if (tid === html_js_1.TAG_ID.TEMPLATE && ns === html_js_1.NS.HTML) {
- commonAncestor = p.treeAdapter.getTemplateContent(commonAncestor);
- }
- p.treeAdapter.appendChild(commonAncestor, lastElement);
- }
- }
- //Steps 15-19 of the algorithm
- function aaReplaceFormattingElement(p, furthestBlock, formattingElementEntry) {
- const ns = p.treeAdapter.getNamespaceURI(formattingElementEntry.element);
- const { token } = formattingElementEntry;
- const newElement = p.treeAdapter.createElement(token.tagName, ns, token.attrs);
- p._adoptNodes(furthestBlock, newElement);
- p.treeAdapter.appendChild(furthestBlock, newElement);
- p.activeFormattingElements.insertElementAfterBookmark(newElement, token);
- p.activeFormattingElements.removeEntry(formattingElementEntry);
- p.openElements.remove(formattingElementEntry.element);
- p.openElements.insertAfter(furthestBlock, newElement, token.tagID);
- }
- //Algorithm entry point
- function callAdoptionAgency(p, token) {
- for (let i = 0; i < AA_OUTER_LOOP_ITER; i++) {
- const formattingElementEntry = aaObtainFormattingElementEntry(p, token);
- if (!formattingElementEntry) {
- break;
- }
- const furthestBlock = aaObtainFurthestBlock(p, formattingElementEntry);
- if (!furthestBlock) {
- break;
- }
- p.activeFormattingElements.bookmark = formattingElementEntry;
- const lastElement = aaInnerLoop(p, furthestBlock, formattingElementEntry.element);
- const commonAncestor = p.openElements.getCommonAncestor(formattingElementEntry.element);
- p.treeAdapter.detachNode(lastElement);
- if (commonAncestor)
- aaInsertLastNodeInCommonAncestor(p, commonAncestor, lastElement);
- aaReplaceFormattingElement(p, furthestBlock, formattingElementEntry);
- }
- }
- //Generic token handlers
- //------------------------------------------------------------------
- function appendComment(p, token) {
- p._appendCommentNode(token, p.openElements.currentTmplContentOrNode);
- }
- function appendCommentToRootHtmlElement(p, token) {
- p._appendCommentNode(token, p.openElements.items[0]);
- }
- function appendCommentToDocument(p, token) {
- p._appendCommentNode(token, p.document);
- }
- function stopParsing(p, token) {
- p.stopped = true;
- // NOTE: Set end locations for elements that remain on the open element stack.
- if (token.location) {
- // NOTE: If we are not in a fragment, `html` and `body` will stay on the stack.
- // This is a problem, as we might overwrite their end position here.
- const target = p.fragmentContext ? 0 : 2;
- for (let i = p.openElements.stackTop; i >= target; i--) {
- p._setEndLocation(p.openElements.items[i], token);
- }
- // Handle `html` and `body`
- if (!p.fragmentContext && p.openElements.stackTop >= 0) {
- const htmlElement = p.openElements.items[0];
- const htmlLocation = p.treeAdapter.getNodeSourceCodeLocation(htmlElement);
- if (htmlLocation && !htmlLocation.endTag) {
- p._setEndLocation(htmlElement, token);
- if (p.openElements.stackTop >= 1) {
- const bodyElement = p.openElements.items[1];
- const bodyLocation = p.treeAdapter.getNodeSourceCodeLocation(bodyElement);
- if (bodyLocation && !bodyLocation.endTag) {
- p._setEndLocation(bodyElement, token);
- }
- }
- }
- }
- }
- }
- // The "initial" insertion mode
- //------------------------------------------------------------------
- function doctypeInInitialMode(p, token) {
- p._setDocumentType(token);
- const mode = token.forceQuirks ? html_js_1.DOCUMENT_MODE.QUIRKS : doctype.getDocumentMode(token);
- if (!doctype.isConforming(token)) {
- p._err(token, error_codes_js_1.ERR.nonConformingDoctype);
- }
- p.treeAdapter.setDocumentMode(p.document, mode);
- p.insertionMode = InsertionMode.BEFORE_HTML;
- }
- function tokenInInitialMode(p, token) {
- p._err(token, error_codes_js_1.ERR.missingDoctype, true);
- p.treeAdapter.setDocumentMode(p.document, html_js_1.DOCUMENT_MODE.QUIRKS);
- p.insertionMode = InsertionMode.BEFORE_HTML;
- p._processToken(token);
- }
- // The "before html" insertion mode
- //------------------------------------------------------------------
- function startTagBeforeHtml(p, token) {
- if (token.tagID === html_js_1.TAG_ID.HTML) {
- p._insertElement(token, html_js_1.NS.HTML);
- p.insertionMode = InsertionMode.BEFORE_HEAD;
- }
- else {
- tokenBeforeHtml(p, token);
- }
- }
- function endTagBeforeHtml(p, token) {
- const tn = token.tagID;
- if (tn === html_js_1.TAG_ID.HTML || tn === html_js_1.TAG_ID.HEAD || tn === html_js_1.TAG_ID.BODY || tn === html_js_1.TAG_ID.BR) {
- tokenBeforeHtml(p, token);
- }
- }
- function tokenBeforeHtml(p, token) {
- p._insertFakeRootElement();
- p.insertionMode = InsertionMode.BEFORE_HEAD;
- p._processToken(token);
- }
- // The "before head" insertion mode
- //------------------------------------------------------------------
- function startTagBeforeHead(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.HTML: {
- startTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.HEAD: {
- p._insertElement(token, html_js_1.NS.HTML);
- p.headElement = p.openElements.current;
- p.insertionMode = InsertionMode.IN_HEAD;
- break;
- }
- default: {
- tokenBeforeHead(p, token);
- }
- }
- }
- function endTagBeforeHead(p, token) {
- const tn = token.tagID;
- if (tn === html_js_1.TAG_ID.HEAD || tn === html_js_1.TAG_ID.BODY || tn === html_js_1.TAG_ID.HTML || tn === html_js_1.TAG_ID.BR) {
- tokenBeforeHead(p, token);
- }
- else {
- p._err(token, error_codes_js_1.ERR.endTagWithoutMatchingOpenElement);
- }
- }
- function tokenBeforeHead(p, token) {
- p._insertFakeElement(html_js_1.TAG_NAMES.HEAD, html_js_1.TAG_ID.HEAD);
- p.headElement = p.openElements.current;
- p.insertionMode = InsertionMode.IN_HEAD;
- p._processToken(token);
- }
- // The "in head" insertion mode
- //------------------------------------------------------------------
- function startTagInHead(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.HTML: {
- startTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.BASE:
- case html_js_1.TAG_ID.BASEFONT:
- case html_js_1.TAG_ID.BGSOUND:
- case html_js_1.TAG_ID.LINK:
- case html_js_1.TAG_ID.META: {
- p._appendElement(token, html_js_1.NS.HTML);
- token.ackSelfClosing = true;
- break;
- }
- case html_js_1.TAG_ID.TITLE: {
- p._switchToTextParsing(token, index_js_1.TokenizerMode.RCDATA);
- break;
- }
- case html_js_1.TAG_ID.NOSCRIPT: {
- if (p.options.scriptingEnabled) {
- p._switchToTextParsing(token, index_js_1.TokenizerMode.RAWTEXT);
- }
- else {
- p._insertElement(token, html_js_1.NS.HTML);
- p.insertionMode = InsertionMode.IN_HEAD_NO_SCRIPT;
- }
- break;
- }
- case html_js_1.TAG_ID.NOFRAMES:
- case html_js_1.TAG_ID.STYLE: {
- p._switchToTextParsing(token, index_js_1.TokenizerMode.RAWTEXT);
- break;
- }
- case html_js_1.TAG_ID.SCRIPT: {
- p._switchToTextParsing(token, index_js_1.TokenizerMode.SCRIPT_DATA);
- break;
- }
- case html_js_1.TAG_ID.TEMPLATE: {
- p._insertTemplate(token);
- p.activeFormattingElements.insertMarker();
- p.framesetOk = false;
- p.insertionMode = InsertionMode.IN_TEMPLATE;
- p.tmplInsertionModeStack.unshift(InsertionMode.IN_TEMPLATE);
- break;
- }
- case html_js_1.TAG_ID.HEAD: {
- p._err(token, error_codes_js_1.ERR.misplacedStartTagForHeadElement);
- break;
- }
- default: {
- tokenInHead(p, token);
- }
- }
- }
- function endTagInHead(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.HEAD: {
- p.openElements.pop();
- p.insertionMode = InsertionMode.AFTER_HEAD;
- break;
- }
- case html_js_1.TAG_ID.BODY:
- case html_js_1.TAG_ID.BR:
- case html_js_1.TAG_ID.HTML: {
- tokenInHead(p, token);
- break;
- }
- case html_js_1.TAG_ID.TEMPLATE: {
- templateEndTagInHead(p, token);
- break;
- }
- default: {
- p._err(token, error_codes_js_1.ERR.endTagWithoutMatchingOpenElement);
- }
- }
- }
- function templateEndTagInHead(p, token) {
- if (p.openElements.tmplCount > 0) {
- p.openElements.generateImpliedEndTagsThoroughly();
- if (p.openElements.currentTagId !== html_js_1.TAG_ID.TEMPLATE) {
- p._err(token, error_codes_js_1.ERR.closingOfElementWithOpenChildElements);
- }
- p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.TEMPLATE);
- p.activeFormattingElements.clearToLastMarker();
- p.tmplInsertionModeStack.shift();
- p._resetInsertionMode();
- }
- else {
- p._err(token, error_codes_js_1.ERR.endTagWithoutMatchingOpenElement);
- }
- }
- function tokenInHead(p, token) {
- p.openElements.pop();
- p.insertionMode = InsertionMode.AFTER_HEAD;
- p._processToken(token);
- }
- // The "in head no script" insertion mode
- //------------------------------------------------------------------
- function startTagInHeadNoScript(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.HTML: {
- startTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.BASEFONT:
- case html_js_1.TAG_ID.BGSOUND:
- case html_js_1.TAG_ID.HEAD:
- case html_js_1.TAG_ID.LINK:
- case html_js_1.TAG_ID.META:
- case html_js_1.TAG_ID.NOFRAMES:
- case html_js_1.TAG_ID.STYLE: {
- startTagInHead(p, token);
- break;
- }
- case html_js_1.TAG_ID.NOSCRIPT: {
- p._err(token, error_codes_js_1.ERR.nestedNoscriptInHead);
- break;
- }
- default: {
- tokenInHeadNoScript(p, token);
- }
- }
- }
- function endTagInHeadNoScript(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.NOSCRIPT: {
- p.openElements.pop();
- p.insertionMode = InsertionMode.IN_HEAD;
- break;
- }
- case html_js_1.TAG_ID.BR: {
- tokenInHeadNoScript(p, token);
- break;
- }
- default: {
- p._err(token, error_codes_js_1.ERR.endTagWithoutMatchingOpenElement);
- }
- }
- }
- function tokenInHeadNoScript(p, token) {
- const errCode = token.type === token_js_1.TokenType.EOF ? error_codes_js_1.ERR.openElementsLeftAfterEof : error_codes_js_1.ERR.disallowedContentInNoscriptInHead;
- p._err(token, errCode);
- p.openElements.pop();
- p.insertionMode = InsertionMode.IN_HEAD;
- p._processToken(token);
- }
- // The "after head" insertion mode
- //------------------------------------------------------------------
- function startTagAfterHead(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.HTML: {
- startTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.BODY: {
- p._insertElement(token, html_js_1.NS.HTML);
- p.framesetOk = false;
- p.insertionMode = InsertionMode.IN_BODY;
- break;
- }
- case html_js_1.TAG_ID.FRAMESET: {
- p._insertElement(token, html_js_1.NS.HTML);
- p.insertionMode = InsertionMode.IN_FRAMESET;
- break;
- }
- case html_js_1.TAG_ID.BASE:
- case html_js_1.TAG_ID.BASEFONT:
- case html_js_1.TAG_ID.BGSOUND:
- case html_js_1.TAG_ID.LINK:
- case html_js_1.TAG_ID.META:
- case html_js_1.TAG_ID.NOFRAMES:
- case html_js_1.TAG_ID.SCRIPT:
- case html_js_1.TAG_ID.STYLE:
- case html_js_1.TAG_ID.TEMPLATE:
- case html_js_1.TAG_ID.TITLE: {
- p._err(token, error_codes_js_1.ERR.abandonedHeadElementChild);
- p.openElements.push(p.headElement, html_js_1.TAG_ID.HEAD);
- startTagInHead(p, token);
- p.openElements.remove(p.headElement);
- break;
- }
- case html_js_1.TAG_ID.HEAD: {
- p._err(token, error_codes_js_1.ERR.misplacedStartTagForHeadElement);
- break;
- }
- default: {
- tokenAfterHead(p, token);
- }
- }
- }
- function endTagAfterHead(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.BODY:
- case html_js_1.TAG_ID.HTML:
- case html_js_1.TAG_ID.BR: {
- tokenAfterHead(p, token);
- break;
- }
- case html_js_1.TAG_ID.TEMPLATE: {
- templateEndTagInHead(p, token);
- break;
- }
- default: {
- p._err(token, error_codes_js_1.ERR.endTagWithoutMatchingOpenElement);
- }
- }
- }
- function tokenAfterHead(p, token) {
- p._insertFakeElement(html_js_1.TAG_NAMES.BODY, html_js_1.TAG_ID.BODY);
- p.insertionMode = InsertionMode.IN_BODY;
- modeInBody(p, token);
- }
- // The "in body" insertion mode
- //------------------------------------------------------------------
- function modeInBody(p, token) {
- switch (token.type) {
- case token_js_1.TokenType.CHARACTER: {
- characterInBody(p, token);
- break;
- }
- case token_js_1.TokenType.WHITESPACE_CHARACTER: {
- whitespaceCharacterInBody(p, token);
- break;
- }
- case token_js_1.TokenType.COMMENT: {
- appendComment(p, token);
- break;
- }
- case token_js_1.TokenType.START_TAG: {
- startTagInBody(p, token);
- break;
- }
- case token_js_1.TokenType.END_TAG: {
- endTagInBody(p, token);
- break;
- }
- case token_js_1.TokenType.EOF: {
- eofInBody(p, token);
- break;
- }
- default:
- // Do nothing
- }
- }
- function whitespaceCharacterInBody(p, token) {
- p._reconstructActiveFormattingElements();
- p._insertCharacters(token);
- }
- function characterInBody(p, token) {
- p._reconstructActiveFormattingElements();
- p._insertCharacters(token);
- p.framesetOk = false;
- }
- function htmlStartTagInBody(p, token) {
- if (p.openElements.tmplCount === 0) {
- p.treeAdapter.adoptAttributes(p.openElements.items[0], token.attrs);
- }
- }
- function bodyStartTagInBody(p, token) {
- const bodyElement = p.openElements.tryPeekProperlyNestedBodyElement();
- if (bodyElement && p.openElements.tmplCount === 0) {
- p.framesetOk = false;
- p.treeAdapter.adoptAttributes(bodyElement, token.attrs);
- }
- }
- function framesetStartTagInBody(p, token) {
- const bodyElement = p.openElements.tryPeekProperlyNestedBodyElement();
- if (p.framesetOk && bodyElement) {
- p.treeAdapter.detachNode(bodyElement);
- p.openElements.popAllUpToHtmlElement();
- p._insertElement(token, html_js_1.NS.HTML);
- p.insertionMode = InsertionMode.IN_FRAMESET;
- }
- }
- function addressStartTagInBody(p, token) {
- if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
- p._closePElement();
- }
- p._insertElement(token, html_js_1.NS.HTML);
- }
- function numberedHeaderStartTagInBody(p, token) {
- if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
- p._closePElement();
- }
- if ((0, html_js_1.isNumberedHeader)(p.openElements.currentTagId)) {
- p.openElements.pop();
- }
- p._insertElement(token, html_js_1.NS.HTML);
- }
- function preStartTagInBody(p, token) {
- if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
- p._closePElement();
- }
- p._insertElement(token, html_js_1.NS.HTML);
- //NOTE: If the next token is a U+000A LINE FEED (LF) character token, then ignore that token and move
- //on to the next one. (Newlines at the start of pre blocks are ignored as an authoring convenience.)
- p.skipNextNewLine = true;
- p.framesetOk = false;
- }
- function formStartTagInBody(p, token) {
- const inTemplate = p.openElements.tmplCount > 0;
- if (!p.formElement || inTemplate) {
- if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
- p._closePElement();
- }
- p._insertElement(token, html_js_1.NS.HTML);
- if (!inTemplate) {
- p.formElement = p.openElements.current;
- }
- }
- }
- function listItemStartTagInBody(p, token) {
- p.framesetOk = false;
- const tn = token.tagID;
- for (let i = p.openElements.stackTop; i >= 0; i--) {
- const elementId = p.openElements.tagIDs[i];
- if ((tn === html_js_1.TAG_ID.LI && elementId === html_js_1.TAG_ID.LI) ||
- ((tn === html_js_1.TAG_ID.DD || tn === html_js_1.TAG_ID.DT) && (elementId === html_js_1.TAG_ID.DD || elementId === html_js_1.TAG_ID.DT))) {
- p.openElements.generateImpliedEndTagsWithExclusion(elementId);
- p.openElements.popUntilTagNamePopped(elementId);
- break;
- }
- if (elementId !== html_js_1.TAG_ID.ADDRESS &&
- elementId !== html_js_1.TAG_ID.DIV &&
- elementId !== html_js_1.TAG_ID.P &&
- p._isSpecialElement(p.openElements.items[i], elementId)) {
- break;
- }
- }
- if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
- p._closePElement();
- }
- p._insertElement(token, html_js_1.NS.HTML);
- }
- function plaintextStartTagInBody(p, token) {
- if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
- p._closePElement();
- }
- p._insertElement(token, html_js_1.NS.HTML);
- p.tokenizer.state = index_js_1.TokenizerMode.PLAINTEXT;
- }
- function buttonStartTagInBody(p, token) {
- if (p.openElements.hasInScope(html_js_1.TAG_ID.BUTTON)) {
- p.openElements.generateImpliedEndTags();
- p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.BUTTON);
- }
- p._reconstructActiveFormattingElements();
- p._insertElement(token, html_js_1.NS.HTML);
- p.framesetOk = false;
- }
- function aStartTagInBody(p, token) {
- const activeElementEntry = p.activeFormattingElements.getElementEntryInScopeWithTagName(html_js_1.TAG_NAMES.A);
- if (activeElementEntry) {
- callAdoptionAgency(p, token);
- p.openElements.remove(activeElementEntry.element);
- p.activeFormattingElements.removeEntry(activeElementEntry);
- }
- p._reconstructActiveFormattingElements();
- p._insertElement(token, html_js_1.NS.HTML);
- p.activeFormattingElements.pushElement(p.openElements.current, token);
- }
- function bStartTagInBody(p, token) {
- p._reconstructActiveFormattingElements();
- p._insertElement(token, html_js_1.NS.HTML);
- p.activeFormattingElements.pushElement(p.openElements.current, token);
- }
- function nobrStartTagInBody(p, token) {
- p._reconstructActiveFormattingElements();
- if (p.openElements.hasInScope(html_js_1.TAG_ID.NOBR)) {
- callAdoptionAgency(p, token);
- p._reconstructActiveFormattingElements();
- }
- p._insertElement(token, html_js_1.NS.HTML);
- p.activeFormattingElements.pushElement(p.openElements.current, token);
- }
- function appletStartTagInBody(p, token) {
- p._reconstructActiveFormattingElements();
- p._insertElement(token, html_js_1.NS.HTML);
- p.activeFormattingElements.insertMarker();
- p.framesetOk = false;
- }
- function tableStartTagInBody(p, token) {
- if (p.treeAdapter.getDocumentMode(p.document) !== html_js_1.DOCUMENT_MODE.QUIRKS && p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
- p._closePElement();
- }
- p._insertElement(token, html_js_1.NS.HTML);
- p.framesetOk = false;
- p.insertionMode = InsertionMode.IN_TABLE;
- }
- function areaStartTagInBody(p, token) {
- p._reconstructActiveFormattingElements();
- p._appendElement(token, html_js_1.NS.HTML);
- p.framesetOk = false;
- token.ackSelfClosing = true;
- }
- function isHiddenInput(token) {
- const inputType = (0, token_js_1.getTokenAttr)(token, html_js_1.ATTRS.TYPE);
- return inputType != null && inputType.toLowerCase() === HIDDEN_INPUT_TYPE;
- }
- function inputStartTagInBody(p, token) {
- p._reconstructActiveFormattingElements();
- p._appendElement(token, html_js_1.NS.HTML);
- if (!isHiddenInput(token)) {
- p.framesetOk = false;
- }
- token.ackSelfClosing = true;
- }
- function paramStartTagInBody(p, token) {
- p._appendElement(token, html_js_1.NS.HTML);
- token.ackSelfClosing = true;
- }
- function hrStartTagInBody(p, token) {
- if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
- p._closePElement();
- }
- p._appendElement(token, html_js_1.NS.HTML);
- p.framesetOk = false;
- token.ackSelfClosing = true;
- }
- function imageStartTagInBody(p, token) {
- token.tagName = html_js_1.TAG_NAMES.IMG;
- token.tagID = html_js_1.TAG_ID.IMG;
- areaStartTagInBody(p, token);
- }
- function textareaStartTagInBody(p, token) {
- p._insertElement(token, html_js_1.NS.HTML);
- //NOTE: If the next token is a U+000A LINE FEED (LF) character token, then ignore that token and move
- //on to the next one. (Newlines at the start of textarea elements are ignored as an authoring convenience.)
- p.skipNextNewLine = true;
- p.tokenizer.state = index_js_1.TokenizerMode.RCDATA;
- p.originalInsertionMode = p.insertionMode;
- p.framesetOk = false;
- p.insertionMode = InsertionMode.TEXT;
- }
- function xmpStartTagInBody(p, token) {
- if (p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
- p._closePElement();
- }
- p._reconstructActiveFormattingElements();
- p.framesetOk = false;
- p._switchToTextParsing(token, index_js_1.TokenizerMode.RAWTEXT);
- }
- function iframeStartTagInBody(p, token) {
- p.framesetOk = false;
- p._switchToTextParsing(token, index_js_1.TokenizerMode.RAWTEXT);
- }
- //NOTE: here we assume that we always act as an user agent with enabled plugins, so we parse
- //<noembed> as rawtext.
- function noembedStartTagInBody(p, token) {
- p._switchToTextParsing(token, index_js_1.TokenizerMode.RAWTEXT);
- }
- function selectStartTagInBody(p, token) {
- p._reconstructActiveFormattingElements();
- p._insertElement(token, html_js_1.NS.HTML);
- p.framesetOk = false;
- p.insertionMode =
- p.insertionMode === InsertionMode.IN_TABLE ||
- p.insertionMode === InsertionMode.IN_CAPTION ||
- p.insertionMode === InsertionMode.IN_TABLE_BODY ||
- p.insertionMode === InsertionMode.IN_ROW ||
- p.insertionMode === InsertionMode.IN_CELL
- ? InsertionMode.IN_SELECT_IN_TABLE
- : InsertionMode.IN_SELECT;
- }
- function optgroupStartTagInBody(p, token) {
- if (p.openElements.currentTagId === html_js_1.TAG_ID.OPTION) {
- p.openElements.pop();
- }
- p._reconstructActiveFormattingElements();
- p._insertElement(token, html_js_1.NS.HTML);
- }
- function rbStartTagInBody(p, token) {
- if (p.openElements.hasInScope(html_js_1.TAG_ID.RUBY)) {
- p.openElements.generateImpliedEndTags();
- }
- p._insertElement(token, html_js_1.NS.HTML);
- }
- function rtStartTagInBody(p, token) {
- if (p.openElements.hasInScope(html_js_1.TAG_ID.RUBY)) {
- p.openElements.generateImpliedEndTagsWithExclusion(html_js_1.TAG_ID.RTC);
- }
- p._insertElement(token, html_js_1.NS.HTML);
- }
- function mathStartTagInBody(p, token) {
- p._reconstructActiveFormattingElements();
- foreignContent.adjustTokenMathMLAttrs(token);
- foreignContent.adjustTokenXMLAttrs(token);
- if (token.selfClosing) {
- p._appendElement(token, html_js_1.NS.MATHML);
- }
- else {
- p._insertElement(token, html_js_1.NS.MATHML);
- }
- token.ackSelfClosing = true;
- }
- function svgStartTagInBody(p, token) {
- p._reconstructActiveFormattingElements();
- foreignContent.adjustTokenSVGAttrs(token);
- foreignContent.adjustTokenXMLAttrs(token);
- if (token.selfClosing) {
- p._appendElement(token, html_js_1.NS.SVG);
- }
- else {
- p._insertElement(token, html_js_1.NS.SVG);
- }
- token.ackSelfClosing = true;
- }
- function genericStartTagInBody(p, token) {
- p._reconstructActiveFormattingElements();
- p._insertElement(token, html_js_1.NS.HTML);
- }
- function startTagInBody(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.I:
- case html_js_1.TAG_ID.S:
- case html_js_1.TAG_ID.B:
- case html_js_1.TAG_ID.U:
- case html_js_1.TAG_ID.EM:
- case html_js_1.TAG_ID.TT:
- case html_js_1.TAG_ID.BIG:
- case html_js_1.TAG_ID.CODE:
- case html_js_1.TAG_ID.FONT:
- case html_js_1.TAG_ID.SMALL:
- case html_js_1.TAG_ID.STRIKE:
- case html_js_1.TAG_ID.STRONG: {
- bStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.A: {
- aStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.H1:
- case html_js_1.TAG_ID.H2:
- case html_js_1.TAG_ID.H3:
- case html_js_1.TAG_ID.H4:
- case html_js_1.TAG_ID.H5:
- case html_js_1.TAG_ID.H6: {
- numberedHeaderStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.P:
- case html_js_1.TAG_ID.DL:
- case html_js_1.TAG_ID.OL:
- case html_js_1.TAG_ID.UL:
- case html_js_1.TAG_ID.DIV:
- case html_js_1.TAG_ID.DIR:
- case html_js_1.TAG_ID.NAV:
- case html_js_1.TAG_ID.MAIN:
- case html_js_1.TAG_ID.MENU:
- case html_js_1.TAG_ID.ASIDE:
- case html_js_1.TAG_ID.CENTER:
- case html_js_1.TAG_ID.FIGURE:
- case html_js_1.TAG_ID.FOOTER:
- case html_js_1.TAG_ID.HEADER:
- case html_js_1.TAG_ID.HGROUP:
- case html_js_1.TAG_ID.DIALOG:
- case html_js_1.TAG_ID.DETAILS:
- case html_js_1.TAG_ID.ADDRESS:
- case html_js_1.TAG_ID.ARTICLE:
- case html_js_1.TAG_ID.SECTION:
- case html_js_1.TAG_ID.SUMMARY:
- case html_js_1.TAG_ID.FIELDSET:
- case html_js_1.TAG_ID.BLOCKQUOTE:
- case html_js_1.TAG_ID.FIGCAPTION: {
- addressStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.LI:
- case html_js_1.TAG_ID.DD:
- case html_js_1.TAG_ID.DT: {
- listItemStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.BR:
- case html_js_1.TAG_ID.IMG:
- case html_js_1.TAG_ID.WBR:
- case html_js_1.TAG_ID.AREA:
- case html_js_1.TAG_ID.EMBED:
- case html_js_1.TAG_ID.KEYGEN: {
- areaStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.HR: {
- hrStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.RB:
- case html_js_1.TAG_ID.RTC: {
- rbStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.RT:
- case html_js_1.TAG_ID.RP: {
- rtStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.PRE:
- case html_js_1.TAG_ID.LISTING: {
- preStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.XMP: {
- xmpStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.SVG: {
- svgStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.HTML: {
- htmlStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.BASE:
- case html_js_1.TAG_ID.LINK:
- case html_js_1.TAG_ID.META:
- case html_js_1.TAG_ID.STYLE:
- case html_js_1.TAG_ID.TITLE:
- case html_js_1.TAG_ID.SCRIPT:
- case html_js_1.TAG_ID.BGSOUND:
- case html_js_1.TAG_ID.BASEFONT:
- case html_js_1.TAG_ID.TEMPLATE: {
- startTagInHead(p, token);
- break;
- }
- case html_js_1.TAG_ID.BODY: {
- bodyStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.FORM: {
- formStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.NOBR: {
- nobrStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.MATH: {
- mathStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.TABLE: {
- tableStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.INPUT: {
- inputStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.PARAM:
- case html_js_1.TAG_ID.TRACK:
- case html_js_1.TAG_ID.SOURCE: {
- paramStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.IMAGE: {
- imageStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.BUTTON: {
- buttonStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.APPLET:
- case html_js_1.TAG_ID.OBJECT:
- case html_js_1.TAG_ID.MARQUEE: {
- appletStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.IFRAME: {
- iframeStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.SELECT: {
- selectStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.OPTION:
- case html_js_1.TAG_ID.OPTGROUP: {
- optgroupStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.NOEMBED: {
- noembedStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.FRAMESET: {
- framesetStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.TEXTAREA: {
- textareaStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.NOSCRIPT: {
- if (p.options.scriptingEnabled) {
- noembedStartTagInBody(p, token);
- }
- else {
- genericStartTagInBody(p, token);
- }
- break;
- }
- case html_js_1.TAG_ID.PLAINTEXT: {
- plaintextStartTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.COL:
- case html_js_1.TAG_ID.TH:
- case html_js_1.TAG_ID.TD:
- case html_js_1.TAG_ID.TR:
- case html_js_1.TAG_ID.HEAD:
- case html_js_1.TAG_ID.FRAME:
- case html_js_1.TAG_ID.TBODY:
- case html_js_1.TAG_ID.TFOOT:
- case html_js_1.TAG_ID.THEAD:
- case html_js_1.TAG_ID.CAPTION:
- case html_js_1.TAG_ID.COLGROUP: {
- // Ignore token
- break;
- }
- default: {
- genericStartTagInBody(p, token);
- }
- }
- }
- function bodyEndTagInBody(p, token) {
- if (p.openElements.hasInScope(html_js_1.TAG_ID.BODY)) {
- p.insertionMode = InsertionMode.AFTER_BODY;
- //NOTE: <body> is never popped from the stack, so we need to updated
- //the end location explicitly.
- if (p.options.sourceCodeLocationInfo) {
- const bodyElement = p.openElements.tryPeekProperlyNestedBodyElement();
- if (bodyElement) {
- p._setEndLocation(bodyElement, token);
- }
- }
- }
- }
- function htmlEndTagInBody(p, token) {
- if (p.openElements.hasInScope(html_js_1.TAG_ID.BODY)) {
- p.insertionMode = InsertionMode.AFTER_BODY;
- endTagAfterBody(p, token);
- }
- }
- function addressEndTagInBody(p, token) {
- const tn = token.tagID;
- if (p.openElements.hasInScope(tn)) {
- p.openElements.generateImpliedEndTags();
- p.openElements.popUntilTagNamePopped(tn);
- }
- }
- function formEndTagInBody(p) {
- const inTemplate = p.openElements.tmplCount > 0;
- const { formElement } = p;
- if (!inTemplate) {
- p.formElement = null;
- }
- if ((formElement || inTemplate) && p.openElements.hasInScope(html_js_1.TAG_ID.FORM)) {
- p.openElements.generateImpliedEndTags();
- if (inTemplate) {
- p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.FORM);
- }
- else if (formElement) {
- p.openElements.remove(formElement);
- }
- }
- }
- function pEndTagInBody(p) {
- if (!p.openElements.hasInButtonScope(html_js_1.TAG_ID.P)) {
- p._insertFakeElement(html_js_1.TAG_NAMES.P, html_js_1.TAG_ID.P);
- }
- p._closePElement();
- }
- function liEndTagInBody(p) {
- if (p.openElements.hasInListItemScope(html_js_1.TAG_ID.LI)) {
- p.openElements.generateImpliedEndTagsWithExclusion(html_js_1.TAG_ID.LI);
- p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.LI);
- }
- }
- function ddEndTagInBody(p, token) {
- const tn = token.tagID;
- if (p.openElements.hasInScope(tn)) {
- p.openElements.generateImpliedEndTagsWithExclusion(tn);
- p.openElements.popUntilTagNamePopped(tn);
- }
- }
- function numberedHeaderEndTagInBody(p) {
- if (p.openElements.hasNumberedHeaderInScope()) {
- p.openElements.generateImpliedEndTags();
- p.openElements.popUntilNumberedHeaderPopped();
- }
- }
- function appletEndTagInBody(p, token) {
- const tn = token.tagID;
- if (p.openElements.hasInScope(tn)) {
- p.openElements.generateImpliedEndTags();
- p.openElements.popUntilTagNamePopped(tn);
- p.activeFormattingElements.clearToLastMarker();
- }
- }
- function brEndTagInBody(p) {
- p._reconstructActiveFormattingElements();
- p._insertFakeElement(html_js_1.TAG_NAMES.BR, html_js_1.TAG_ID.BR);
- p.openElements.pop();
- p.framesetOk = false;
- }
- function genericEndTagInBody(p, token) {
- const tn = token.tagName;
- const tid = token.tagID;
- for (let i = p.openElements.stackTop; i > 0; i--) {
- const element = p.openElements.items[i];
- const elementId = p.openElements.tagIDs[i];
- // Compare the tag name here, as the tag might not be a known tag with an ID.
- if (tid === elementId && (tid !== html_js_1.TAG_ID.UNKNOWN || p.treeAdapter.getTagName(element) === tn)) {
- p.openElements.generateImpliedEndTagsWithExclusion(tid);
- if (p.openElements.stackTop >= i)
- p.openElements.shortenToLength(i);
- break;
- }
- if (p._isSpecialElement(element, elementId)) {
- break;
- }
- }
- }
- function endTagInBody(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.A:
- case html_js_1.TAG_ID.B:
- case html_js_1.TAG_ID.I:
- case html_js_1.TAG_ID.S:
- case html_js_1.TAG_ID.U:
- case html_js_1.TAG_ID.EM:
- case html_js_1.TAG_ID.TT:
- case html_js_1.TAG_ID.BIG:
- case html_js_1.TAG_ID.CODE:
- case html_js_1.TAG_ID.FONT:
- case html_js_1.TAG_ID.NOBR:
- case html_js_1.TAG_ID.SMALL:
- case html_js_1.TAG_ID.STRIKE:
- case html_js_1.TAG_ID.STRONG: {
- callAdoptionAgency(p, token);
- break;
- }
- case html_js_1.TAG_ID.P: {
- pEndTagInBody(p);
- break;
- }
- case html_js_1.TAG_ID.DL:
- case html_js_1.TAG_ID.UL:
- case html_js_1.TAG_ID.OL:
- case html_js_1.TAG_ID.DIR:
- case html_js_1.TAG_ID.DIV:
- case html_js_1.TAG_ID.NAV:
- case html_js_1.TAG_ID.PRE:
- case html_js_1.TAG_ID.MAIN:
- case html_js_1.TAG_ID.MENU:
- case html_js_1.TAG_ID.ASIDE:
- case html_js_1.TAG_ID.BUTTON:
- case html_js_1.TAG_ID.CENTER:
- case html_js_1.TAG_ID.FIGURE:
- case html_js_1.TAG_ID.FOOTER:
- case html_js_1.TAG_ID.HEADER:
- case html_js_1.TAG_ID.HGROUP:
- case html_js_1.TAG_ID.DIALOG:
- case html_js_1.TAG_ID.ADDRESS:
- case html_js_1.TAG_ID.ARTICLE:
- case html_js_1.TAG_ID.DETAILS:
- case html_js_1.TAG_ID.SECTION:
- case html_js_1.TAG_ID.SUMMARY:
- case html_js_1.TAG_ID.LISTING:
- case html_js_1.TAG_ID.FIELDSET:
- case html_js_1.TAG_ID.BLOCKQUOTE:
- case html_js_1.TAG_ID.FIGCAPTION: {
- addressEndTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.LI: {
- liEndTagInBody(p);
- break;
- }
- case html_js_1.TAG_ID.DD:
- case html_js_1.TAG_ID.DT: {
- ddEndTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.H1:
- case html_js_1.TAG_ID.H2:
- case html_js_1.TAG_ID.H3:
- case html_js_1.TAG_ID.H4:
- case html_js_1.TAG_ID.H5:
- case html_js_1.TAG_ID.H6: {
- numberedHeaderEndTagInBody(p);
- break;
- }
- case html_js_1.TAG_ID.BR: {
- brEndTagInBody(p);
- break;
- }
- case html_js_1.TAG_ID.BODY: {
- bodyEndTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.HTML: {
- htmlEndTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.FORM: {
- formEndTagInBody(p);
- break;
- }
- case html_js_1.TAG_ID.APPLET:
- case html_js_1.TAG_ID.OBJECT:
- case html_js_1.TAG_ID.MARQUEE: {
- appletEndTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.TEMPLATE: {
- templateEndTagInHead(p, token);
- break;
- }
- default: {
- genericEndTagInBody(p, token);
- }
- }
- }
- function eofInBody(p, token) {
- if (p.tmplInsertionModeStack.length > 0) {
- eofInTemplate(p, token);
- }
- else {
- stopParsing(p, token);
- }
- }
- // The "text" insertion mode
- //------------------------------------------------------------------
- function endTagInText(p, token) {
- var _a;
- if (token.tagID === html_js_1.TAG_ID.SCRIPT) {
- (_a = p.scriptHandler) === null || _a === void 0 ? void 0 : _a.call(p, p.openElements.current);
- }
- p.openElements.pop();
- p.insertionMode = p.originalInsertionMode;
- }
- function eofInText(p, token) {
- p._err(token, error_codes_js_1.ERR.eofInElementThatCanContainOnlyText);
- p.openElements.pop();
- p.insertionMode = p.originalInsertionMode;
- p.onEof(token);
- }
- // The "in table" insertion mode
- //------------------------------------------------------------------
- function characterInTable(p, token) {
- if (TABLE_STRUCTURE_TAGS.has(p.openElements.currentTagId)) {
- p.pendingCharacterTokens.length = 0;
- p.hasNonWhitespacePendingCharacterToken = false;
- p.originalInsertionMode = p.insertionMode;
- p.insertionMode = InsertionMode.IN_TABLE_TEXT;
- switch (token.type) {
- case token_js_1.TokenType.CHARACTER: {
- characterInTableText(p, token);
- break;
- }
- case token_js_1.TokenType.WHITESPACE_CHARACTER: {
- whitespaceCharacterInTableText(p, token);
- break;
- }
- // Ignore null
- }
- }
- else {
- tokenInTable(p, token);
- }
- }
- function captionStartTagInTable(p, token) {
- p.openElements.clearBackToTableContext();
- p.activeFormattingElements.insertMarker();
- p._insertElement(token, html_js_1.NS.HTML);
- p.insertionMode = InsertionMode.IN_CAPTION;
- }
- function colgroupStartTagInTable(p, token) {
- p.openElements.clearBackToTableContext();
- p._insertElement(token, html_js_1.NS.HTML);
- p.insertionMode = InsertionMode.IN_COLUMN_GROUP;
- }
- function colStartTagInTable(p, token) {
- p.openElements.clearBackToTableContext();
- p._insertFakeElement(html_js_1.TAG_NAMES.COLGROUP, html_js_1.TAG_ID.COLGROUP);
- p.insertionMode = InsertionMode.IN_COLUMN_GROUP;
- startTagInColumnGroup(p, token);
- }
- function tbodyStartTagInTable(p, token) {
- p.openElements.clearBackToTableContext();
- p._insertElement(token, html_js_1.NS.HTML);
- p.insertionMode = InsertionMode.IN_TABLE_BODY;
- }
- function tdStartTagInTable(p, token) {
- p.openElements.clearBackToTableContext();
- p._insertFakeElement(html_js_1.TAG_NAMES.TBODY, html_js_1.TAG_ID.TBODY);
- p.insertionMode = InsertionMode.IN_TABLE_BODY;
- startTagInTableBody(p, token);
- }
- function tableStartTagInTable(p, token) {
- if (p.openElements.hasInTableScope(html_js_1.TAG_ID.TABLE)) {
- p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.TABLE);
- p._resetInsertionMode();
- p._processStartTag(token);
- }
- }
- function inputStartTagInTable(p, token) {
- if (isHiddenInput(token)) {
- p._appendElement(token, html_js_1.NS.HTML);
- }
- else {
- tokenInTable(p, token);
- }
- token.ackSelfClosing = true;
- }
- function formStartTagInTable(p, token) {
- if (!p.formElement && p.openElements.tmplCount === 0) {
- p._insertElement(token, html_js_1.NS.HTML);
- p.formElement = p.openElements.current;
- p.openElements.pop();
- }
- }
- function startTagInTable(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.TD:
- case html_js_1.TAG_ID.TH:
- case html_js_1.TAG_ID.TR: {
- tdStartTagInTable(p, token);
- break;
- }
- case html_js_1.TAG_ID.STYLE:
- case html_js_1.TAG_ID.SCRIPT:
- case html_js_1.TAG_ID.TEMPLATE: {
- startTagInHead(p, token);
- break;
- }
- case html_js_1.TAG_ID.COL: {
- colStartTagInTable(p, token);
- break;
- }
- case html_js_1.TAG_ID.FORM: {
- formStartTagInTable(p, token);
- break;
- }
- case html_js_1.TAG_ID.TABLE: {
- tableStartTagInTable(p, token);
- break;
- }
- case html_js_1.TAG_ID.TBODY:
- case html_js_1.TAG_ID.TFOOT:
- case html_js_1.TAG_ID.THEAD: {
- tbodyStartTagInTable(p, token);
- break;
- }
- case html_js_1.TAG_ID.INPUT: {
- inputStartTagInTable(p, token);
- break;
- }
- case html_js_1.TAG_ID.CAPTION: {
- captionStartTagInTable(p, token);
- break;
- }
- case html_js_1.TAG_ID.COLGROUP: {
- colgroupStartTagInTable(p, token);
- break;
- }
- default: {
- tokenInTable(p, token);
- }
- }
- }
- function endTagInTable(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.TABLE: {
- if (p.openElements.hasInTableScope(html_js_1.TAG_ID.TABLE)) {
- p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.TABLE);
- p._resetInsertionMode();
- }
- break;
- }
- case html_js_1.TAG_ID.TEMPLATE: {
- templateEndTagInHead(p, token);
- break;
- }
- case html_js_1.TAG_ID.BODY:
- case html_js_1.TAG_ID.CAPTION:
- case html_js_1.TAG_ID.COL:
- case html_js_1.TAG_ID.COLGROUP:
- case html_js_1.TAG_ID.HTML:
- case html_js_1.TAG_ID.TBODY:
- case html_js_1.TAG_ID.TD:
- case html_js_1.TAG_ID.TFOOT:
- case html_js_1.TAG_ID.TH:
- case html_js_1.TAG_ID.THEAD:
- case html_js_1.TAG_ID.TR: {
- // Ignore token
- break;
- }
- default: {
- tokenInTable(p, token);
- }
- }
- }
- function tokenInTable(p, token) {
- const savedFosterParentingState = p.fosterParentingEnabled;
- p.fosterParentingEnabled = true;
- // Process token in `In Body` mode
- modeInBody(p, token);
- p.fosterParentingEnabled = savedFosterParentingState;
- }
- // The "in table text" insertion mode
- //------------------------------------------------------------------
- function whitespaceCharacterInTableText(p, token) {
- p.pendingCharacterTokens.push(token);
- }
- function characterInTableText(p, token) {
- p.pendingCharacterTokens.push(token);
- p.hasNonWhitespacePendingCharacterToken = true;
- }
- function tokenInTableText(p, token) {
- let i = 0;
- if (p.hasNonWhitespacePendingCharacterToken) {
- for (; i < p.pendingCharacterTokens.length; i++) {
- tokenInTable(p, p.pendingCharacterTokens[i]);
- }
- }
- else {
- for (; i < p.pendingCharacterTokens.length; i++) {
- p._insertCharacters(p.pendingCharacterTokens[i]);
- }
- }
- p.insertionMode = p.originalInsertionMode;
- p._processToken(token);
- }
- // The "in caption" insertion mode
- //------------------------------------------------------------------
- const TABLE_VOID_ELEMENTS = new Set([html_js_1.TAG_ID.CAPTION, html_js_1.TAG_ID.COL, html_js_1.TAG_ID.COLGROUP, html_js_1.TAG_ID.TBODY, html_js_1.TAG_ID.TD, html_js_1.TAG_ID.TFOOT, html_js_1.TAG_ID.TH, html_js_1.TAG_ID.THEAD, html_js_1.TAG_ID.TR]);
- function startTagInCaption(p, token) {
- const tn = token.tagID;
- if (TABLE_VOID_ELEMENTS.has(tn)) {
- if (p.openElements.hasInTableScope(html_js_1.TAG_ID.CAPTION)) {
- p.openElements.generateImpliedEndTags();
- p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.CAPTION);
- p.activeFormattingElements.clearToLastMarker();
- p.insertionMode = InsertionMode.IN_TABLE;
- startTagInTable(p, token);
- }
- }
- else {
- startTagInBody(p, token);
- }
- }
- function endTagInCaption(p, token) {
- const tn = token.tagID;
- switch (tn) {
- case html_js_1.TAG_ID.CAPTION:
- case html_js_1.TAG_ID.TABLE: {
- if (p.openElements.hasInTableScope(html_js_1.TAG_ID.CAPTION)) {
- p.openElements.generateImpliedEndTags();
- p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.CAPTION);
- p.activeFormattingElements.clearToLastMarker();
- p.insertionMode = InsertionMode.IN_TABLE;
- if (tn === html_js_1.TAG_ID.TABLE) {
- endTagInTable(p, token);
- }
- }
- break;
- }
- case html_js_1.TAG_ID.BODY:
- case html_js_1.TAG_ID.COL:
- case html_js_1.TAG_ID.COLGROUP:
- case html_js_1.TAG_ID.HTML:
- case html_js_1.TAG_ID.TBODY:
- case html_js_1.TAG_ID.TD:
- case html_js_1.TAG_ID.TFOOT:
- case html_js_1.TAG_ID.TH:
- case html_js_1.TAG_ID.THEAD:
- case html_js_1.TAG_ID.TR: {
- // Ignore token
- break;
- }
- default: {
- endTagInBody(p, token);
- }
- }
- }
- // The "in column group" insertion mode
- //------------------------------------------------------------------
- function startTagInColumnGroup(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.HTML: {
- startTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.COL: {
- p._appendElement(token, html_js_1.NS.HTML);
- token.ackSelfClosing = true;
- break;
- }
- case html_js_1.TAG_ID.TEMPLATE: {
- startTagInHead(p, token);
- break;
- }
- default: {
- tokenInColumnGroup(p, token);
- }
- }
- }
- function endTagInColumnGroup(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.COLGROUP: {
- if (p.openElements.currentTagId === html_js_1.TAG_ID.COLGROUP) {
- p.openElements.pop();
- p.insertionMode = InsertionMode.IN_TABLE;
- }
- break;
- }
- case html_js_1.TAG_ID.TEMPLATE: {
- templateEndTagInHead(p, token);
- break;
- }
- case html_js_1.TAG_ID.COL: {
- // Ignore token
- break;
- }
- default: {
- tokenInColumnGroup(p, token);
- }
- }
- }
- function tokenInColumnGroup(p, token) {
- if (p.openElements.currentTagId === html_js_1.TAG_ID.COLGROUP) {
- p.openElements.pop();
- p.insertionMode = InsertionMode.IN_TABLE;
- p._processToken(token);
- }
- }
- // The "in table body" insertion mode
- //------------------------------------------------------------------
- function startTagInTableBody(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.TR: {
- p.openElements.clearBackToTableBodyContext();
- p._insertElement(token, html_js_1.NS.HTML);
- p.insertionMode = InsertionMode.IN_ROW;
- break;
- }
- case html_js_1.TAG_ID.TH:
- case html_js_1.TAG_ID.TD: {
- p.openElements.clearBackToTableBodyContext();
- p._insertFakeElement(html_js_1.TAG_NAMES.TR, html_js_1.TAG_ID.TR);
- p.insertionMode = InsertionMode.IN_ROW;
- startTagInRow(p, token);
- break;
- }
- case html_js_1.TAG_ID.CAPTION:
- case html_js_1.TAG_ID.COL:
- case html_js_1.TAG_ID.COLGROUP:
- case html_js_1.TAG_ID.TBODY:
- case html_js_1.TAG_ID.TFOOT:
- case html_js_1.TAG_ID.THEAD: {
- if (p.openElements.hasTableBodyContextInTableScope()) {
- p.openElements.clearBackToTableBodyContext();
- p.openElements.pop();
- p.insertionMode = InsertionMode.IN_TABLE;
- startTagInTable(p, token);
- }
- break;
- }
- default: {
- startTagInTable(p, token);
- }
- }
- }
- function endTagInTableBody(p, token) {
- const tn = token.tagID;
- switch (token.tagID) {
- case html_js_1.TAG_ID.TBODY:
- case html_js_1.TAG_ID.TFOOT:
- case html_js_1.TAG_ID.THEAD: {
- if (p.openElements.hasInTableScope(tn)) {
- p.openElements.clearBackToTableBodyContext();
- p.openElements.pop();
- p.insertionMode = InsertionMode.IN_TABLE;
- }
- break;
- }
- case html_js_1.TAG_ID.TABLE: {
- if (p.openElements.hasTableBodyContextInTableScope()) {
- p.openElements.clearBackToTableBodyContext();
- p.openElements.pop();
- p.insertionMode = InsertionMode.IN_TABLE;
- endTagInTable(p, token);
- }
- break;
- }
- case html_js_1.TAG_ID.BODY:
- case html_js_1.TAG_ID.CAPTION:
- case html_js_1.TAG_ID.COL:
- case html_js_1.TAG_ID.COLGROUP:
- case html_js_1.TAG_ID.HTML:
- case html_js_1.TAG_ID.TD:
- case html_js_1.TAG_ID.TH:
- case html_js_1.TAG_ID.TR: {
- // Ignore token
- break;
- }
- default: {
- endTagInTable(p, token);
- }
- }
- }
- // The "in row" insertion mode
- //------------------------------------------------------------------
- function startTagInRow(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.TH:
- case html_js_1.TAG_ID.TD: {
- p.openElements.clearBackToTableRowContext();
- p._insertElement(token, html_js_1.NS.HTML);
- p.insertionMode = InsertionMode.IN_CELL;
- p.activeFormattingElements.insertMarker();
- break;
- }
- case html_js_1.TAG_ID.CAPTION:
- case html_js_1.TAG_ID.COL:
- case html_js_1.TAG_ID.COLGROUP:
- case html_js_1.TAG_ID.TBODY:
- case html_js_1.TAG_ID.TFOOT:
- case html_js_1.TAG_ID.THEAD:
- case html_js_1.TAG_ID.TR: {
- if (p.openElements.hasInTableScope(html_js_1.TAG_ID.TR)) {
- p.openElements.clearBackToTableRowContext();
- p.openElements.pop();
- p.insertionMode = InsertionMode.IN_TABLE_BODY;
- startTagInTableBody(p, token);
- }
- break;
- }
- default: {
- startTagInTable(p, token);
- }
- }
- }
- function endTagInRow(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.TR: {
- if (p.openElements.hasInTableScope(html_js_1.TAG_ID.TR)) {
- p.openElements.clearBackToTableRowContext();
- p.openElements.pop();
- p.insertionMode = InsertionMode.IN_TABLE_BODY;
- }
- break;
- }
- case html_js_1.TAG_ID.TABLE: {
- if (p.openElements.hasInTableScope(html_js_1.TAG_ID.TR)) {
- p.openElements.clearBackToTableRowContext();
- p.openElements.pop();
- p.insertionMode = InsertionMode.IN_TABLE_BODY;
- endTagInTableBody(p, token);
- }
- break;
- }
- case html_js_1.TAG_ID.TBODY:
- case html_js_1.TAG_ID.TFOOT:
- case html_js_1.TAG_ID.THEAD: {
- if (p.openElements.hasInTableScope(token.tagID) || p.openElements.hasInTableScope(html_js_1.TAG_ID.TR)) {
- p.openElements.clearBackToTableRowContext();
- p.openElements.pop();
- p.insertionMode = InsertionMode.IN_TABLE_BODY;
- endTagInTableBody(p, token);
- }
- break;
- }
- case html_js_1.TAG_ID.BODY:
- case html_js_1.TAG_ID.CAPTION:
- case html_js_1.TAG_ID.COL:
- case html_js_1.TAG_ID.COLGROUP:
- case html_js_1.TAG_ID.HTML:
- case html_js_1.TAG_ID.TD:
- case html_js_1.TAG_ID.TH: {
- // Ignore end tag
- break;
- }
- default: {
- endTagInTable(p, token);
- }
- }
- }
- // The "in cell" insertion mode
- //------------------------------------------------------------------
- function startTagInCell(p, token) {
- const tn = token.tagID;
- if (TABLE_VOID_ELEMENTS.has(tn)) {
- if (p.openElements.hasInTableScope(html_js_1.TAG_ID.TD) || p.openElements.hasInTableScope(html_js_1.TAG_ID.TH)) {
- p._closeTableCell();
- startTagInRow(p, token);
- }
- }
- else {
- startTagInBody(p, token);
- }
- }
- function endTagInCell(p, token) {
- const tn = token.tagID;
- switch (tn) {
- case html_js_1.TAG_ID.TD:
- case html_js_1.TAG_ID.TH: {
- if (p.openElements.hasInTableScope(tn)) {
- p.openElements.generateImpliedEndTags();
- p.openElements.popUntilTagNamePopped(tn);
- p.activeFormattingElements.clearToLastMarker();
- p.insertionMode = InsertionMode.IN_ROW;
- }
- break;
- }
- case html_js_1.TAG_ID.TABLE:
- case html_js_1.TAG_ID.TBODY:
- case html_js_1.TAG_ID.TFOOT:
- case html_js_1.TAG_ID.THEAD:
- case html_js_1.TAG_ID.TR: {
- if (p.openElements.hasInTableScope(tn)) {
- p._closeTableCell();
- endTagInRow(p, token);
- }
- break;
- }
- case html_js_1.TAG_ID.BODY:
- case html_js_1.TAG_ID.CAPTION:
- case html_js_1.TAG_ID.COL:
- case html_js_1.TAG_ID.COLGROUP:
- case html_js_1.TAG_ID.HTML: {
- // Ignore token
- break;
- }
- default: {
- endTagInBody(p, token);
- }
- }
- }
- // The "in select" insertion mode
- //------------------------------------------------------------------
- function startTagInSelect(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.HTML: {
- startTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.OPTION: {
- if (p.openElements.currentTagId === html_js_1.TAG_ID.OPTION) {
- p.openElements.pop();
- }
- p._insertElement(token, html_js_1.NS.HTML);
- break;
- }
- case html_js_1.TAG_ID.OPTGROUP: {
- if (p.openElements.currentTagId === html_js_1.TAG_ID.OPTION) {
- p.openElements.pop();
- }
- if (p.openElements.currentTagId === html_js_1.TAG_ID.OPTGROUP) {
- p.openElements.pop();
- }
- p._insertElement(token, html_js_1.NS.HTML);
- break;
- }
- case html_js_1.TAG_ID.INPUT:
- case html_js_1.TAG_ID.KEYGEN:
- case html_js_1.TAG_ID.TEXTAREA:
- case html_js_1.TAG_ID.SELECT: {
- if (p.openElements.hasInSelectScope(html_js_1.TAG_ID.SELECT)) {
- p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.SELECT);
- p._resetInsertionMode();
- if (token.tagID !== html_js_1.TAG_ID.SELECT) {
- p._processStartTag(token);
- }
- }
- break;
- }
- case html_js_1.TAG_ID.SCRIPT:
- case html_js_1.TAG_ID.TEMPLATE: {
- startTagInHead(p, token);
- break;
- }
- default:
- // Do nothing
- }
- }
- function endTagInSelect(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.OPTGROUP: {
- if (p.openElements.stackTop > 0 &&
- p.openElements.currentTagId === html_js_1.TAG_ID.OPTION &&
- p.openElements.tagIDs[p.openElements.stackTop - 1] === html_js_1.TAG_ID.OPTGROUP) {
- p.openElements.pop();
- }
- if (p.openElements.currentTagId === html_js_1.TAG_ID.OPTGROUP) {
- p.openElements.pop();
- }
- break;
- }
- case html_js_1.TAG_ID.OPTION: {
- if (p.openElements.currentTagId === html_js_1.TAG_ID.OPTION) {
- p.openElements.pop();
- }
- break;
- }
- case html_js_1.TAG_ID.SELECT: {
- if (p.openElements.hasInSelectScope(html_js_1.TAG_ID.SELECT)) {
- p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.SELECT);
- p._resetInsertionMode();
- }
- break;
- }
- case html_js_1.TAG_ID.TEMPLATE: {
- templateEndTagInHead(p, token);
- break;
- }
- default:
- // Do nothing
- }
- }
- // The "in select in table" insertion mode
- //------------------------------------------------------------------
- function startTagInSelectInTable(p, token) {
- const tn = token.tagID;
- if (tn === html_js_1.TAG_ID.CAPTION ||
- tn === html_js_1.TAG_ID.TABLE ||
- tn === html_js_1.TAG_ID.TBODY ||
- tn === html_js_1.TAG_ID.TFOOT ||
- tn === html_js_1.TAG_ID.THEAD ||
- tn === html_js_1.TAG_ID.TR ||
- tn === html_js_1.TAG_ID.TD ||
- tn === html_js_1.TAG_ID.TH) {
- p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.SELECT);
- p._resetInsertionMode();
- p._processStartTag(token);
- }
- else {
- startTagInSelect(p, token);
- }
- }
- function endTagInSelectInTable(p, token) {
- const tn = token.tagID;
- if (tn === html_js_1.TAG_ID.CAPTION ||
- tn === html_js_1.TAG_ID.TABLE ||
- tn === html_js_1.TAG_ID.TBODY ||
- tn === html_js_1.TAG_ID.TFOOT ||
- tn === html_js_1.TAG_ID.THEAD ||
- tn === html_js_1.TAG_ID.TR ||
- tn === html_js_1.TAG_ID.TD ||
- tn === html_js_1.TAG_ID.TH) {
- if (p.openElements.hasInTableScope(tn)) {
- p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.SELECT);
- p._resetInsertionMode();
- p.onEndTag(token);
- }
- }
- else {
- endTagInSelect(p, token);
- }
- }
- // The "in template" insertion mode
- //------------------------------------------------------------------
- function startTagInTemplate(p, token) {
- switch (token.tagID) {
- // First, handle tags that can start without a mode change
- case html_js_1.TAG_ID.BASE:
- case html_js_1.TAG_ID.BASEFONT:
- case html_js_1.TAG_ID.BGSOUND:
- case html_js_1.TAG_ID.LINK:
- case html_js_1.TAG_ID.META:
- case html_js_1.TAG_ID.NOFRAMES:
- case html_js_1.TAG_ID.SCRIPT:
- case html_js_1.TAG_ID.STYLE:
- case html_js_1.TAG_ID.TEMPLATE:
- case html_js_1.TAG_ID.TITLE: {
- startTagInHead(p, token);
- break;
- }
- // Re-process the token in the appropriate mode
- case html_js_1.TAG_ID.CAPTION:
- case html_js_1.TAG_ID.COLGROUP:
- case html_js_1.TAG_ID.TBODY:
- case html_js_1.TAG_ID.TFOOT:
- case html_js_1.TAG_ID.THEAD: {
- p.tmplInsertionModeStack[0] = InsertionMode.IN_TABLE;
- p.insertionMode = InsertionMode.IN_TABLE;
- startTagInTable(p, token);
- break;
- }
- case html_js_1.TAG_ID.COL: {
- p.tmplInsertionModeStack[0] = InsertionMode.IN_COLUMN_GROUP;
- p.insertionMode = InsertionMode.IN_COLUMN_GROUP;
- startTagInColumnGroup(p, token);
- break;
- }
- case html_js_1.TAG_ID.TR: {
- p.tmplInsertionModeStack[0] = InsertionMode.IN_TABLE_BODY;
- p.insertionMode = InsertionMode.IN_TABLE_BODY;
- startTagInTableBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.TD:
- case html_js_1.TAG_ID.TH: {
- p.tmplInsertionModeStack[0] = InsertionMode.IN_ROW;
- p.insertionMode = InsertionMode.IN_ROW;
- startTagInRow(p, token);
- break;
- }
- default: {
- p.tmplInsertionModeStack[0] = InsertionMode.IN_BODY;
- p.insertionMode = InsertionMode.IN_BODY;
- startTagInBody(p, token);
- }
- }
- }
- function endTagInTemplate(p, token) {
- if (token.tagID === html_js_1.TAG_ID.TEMPLATE) {
- templateEndTagInHead(p, token);
- }
- }
- function eofInTemplate(p, token) {
- if (p.openElements.tmplCount > 0) {
- p.openElements.popUntilTagNamePopped(html_js_1.TAG_ID.TEMPLATE);
- p.activeFormattingElements.clearToLastMarker();
- p.tmplInsertionModeStack.shift();
- p._resetInsertionMode();
- p.onEof(token);
- }
- else {
- stopParsing(p, token);
- }
- }
- // The "after body" insertion mode
- //------------------------------------------------------------------
- function startTagAfterBody(p, token) {
- if (token.tagID === html_js_1.TAG_ID.HTML) {
- startTagInBody(p, token);
- }
- else {
- tokenAfterBody(p, token);
- }
- }
- function endTagAfterBody(p, token) {
- var _a;
- if (token.tagID === html_js_1.TAG_ID.HTML) {
- if (!p.fragmentContext) {
- p.insertionMode = InsertionMode.AFTER_AFTER_BODY;
- }
- //NOTE: <html> is never popped from the stack, so we need to updated
- //the end location explicitly.
- if (p.options.sourceCodeLocationInfo && p.openElements.tagIDs[0] === html_js_1.TAG_ID.HTML) {
- p._setEndLocation(p.openElements.items[0], token);
- // Update the body element, if it doesn't have an end tag
- const bodyElement = p.openElements.items[1];
- if (bodyElement && !((_a = p.treeAdapter.getNodeSourceCodeLocation(bodyElement)) === null || _a === void 0 ? void 0 : _a.endTag)) {
- p._setEndLocation(bodyElement, token);
- }
- }
- }
- else {
- tokenAfterBody(p, token);
- }
- }
- function tokenAfterBody(p, token) {
- p.insertionMode = InsertionMode.IN_BODY;
- modeInBody(p, token);
- }
- // The "in frameset" insertion mode
- //------------------------------------------------------------------
- function startTagInFrameset(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.HTML: {
- startTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.FRAMESET: {
- p._insertElement(token, html_js_1.NS.HTML);
- break;
- }
- case html_js_1.TAG_ID.FRAME: {
- p._appendElement(token, html_js_1.NS.HTML);
- token.ackSelfClosing = true;
- break;
- }
- case html_js_1.TAG_ID.NOFRAMES: {
- startTagInHead(p, token);
- break;
- }
- default:
- // Do nothing
- }
- }
- function endTagInFrameset(p, token) {
- if (token.tagID === html_js_1.TAG_ID.FRAMESET && !p.openElements.isRootHtmlElementCurrent()) {
- p.openElements.pop();
- if (!p.fragmentContext && p.openElements.currentTagId !== html_js_1.TAG_ID.FRAMESET) {
- p.insertionMode = InsertionMode.AFTER_FRAMESET;
- }
- }
- }
- // The "after frameset" insertion mode
- //------------------------------------------------------------------
- function startTagAfterFrameset(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.HTML: {
- startTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.NOFRAMES: {
- startTagInHead(p, token);
- break;
- }
- default:
- // Do nothing
- }
- }
- function endTagAfterFrameset(p, token) {
- if (token.tagID === html_js_1.TAG_ID.HTML) {
- p.insertionMode = InsertionMode.AFTER_AFTER_FRAMESET;
- }
- }
- // The "after after body" insertion mode
- //------------------------------------------------------------------
- function startTagAfterAfterBody(p, token) {
- if (token.tagID === html_js_1.TAG_ID.HTML) {
- startTagInBody(p, token);
- }
- else {
- tokenAfterAfterBody(p, token);
- }
- }
- function tokenAfterAfterBody(p, token) {
- p.insertionMode = InsertionMode.IN_BODY;
- modeInBody(p, token);
- }
- // The "after after frameset" insertion mode
- //------------------------------------------------------------------
- function startTagAfterAfterFrameset(p, token) {
- switch (token.tagID) {
- case html_js_1.TAG_ID.HTML: {
- startTagInBody(p, token);
- break;
- }
- case html_js_1.TAG_ID.NOFRAMES: {
- startTagInHead(p, token);
- break;
- }
- default:
- // Do nothing
- }
- }
- // The rules for parsing tokens in foreign content
- //------------------------------------------------------------------
- function nullCharacterInForeignContent(p, token) {
- token.chars = unicode.REPLACEMENT_CHARACTER;
- p._insertCharacters(token);
- }
- function characterInForeignContent(p, token) {
- p._insertCharacters(token);
- p.framesetOk = false;
- }
- function popUntilHtmlOrIntegrationPoint(p) {
- while (p.treeAdapter.getNamespaceURI(p.openElements.current) !== html_js_1.NS.HTML &&
- !p._isIntegrationPoint(p.openElements.currentTagId, p.openElements.current)) {
- p.openElements.pop();
- }
- }
- function startTagInForeignContent(p, token) {
- if (foreignContent.causesExit(token)) {
- popUntilHtmlOrIntegrationPoint(p);
- p._startTagOutsideForeignContent(token);
- }
- else {
- const current = p._getAdjustedCurrentElement();
- const currentNs = p.treeAdapter.getNamespaceURI(current);
- if (currentNs === html_js_1.NS.MATHML) {
- foreignContent.adjustTokenMathMLAttrs(token);
- }
- else if (currentNs === html_js_1.NS.SVG) {
- foreignContent.adjustTokenSVGTagName(token);
- foreignContent.adjustTokenSVGAttrs(token);
- }
- foreignContent.adjustTokenXMLAttrs(token);
- if (token.selfClosing) {
- p._appendElement(token, currentNs);
- }
- else {
- p._insertElement(token, currentNs);
- }
- token.ackSelfClosing = true;
- }
- }
- function endTagInForeignContent(p, token) {
- if (token.tagID === html_js_1.TAG_ID.P || token.tagID === html_js_1.TAG_ID.BR) {
- popUntilHtmlOrIntegrationPoint(p);
- p._endTagOutsideForeignContent(token);
- return;
- }
- for (let i = p.openElements.stackTop; i > 0; i--) {
- const element = p.openElements.items[i];
- if (p.treeAdapter.getNamespaceURI(element) === html_js_1.NS.HTML) {
- p._endTagOutsideForeignContent(token);
- break;
- }
- const tagName = p.treeAdapter.getTagName(element);
- if (tagName.toLowerCase() === token.tagName) {
- //NOTE: update the token tag name for `_setEndLocation`.
- token.tagName = tagName;
- p.openElements.shortenToLength(i);
- break;
- }
- }
- }
- //# sourceMappingURL=index.js.map
|