1
0
mirror of https://github.com/golang/go synced 2024-11-20 02:04:39 -07:00

exp/html: detect "integration points" in SVG and MathML content

Detect HTML integration points and MathML text integration points.
At these points, process tokens as HTML, not as foreign content.

Pass 33 more tests.

R=nigeltao
CC=golang-dev
https://golang.org/cl/6249044
This commit is contained in:
Andrew Balholm 2012-05-24 13:46:41 +10:00 committed by Nigel Tao
parent 04f3cf0faa
commit 82e2272566
12 changed files with 71 additions and 37 deletions

View File

@ -37,8 +37,16 @@ func htmlIntegrationPoint(n *Node) bool {
}
switch n.Namespace {
case "math":
// TODO: annotation-xml elements whose start tags have "text/html" or
// "application/xhtml+xml" encodings.
if n.Data == "annotation-xml" {
for _, a := range n.Attr {
if a.Key == "encoding" {
val := strings.ToLower(a.Val)
if val == "text/html" || val == "application/xhtml+xml" {
return true
}
}
}
}
case "svg":
switch n.Data {
case "desc", "foreignObject", "title":
@ -48,6 +56,17 @@ func htmlIntegrationPoint(n *Node) bool {
return false
}
func mathMLTextIntegrationPoint(n *Node) bool {
if n.Namespace != "math" {
return false
}
switch n.Data {
case "mi", "mo", "mn", "ms", "mtext":
return true
}
return false
}
// Section 12.2.5.5.
var breakout = map[string]bool{
"b": true,

View File

@ -1859,8 +1859,23 @@ func (p *parser) inForeignContent() bool {
if n.Namespace == "" {
return false
}
// TODO: MathML, HTML integration points.
// TODO: MathML's annotation-xml combining with SVG's svg.
if mathMLTextIntegrationPoint(n) {
if p.tok.Type == StartTagToken && p.tok.Data != "mglyph" && p.tok.Data != "malignmark" {
return false
}
if p.tok.Type == TextToken {
return false
}
}
if n.Namespace == "math" && n.Data == "annotation-xml" && p.tok.Type == StartTagToken && p.tok.Data == "svg" {
return false
}
if htmlIntegrationPoint(n) && (p.tok.Type == StartTagToken || p.tok.Type == TextToken) {
return false
}
if p.tok.Type == ErrorToken {
return false
}
return true
}

View File

@ -1,3 +1,3 @@
PASS "<input type=\"hidden\"><frameset>"
PASS "<!DOCTYPE html><table><caption><svg>foo</table>bar"
FAIL "<table><tr><td><svg><desc><td></desc><circle>"
PASS "<table><tr><td><svg><desc><td></desc><circle>"

View File

@ -11,7 +11,7 @@ FAIL "<plaintext>\x00filler\x00text\x00"
FAIL "<svg><![CDATA[\x00filler\x00text\x00]]>"
FAIL "<body><!\x00>"
FAIL "<body><!\x00filler\x00text>"
FAIL "<body><svg><foreignObject>\x00filler\x00text"
PASS "<body><svg><foreignObject>\x00filler\x00text"
FAIL "<svg>\x00filler\x00text"
FAIL "<svg>\x00<frameset>"
FAIL "<svg>\x00 <frameset>"
@ -24,10 +24,10 @@ PASS "<svg><p><frameset>"
FAIL "<!DOCTYPE html><pre>\r\n\r\nA</pre>"
FAIL "<!DOCTYPE html><pre>\r\rA</pre>"
PASS "<!DOCTYPE html><pre>\rA</pre>"
FAIL "<!DOCTYPE html><table><tr><td><math><mtext>\x00a"
FAIL "<!DOCTYPE html><table><tr><td><svg><foreignObject>\x00a"
FAIL "<!DOCTYPE html><math><mi>a\x00b"
FAIL "<!DOCTYPE html><math><mo>a\x00b"
FAIL "<!DOCTYPE html><math><mn>a\x00b"
FAIL "<!DOCTYPE html><math><ms>a\x00b"
FAIL "<!DOCTYPE html><math><mtext>a\x00b"
PASS "<!DOCTYPE html><table><tr><td><math><mtext>\x00a"
PASS "<!DOCTYPE html><table><tr><td><svg><foreignObject>\x00a"
PASS "<!DOCTYPE html><math><mi>a\x00b"
PASS "<!DOCTYPE html><math><mo>a\x00b"
PASS "<!DOCTYPE html><math><mn>a\x00b"
PASS "<!DOCTYPE html><math><ms>a\x00b"
PASS "<!DOCTYPE html><math><mtext>a\x00b"

View File

@ -14,4 +14,4 @@ PASS "<table><tr><caption>"
PASS "<table><tr></body></caption></col></colgroup></html></td></th><td>foo"
PASS "<table><td><tr>"
PASS "<table><td><button><td>"
FAIL "<table><tr><td><svg><desc><td>"
PASS "<table><tr><td><svg><desc><td>"

View File

@ -35,8 +35,8 @@ PASS "<!DOCTYPE html><svg><desc><svg><ul>a"
PASS "<!DOCTYPE html><p><svg><desc><p>"
FAIL "<!DOCTYPE html><p><svg><title><p>"
PASS "<div><svg><path><foreignObject><p></foreignObject><p>"
FAIL "<math><mi><div><object><div><span></span></div></object></div></mi><mi>"
FAIL "<math><mi><svg><foreignObject><div><div></div></div></foreignObject></svg></mi><mi>"
PASS "<math><mi><div><object><div><span></span></div></object></div></mi><mi>"
PASS "<math><mi><svg><foreignObject><div><div></div></div></foreignObject></svg></mi><mi>"
PASS "<svg><script></script><path>"
PASS "<table><svg></svg><tr>"
PASS "<math><mi><mglyph>"
@ -49,6 +49,6 @@ PASS "<math><ms><mglyph>"
PASS "<math><ms><malignmark>"
PASS "<math><mtext><mglyph>"
PASS "<math><mtext><malignmark>"
FAIL "<math><annotation-xml><svg></svg></annotation-xml><mi>"
FAIL "<math><annotation-xml><svg><foreignObject><div><math><mi></mi></math><span></span></div></foreignObject><path></path></svg></annotation-xml><mi>"
FAIL "<math><annotation-xml><svg><foreignObject><math><mi><svg></svg></mi><mo></mo></math><span></span></foreignObject><path></path></svg></annotation-xml><mi>"
PASS "<math><annotation-xml><svg></svg></annotation-xml><mi>"
PASS "<math><annotation-xml><svg><foreignObject><div><math><mi></mi></math><span></span></div></foreignObject><path></path></svg></annotation-xml><mi>"
PASS "<math><annotation-xml><svg><foreignObject><math><mi><svg></svg></mi><mo></mo></math><span></span></foreignObject><path></path></svg></annotation-xml><mi>"

View File

@ -1,2 +1,2 @@
FAIL "<!DOCTYPE html><body><p>foo<math><mtext><i>baz</i></mtext><annotation-xml><svg><desc><b>eggs</b></desc><g><foreignObject><P>spam<TABLE><tr><td><img></td></table></foreignObject></g><g>quux</g></svg></annotation-xml></math>bar"
FAIL "<!DOCTYPE html><body>foo<math><mtext><i>baz</i></mtext><annotation-xml><svg><desc><b>eggs</b></desc><g><foreignObject><P>spam<TABLE><tr><td><img></td></table></foreignObject></g><g>quux</g></svg></annotation-xml></math>bar"
PASS "<!DOCTYPE html><body><p>foo<math><mtext><i>baz</i></mtext><annotation-xml><svg><desc><b>eggs</b></desc><g><foreignObject><P>spam<TABLE><tr><td><img></td></table></foreignObject></g><g>quux</g></svg></annotation-xml></math>bar"
PASS "<!DOCTYPE html><body>foo<math><mtext><i>baz</i></mtext><annotation-xml><svg><desc><b>eggs</b></desc><g><foreignObject><P>spam<TABLE><tr><td><img></td></table></foreignObject></g><g>quux</g></svg></annotation-xml></math>bar"

View File

@ -28,11 +28,11 @@ PASS "<!doctype html><table> b <!--foo-->"
PASS "<!doctype html><select><option><option>"
PASS "<!doctype html><select><option></optgroup>"
PASS "<!doctype html><select><option></optgroup>"
FAIL "<!doctype html><p><math><mi><p><h1>"
FAIL "<!doctype html><p><math><mo><p><h1>"
FAIL "<!doctype html><p><math><mn><p><h1>"
FAIL "<!doctype html><p><math><ms><p><h1>"
FAIL "<!doctype html><p><math><mtext><p><h1>"
PASS "<!doctype html><p><math><mi><p><h1>"
PASS "<!doctype html><p><math><mo><p><h1>"
PASS "<!doctype html><p><math><mn><p><h1>"
PASS "<!doctype html><p><math><ms><p><h1>"
PASS "<!doctype html><p><math><mtext><p><h1>"
PASS "<!doctype html><frameset></noframes>"
FAIL "<!doctype html><html c=d><body></html><html a=b>"
FAIL "<!doctype html><html c=d><frameset></frameset></html><html a=b>"
@ -80,7 +80,7 @@ PASS "<html> a <frameset></frameset>"
PASS "<!doctype html><div><frameset>"
PASS "<!doctype html><div><body><frameset>"
PASS "<!doctype html><p><math></p>a"
FAIL "<!doctype html><p><math><mn><span></p>a"
PASS "<!doctype html><p><math><mn><span></p>a"
PASS "<!doctype html><math></html>"
PASS "<!doctype html><meta charset=\"ascii\">"
FAIL "<!doctype html><meta http-equiv=\"content-type\" content=\"text/html;charset=ascii\">"

View File

@ -32,8 +32,8 @@ PASS "<option><span><option>"
PASS "<option><option>"
PASS "<math><annotation-xml><div>"
PASS "<math><annotation-xml encoding=\"application/svg+xml\"><div>"
FAIL "<math><annotation-xml encoding=\"application/xhtml+xml\"><div>"
FAIL "<math><annotation-xml encoding=\"aPPlication/xhtmL+xMl\"><div>"
FAIL "<math><annotation-xml encoding=\"text/html\"><div>"
FAIL "<math><annotation-xml encoding=\"Text/htmL\"><div>"
PASS "<math><annotation-xml encoding=\"application/xhtml+xml\"><div>"
PASS "<math><annotation-xml encoding=\"aPPlication/xhtmL+xMl\"><div>"
PASS "<math><annotation-xml encoding=\"text/html\"><div>"
PASS "<math><annotation-xml encoding=\"Text/htmL\"><div>"
PASS "<math><annotation-xml encoding=\" text/html \"><div>"

View File

@ -8,8 +8,8 @@ PASS "<!DOCTYPE html><body><b><nobr>1<nobr><ins></b><i><nobr>"
PASS "<!DOCTYPE html><body><b><nobr>1<ins><nobr></b><i>2"
PASS "<!DOCTYPE html><body><b>1<nobr></b><i><nobr>2</i>"
FAIL "<p><code x</code></p>"
FAIL "<!DOCTYPE html><svg><foreignObject><p><i></p>a"
FAIL "<!DOCTYPE html><table><tr><td><svg><foreignObject><p><i></p>a"
FAIL "<!DOCTYPE html><math><mtext><p><i></p>a"
FAIL "<!DOCTYPE html><table><tr><td><math><mtext><p><i></p>a"
PASS "<!DOCTYPE html><svg><foreignObject><p><i></p>a"
PASS "<!DOCTYPE html><table><tr><td><svg><foreignObject><p><i></p>a"
PASS "<!DOCTYPE html><math><mtext><p><i></p>a"
PASS "<!DOCTYPE html><table><tr><td><math><mtext><p><i></p>a"
PASS "<!DOCTYPE html><body><div><!/div>a"

View File

@ -1,7 +1,7 @@
PASS "<!DOCTYPE html><math></math>"
PASS "<!DOCTYPE html><body><math></math>"
PASS "<!DOCTYPE html><math><mi>"
FAIL "<!DOCTYPE html><math><annotation-xml><svg><u>"
PASS "<!DOCTYPE html><math><annotation-xml><svg><u>"
PASS "<!DOCTYPE html><body><select><math></math></select>"
PASS "<!DOCTYPE html><body><select><option><math></math></option></select>"
PASS "<!DOCTYPE html><body><table><math></math></table>"

View File

@ -42,7 +42,7 @@ FAIL "<svg><title><svg><div>"
PASS "<img <=\"\" FAIL>"
FAIL "<ul><li><div id='foo'/>A</li><li>B<div>C</div></li></ul>"
PASS "<svg><em><desc></em>"
FAIL "<table><tr><td><svg><desc><td></desc><circle>"
PASS "<table><tr><td><svg><desc><td></desc><circle>"
PASS "<svg><tfoot></mi><td>"
PASS "<math><mrow><mrow><mn>1</mn></mrow><mi>a</mi></mrow></math>"
PASS "<!doctype html><input type=\"hidden\"><frameset>"