From: Andrew Balholm
Date: Wed, 26 Oct 2011 03:02:30 +0000 (+1100)
Subject: html: improve parsing of lists
X-Git-Tag: weekly.2011-10-25~1
X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=05ed18f4f6c661bfe01db0d8c25e5d7b65658a54;p=gostls13.git
html: improve parsing of lists
Make a tag close the previous element.
Make a tag close elements.
Pass tests1.dat, test 33:
hello worldyou
|
| "hello"
|
| "world"
|
| "how"
|
| "do"
| "you"
|
R=nigeltao
CC=golang-dev
https://golang.org/cl/5321051
---
diff --git a/src/pkg/html/parse.go b/src/pkg/html/parse.go
index 292fbaf6be..530942aa8f 100644
--- a/src/pkg/html/parse.go
+++ b/src/pkg/html/parse.go
@@ -576,6 +576,24 @@ func inBodyIM(p *parser) (insertionMode, bool) {
p.framesetOK = false
// TODO: detect inside a table.
return inSelectIM, true
+ case "li":
+ p.framesetOK = false
+ for i := len(p.oe) - 1; i >= 0; i-- {
+ node := p.oe[i]
+ switch node.Data {
+ case "li":
+ p.popUntil(listItemScopeStopTags, "li")
+ case "address", "div", "p":
+ continue
+ default:
+ if !isSpecialElement[node.Data] {
+ continue
+ }
+ }
+ break
+ }
+ p.popUntil(buttonScopeStopTags, "p")
+ p.addElement("li", p.tok.Attr)
default:
// TODO.
p.addElement(p.tok.Data, p.tok.Attr)
@@ -592,6 +610,8 @@ func inBodyIM(p *parser) (insertionMode, bool) {
p.popUntil(buttonScopeStopTags, "p")
case "a", "b", "big", "code", "em", "font", "i", "nobr", "s", "small", "strike", "strong", "tt", "u":
p.inBodyEndTagFormatting(p.tok.Data)
+ case "address", "article", "aside", "blockquote", "button", "center", "details", "dir", "div", "dl", "fieldset", "figcaption", "figure", "footer", "header", "hgroup", "listing", "menu", "nav", "ol", "pre", "section", "summary", "ul":
+ p.popUntil(defaultScopeStopTags, p.tok.Data)
default:
p.inBodyEndTagOther(p.tok.Data)
}
diff --git a/src/pkg/html/parse_test.go b/src/pkg/html/parse_test.go
index 865a47dea1..b0ddd92476 100644
--- a/src/pkg/html/parse_test.go
+++ b/src/pkg/html/parse_test.go
@@ -132,7 +132,7 @@ func TestParser(t *testing.T) {
rc := make(chan io.Reader)
go readDat(filename, rc)
// TODO(nigeltao): Process all test cases, not just a subset.
- for i := 0; i < 33; i++ {
+ for i := 0; i < 34; i++ {
// Parse the #data section.
b, err := ioutil.ReadAll(<-rc)
if err != nil {