idx += len(ignoredSyntax.Find(b[idx:]))
idx += len(tag.Find(b[idx:]))
}
+ if idx == 0 {
+ // doctype is required for HTML5, we did not find it,
+ // and neither did we find html or head tags, so
+ // skip injection.
+ // This allows us to render partial HTML documents to be used in
+ // e.g. JS frameworks.
+ ft.To().Write(b)
+ return nil
+ }
path := strings.TrimSuffix(baseURL.Path, "/")
c.Assert(apply("<!doctype html>after"), qt.Equals, "<!doctype html>"+expectBase+"after")
})
- c.Run("Inject before other elements if all else omitted", func(c *qt.C) {
- c.Assert(apply("<title>after</title>"), qt.Equals, expectBase+"<title>after</title>")
+ c.Run("Inject nothing if no doctype, html or head found", func(c *qt.C) {
+ c.Assert(apply("<title>after</title>"), qt.Equals, "<title>after</title>")
})
- c.Run("Inject before text content if all else omitted", func(c *qt.C) {
- c.Assert(apply("after"), qt.Equals, expectBase+"after")
+ c.Run("Inject nothing if no tag found", func(c *qt.C) {
+ c.Assert(apply("after"), qt.Equals, "after")
})
c.Run("Inject after HeAd tag MiXed CaSe", func(c *qt.C) {