diff --git a/hugolib/page.go b/hugolib/page.go index f09c6c1bf..817dec868 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -490,17 +490,35 @@ func (p *Page) ExecuteTemplate(layout string) *bytes.Buffer { } func (page *Page) guessMarkupType() string { + // First try the explicitly set markup from the frontmatter if page.Markup != "" { - return page.Markup + format := guessType(page.Markup) + if format != "unknown" { + return format + } } - if strings.HasSuffix(page.FileName, ".md") { - return "md" + // Then try to guess from the extension + ext := strings.ToLower(path.Ext(page.FileName)) + if strings.HasPrefix(ext, ".") { + return guessType(ext[1:]) } return "unknown" } +func guessType(in string) string { + switch in { + case "md", "markdown", "mdown": + return "markdown" + case "rst": + return "rst" + case "html", "htm": + return "html" + } + return "unknown" +} + func (page *Page) parse(reader io.Reader) error { p, err := parser.ReadFrom(reader) if err != nil { @@ -530,14 +548,10 @@ func (page *Page) parse(reader io.Reader) error { func (page *Page) Convert() error { switch page.guessMarkupType() { - case "md", "markdown", "mdown": + case "markdown": page.convertMarkdown(bytes.NewReader([]byte(page.Content))) case "rst": page.convertRestructuredText(bytes.NewReader([]byte(page.Content))) - case "html": - fallthrough - default: - page.Content = template.HTML(page.Content) } return nil } diff --git a/hugolib/site_test.go b/hugolib/site_test.go index 838445463..3f78f7b3e 100644 --- a/hugolib/site_test.go +++ b/hugolib/site_test.go @@ -229,6 +229,7 @@ func TestSkipRender(t *testing.T) { {"sect/doc5.html", []byte("{{ template \"head\" }}
body5"), "sect"}, {"sect/doc6.html", []byte("{{ template \"head_abs\" }}body5"), "sect"}, {"doc7.html", []byte("doc7 content"), ""}, + {"sect/doc8.html", []byte("---\nmarkup: md\n---\n# title\nsome *content*"), "sect"}, } s := &Site{ @@ -267,6 +268,7 @@ func TestSkipRender(t *testing.T) { {"sect/doc5.html", "body5"}, {"sect/doc6.html", "body5"}, {"doc7.html", "doc7 content"}, + {"sect/doc8.html", "some content
\n"}, } for _, test := range tests {