MCPcopy Index your code
hub / github.com/ampproject/amphtml / endTag

Method endTag

validator/js/engine/htmlparser.js:441–474  ·  view source on GitHub ↗

* Upon exiting a tag, validation for the current matcher is triggered, * e.g. for checking that the tag had some specified number of children. * @param {!parserInterface.ParsedHtmlTag} tag

(tag)

Source from the content-addressed store, hash-verified

439 * @param {!parserInterface.ParsedHtmlTag} tag
440 */
441 endTag(tag) {
442 if (this.region_ == TagRegion.IN_HEAD && tag.upperName() === 'HEAD') {
443 this.region_ = TagRegion.PRE_BODY;
444 }
445
446 // We ignore close body tags (</body) and instead insert them when their
447 // outer scope is closed (/html). This is closer to how a browser parser
448 // works. The idea here is if other tags are found after the <body>,
449 // (ex: <div>) which are only allowed in the <body>, we will effectively
450 // move them into the body section.
451 if (tag.upperName() === 'BODY') {
452 return;
453 }
454
455 // We look for tag.upperName() from the end. If we can find it, we pop
456 // everything from thereon off the stack. If we can't find it,
457 // we don't bother with closing the tag, since it doesn't have
458 // a matching open tag, though in practice the HtmlParser class
459 // will have already manufactured a start tag.
460 for (let idx = this.stack_.length - 1; idx >= 0; idx--) {
461 if (this.stack_[idx] === tag.upperName()) {
462 while (this.stack_.length > idx) {
463 if (this.stack_[this.stack_.length - 1] === 'SVG') {
464 this.region_ = TagRegion.IN_BODY;
465 }
466 if (this.handler_.endTag) {
467 this.handler_.endTag(
468 new parserInterface.ParsedHtmlTag(this.stack_.pop()));
469 }
470 }
471 return;
472 }
473 }
474 }
475
476 /**
477 * This method is called when we're done with the

Callers 4

startTagMethod · 0.95
pcdataMethod · 0.95
parseMethod · 0.95
exitRemainingTagsMethod · 0.45

Calls 2

upperNameMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected