Add Markdown as an output format

The motivation behind this is not to make it easier to publish Markdown files, as that sounds unusual.

This is mainly meant for shortcodes that produces Markdown to be inlined.

You would do this by creating shortcodes with `*.md` suffix (e.g. `layouts/shortcodes/myshortcode.md`).

This output format is defined as plain text, and will use Go's much more lenient text template parser.

Updates #9821
This commit is contained in:
Bjørn Erik Pedersen 2022-05-27 15:19:02 +02:00
parent 7cb484e121
commit 322d19a81f
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
5 changed files with 47 additions and 3 deletions

View file

@ -909,3 +909,36 @@ outputs: ["html", "css", "csv", "json"]
} }
} }
// #9821
func TestShortcodeMarkdownOutputFormat(t *testing.T) {
t.Parallel()
files := `
-- config.toml --
-- content/p1.md --
---
title: "p1"
---
{{< foo >}}
-- layouts/shortcodes/foo.md --
§§§
<x
§§§
-- layouts/_default/single.html --
{{ .Content }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
Running: true,
},
).Build()
b.AssertFileContent("public/p1/index.html", `
<x
`)
}

View file

@ -258,6 +258,7 @@ var (
// Common document types // Common document types
PDFType = newMediaType("application", "pdf", []string{"pdf"}) PDFType = newMediaType("application", "pdf", []string{"pdf"})
MarkdownType = newMediaType("text", "markdown", []string{"md", "markdown"})
// Common video types // Common video types
AVIType = newMediaType("video", "x-msvideo", []string{"avi"}) AVIType = newMediaType("video", "x-msvideo", []string{"avi"})
@ -278,6 +279,7 @@ var DefaultTypes = Types{
SCSSType, SCSSType,
SASSType, SASSType,
HTMLType, HTMLType,
MarkdownType,
JavascriptType, JavascriptType,
TypeScriptType, TypeScriptType,
TSXType, TSXType,

View file

@ -63,7 +63,7 @@ func TestDefaultTypes(t *testing.T) {
} }
c.Assert(len(DefaultTypes), qt.Equals, 33) c.Assert(len(DefaultTypes), qt.Equals, 34)
} }
func TestGetByType(t *testing.T) { func TestGetByType(t *testing.T) {

View file

@ -133,6 +133,14 @@ var (
Weight: 10, Weight: 10,
} }
MarkdownFormat = Format{
Name: "MARKDOWN",
MediaType: media.MarkdownType,
BaseName: "index",
Rel: "alternate",
IsPlainText: true,
}
JSONFormat = Format{ JSONFormat = Format{
Name: "JSON", Name: "JSON",
MediaType: media.JSONType, MediaType: media.JSONType,
@ -183,6 +191,7 @@ var DefaultFormats = Formats{
CSVFormat, CSVFormat,
HTMLFormat, HTMLFormat,
JSONFormat, JSONFormat,
MarkdownFormat,
WebAppManifestFormat, WebAppManifestFormat,
RobotsTxtFormat, RobotsTxtFormat,
RSSFormat, RSSFormat,

View file

@ -68,7 +68,7 @@ func TestDefaultTypes(t *testing.T) {
c.Assert(RSSFormat.NoUgly, qt.Equals, true) c.Assert(RSSFormat.NoUgly, qt.Equals, true)
c.Assert(CalendarFormat.IsHTML, qt.Equals, false) c.Assert(CalendarFormat.IsHTML, qt.Equals, false)
c.Assert(len(DefaultFormats), qt.Equals, 10) c.Assert(len(DefaultFormats), qt.Equals, 11)
} }