// Section 12.2.3.2 of the HTML5 specification says "The following elements
// have varying levels of special parsing rules".
// http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#the-stack-of-open-elements
-var isSpecialElement = map[string]bool{
+var isSpecialElementMap = map[string]bool{
"address": true,
"applet": true,
"area": true,
"wbr": true,
"xmp": true,
}
+
+func isSpecialElement(element *Node) bool {
+ switch element.Namespace {
+ case "", "html":
+ return isSpecialElementMap[element.Data]
+ case "svg":
+ return element.Data == "foreignObject"
+ }
+ return false
+}
case "address", "div", "p":
continue
default:
- if !isSpecialElement[node.Data] {
+ if !isSpecialElement(node) {
continue
}
}
case "address", "div", "p":
continue
default:
- if !isSpecialElement[node.Data] {
+ if !isSpecialElement(node) {
continue
}
}
// Steps 5-6. Find the furthest block.
var furthestBlock *Node
for _, e := range p.oe[feIndex:] {
- if isSpecialElement[e.Data] {
+ if isSpecialElement(e) {
furthestBlock = e
break
}
p.oe = p.oe[:i]
break
}
- if isSpecialElement[p.oe[i].Data] {
+ if isSpecialElement(p.oe[i]) {
break
}
}
// TODO: adjust foreign attributes.
p.addElement(p.tok.Data, p.tok.Attr)
case EndTagToken:
- // TODO.
+ for i := len(p.oe) - 1; i >= 0; i-- {
+ if p.oe[i].Namespace == "" {
+ inBodyIM(p)
+ break
+ }
+ if strings.EqualFold(p.oe[i].Data, p.tok.Data) {
+ p.oe = p.oe[:i]
+ break
+ }
+ }
+ p.resetInsertionMode()
+ return true
default:
// Ignore the token.
}