}
func (s *TemplateStore) insertEmbedded() error {
- return fs.WalkDir(embeddedTemplatesFs, ".", func(path string, d fs.DirEntry, err error) error {
+ return fs.WalkDir(embeddedTemplatesFs, ".", func(tpath string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
return nil
}
- templb, err := embeddedTemplatesFs.ReadFile(path)
+ templb, err := embeddedTemplatesFs.ReadFile(tpath)
if err != nil {
return err
}
// Get the newlines on Windows in line with how we had it back when we used Go Generate
// to write the templates to Go files.
templ := string(bytes.ReplaceAll(templb, []byte("\r\n"), []byte("\n")))
- name := strings.TrimPrefix(filepath.ToSlash(path), "embedded/templates/")
+ name := strings.TrimPrefix(filepath.ToSlash(tpath), "embedded/templates/")
insertOne := func(name, content string) error {
pi := s.opts.PathParser.Parse(files.ComponentFolderLayouts, name)
return nil
}
+ // Copy the embedded HTML table render hook to each output format.
+ // See https://github.com/gohugoio/hugo/issues/13351.
+ if name == path.Join(containerMarkup, "render-table.html") {
+ for _, of := range s.opts.OutputFormats {
+ path := paths.TrimExt(name) + "." + of.Name + of.MediaType.FirstSuffix.FullSuffix
+ if err := insertOne(path, templ); err != nil {
+ return err
+ }
+ }
+
+ return nil
+ }
+
if err := insertOne(name, templ); err != nil {
return err
}
"mytexts|safeHTML: <div>mytext</div>",
)
}
+
+func TestIssue13351(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+disableKinds = ['page','rss','section','sitemap','taxonomy','term']
+[outputs]
+home = ['html','json']
+[outputFormats.html]
+weight = 1
+[outputFormats.json]
+weight = 2
+-- content/_index.md --
+---
+title: home
+---
+a|b
+:--|:--
+1|2
+-- layouts/index.html --
+{{ .Content }}
+-- layouts/index.json --
+{{ .Content }}
+`
+
+ b := hugolib.Test(t, files)
+ b.AssertFileContent("public/index.html", "<table>")
+ b.AssertFileContent("public/index.json", "<table>")
+
+ f := strings.ReplaceAll(files, "weight = 1", "weight = 0")
+ b = hugolib.Test(t, f)
+ b.AssertFileContent("public/index.html", "<table>")
+ b.AssertFileContent("public/index.json", "<table>")
+
+ f = strings.ReplaceAll(files, "weight = 1", "")
+ b = hugolib.Test(t, f)
+ b.AssertFileContent("public/index.html", "<table>")
+ b.AssertFileContent("public/index.json", "<table>")
+}