hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 322d19a81fedbf423a047bdf286499d2e25d14be
parent 7cb484e121da73b63aab231ba29bb644b5f7965e
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Fri, 27 May 2022 15:19:02 +0200

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

Diffstat:
Mhugolib/shortcode_test.go | 33+++++++++++++++++++++++++++++++++
Mmedia/mediaType.go | 4+++-
Mmedia/mediaType_test.go | 2+-
Moutput/outputFormat.go | 9+++++++++
Moutput/outputFormat_test.go | 2+-
5 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go
@@ -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
+	`)
+
+}
diff --git a/media/mediaType.go b/media/mediaType.go
@@ -257,7 +257,8 @@ var (
 	OpenTypeFontType = newMediaType("font", "otf", []string{"otf"})
 
 	// 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
 	AVIType  = newMediaType("video", "x-msvideo", []string{"avi"})
@@ -278,6 +279,7 @@ var DefaultTypes = Types{
 	SCSSType,
 	SASSType,
 	HTMLType,
+	MarkdownType,
 	JavascriptType,
 	TypeScriptType,
 	TSXType,
diff --git a/media/mediaType_test.go b/media/mediaType_test.go
@@ -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) {
diff --git a/output/outputFormat.go b/output/outputFormat.go
@@ -133,6 +133,14 @@ var (
 		Weight: 10,
 	}
 
+	MarkdownFormat = Format{
+		Name:        "MARKDOWN",
+		MediaType:   media.MarkdownType,
+		BaseName:    "index",
+		Rel:         "alternate",
+		IsPlainText: true,
+	}
+
 	JSONFormat = Format{
 		Name:        "JSON",
 		MediaType:   media.JSONType,
@@ -183,6 +191,7 @@ var DefaultFormats = Formats{
 	CSVFormat,
 	HTMLFormat,
 	JSONFormat,
+	MarkdownFormat,
 	WebAppManifestFormat,
 	RobotsTxtFormat,
 	RSSFormat,
diff --git a/output/outputFormat_test.go b/output/outputFormat_test.go
@@ -68,7 +68,7 @@ func TestDefaultTypes(t *testing.T) {
 	c.Assert(RSSFormat.NoUgly, qt.Equals, true)
 	c.Assert(CalendarFormat.IsHTML, qt.Equals, false)
 
-	c.Assert(len(DefaultFormats), qt.Equals, 10)
+	c.Assert(len(DefaultFormats), qt.Equals, 11)
 
 }