import (
"io"
"os"
+ "strings"
)
// A parser implements the HTML5 parsing algorithm:
return inHeadIM, !implied
}
+const whitespace = " \t\r\n\f"
+
// Section 11.2.5.4.4.
func inHeadIM(p *parser) (insertionMode, bool) {
var (
implied bool
)
switch p.tok.Type {
- case ErrorToken, TextToken:
+ case ErrorToken:
+ implied = true
+ case TextToken:
+ s := strings.TrimLeft(p.tok.Data, whitespace)
+ if len(s) < len(p.tok.Data) {
+ // Add the initial whitespace to the current node.
+ p.addText(p.tok.Data[:len(p.tok.Data)-len(s)])
+ if s == "" {
+ return inHeadIM, true
+ }
+ p.tok.Data = s
+ }
implied = true
case StartTagToken:
switch p.tok.Data {
}
return afterHeadIM, !implied
}
- return inHeadIM, !implied
+ return inHeadIM, true
}
// Section 11.2.5.4.6.
rc := make(chan io.Reader)
go readDat(filename, rc)
// TODO(nigeltao): Process all test cases, not just a subset.
- for i := 0; i < 50; i++ {
+ for i := 0; i < 55; i++ {
// Parse the #data section.
b, err := ioutil.ReadAll(<-rc)
if err != nil {