]> Cypherpunks repositories - gostls13.git/commitdiff
html: adjust bookmark in "adoption agency" algorithm
authorAndrew Balholm <andybalholm@gmail.com>
Fri, 28 Oct 2011 23:51:59 +0000 (10:51 +1100)
committerNigel Tao <nigeltao@golang.org>
Fri, 28 Oct 2011 23:51:59 +0000 (10:51 +1100)
In the adoption agency algorithm, the formatting element is sometimes
removed from the list of active formatting elements and reinserted at a later index.
In that case, the bookmark showing where it is to be reinserted needs to be moved,
so that its position relative to its neighbors remains the same
(and also so that it doesn't become out of bounds).

Pass tests1.dat, test 70:
<DIV> abc <B> def <I> ghi <P> jkl </B>

| <html>
|   <head>
|   <body>
|     <div>
|       " abc "
|       <b>
|         " def "
|         <i>
|           " ghi "
|       <i>
|         <p>
|           <b>
|             " jkl "

Also pass tests through test 76:
<test attribute---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->

R=nigeltao
CC=golang-dev
https://golang.org/cl/5322052

src/pkg/html/parse.go
src/pkg/html/parse_test.go

index b0348790c19f4d9c9f1482ef78dc8addf5c1aa98..49c7a65babfedc92f1eec5dd867944598feb8209 100644 (file)
@@ -756,6 +756,10 @@ func (p *parser) inBodyEndTagFormatting(tag string) {
                furthestBlock.Add(clone)
 
                // Step 14. Fix up the list of active formatting elements.
+               if oldLoc := p.afe.index(formattingElement); oldLoc != -1 && oldLoc < bookmark {
+                       // Move the bookmark with the rest of the list.
+                       bookmark--
+               }
                p.afe.remove(formattingElement)
                p.afe.insert(bookmark, clone)
 
index e86a36f18a8b0e91f8b498208c1c5c19496e4647..861070d103df89d585d84afe7b2f8195a4face7e 100644 (file)
@@ -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 < 70; i++ {
+               for i := 0; i < 77; i++ {
                        // Parse the #data section.
                        b, err := ioutil.ReadAll(<-rc)
                        if err != nil {