* 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)
| 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 |