Commit 500e7a4f authored by namusyaka's avatar namusyaka Committed by Nigel Tao

html: add "in template" insertion mode support

See:
https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-intemplate

Updates golang/go#23071

Change-Id: I36529b7cf5d2adf159ed5c471fba9f67890b7eb9
Reviewed-on: https://go-review.googlesource.com/94838
Run-TryBot: Kunpei Sakai <namusyaka@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarNigel Tao <nigeltao@golang.org>
parent 61147c48
...@@ -174,6 +174,16 @@ func (s *nodeStack) index(n *Node) int { ...@@ -174,6 +174,16 @@ func (s *nodeStack) index(n *Node) int {
return -1 return -1
} }
// contains returns whether a is within s.
func (s *nodeStack) contains(a atom.Atom) bool {
for _, n := range *s {
if n.DataAtom == a {
return true
}
}
return false
}
// insert inserts a node at the given index. // insert inserts a node at the given index.
func (s *nodeStack) insert(i int, n *Node) { func (s *nodeStack) insert(i int, n *Node) {
(*s) = append(*s, nil) (*s) = append(*s, nil)
...@@ -192,3 +202,19 @@ func (s *nodeStack) remove(n *Node) { ...@@ -192,3 +202,19 @@ func (s *nodeStack) remove(n *Node) {
(*s)[j] = nil (*s)[j] = nil
*s = (*s)[:j] *s = (*s)[:j]
} }
type insertionModeStack []insertionMode
func (s *insertionModeStack) pop() (im insertionMode) {
i := len(*s)
im = (*s)[i-1]
*s = (*s)[:i-1]
return im
}
func (s *insertionModeStack) top() insertionMode {
if i := len(*s); i > 0 {
return (*s)[i-1]
}
return nil
}
This diff is collapsed.
...@@ -125,6 +125,7 @@ func (a sortedAttributes) Swap(i, j int) { ...@@ -125,6 +125,7 @@ func (a sortedAttributes) Swap(i, j int) {
func dumpLevel(w io.Writer, n *Node, level int) error { func dumpLevel(w io.Writer, n *Node, level int) error {
dumpIndent(w, level) dumpIndent(w, level)
level++
switch n.Type { switch n.Type {
case ErrorNode: case ErrorNode:
return errors.New("unexpected ErrorNode") return errors.New("unexpected ErrorNode")
...@@ -140,13 +141,19 @@ func dumpLevel(w io.Writer, n *Node, level int) error { ...@@ -140,13 +141,19 @@ func dumpLevel(w io.Writer, n *Node, level int) error {
sort.Sort(attr) sort.Sort(attr)
for _, a := range attr { for _, a := range attr {
io.WriteString(w, "\n") io.WriteString(w, "\n")
dumpIndent(w, level+1) dumpIndent(w, level)
if a.Namespace != "" { if a.Namespace != "" {
fmt.Fprintf(w, `%s %s="%s"`, a.Namespace, a.Key, a.Val) fmt.Fprintf(w, `%s %s="%s"`, a.Namespace, a.Key, a.Val)
} else { } else {
fmt.Fprintf(w, `%s="%s"`, a.Key, a.Val) fmt.Fprintf(w, `%s="%s"`, a.Key, a.Val)
} }
} }
if n.Namespace == "" && n.DataAtom == atom.Template {
io.WriteString(w, "\n")
dumpIndent(w, level)
level++
io.WriteString(w, "content")
}
case TextNode: case TextNode:
fmt.Fprintf(w, `"%s"`, n.Data) fmt.Fprintf(w, `"%s"`, n.Data)
case CommentNode: case CommentNode:
...@@ -176,7 +183,7 @@ func dumpLevel(w io.Writer, n *Node, level int) error { ...@@ -176,7 +183,7 @@ func dumpLevel(w io.Writer, n *Node, level int) error {
} }
io.WriteString(w, "\n") io.WriteString(w, "\n")
for c := n.FirstChild; c != nil; c = c.NextSibling { for c := n.FirstChild; c != nil; c = c.NextSibling {
if err := dumpLevel(w, c, level+1); err != nil { if err := dumpLevel(w, c, level); err != nil {
return err return err
} }
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment