]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Add Markdown as an output format
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 27 May 2022 13:19:02 +0000 (15:19 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 30 May 2022 09:32:55 +0000 (11:32 +0200)
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

hugolib/shortcode_test.go
media/mediaType.go
media/mediaType_test.go
output/outputFormat.go
output/outputFormat_test.go

index 7926a820392f0eb2d0fde9997e1fa348fe470c1a..372e1be9b050d1b1368084aaa5b352db88c8f14d 100644 (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
+       `)
+
+}
index 69bb9182acdc3d1522dc2fbcacbd05ee5a4f107c..3ac3123ac81881de7451fb8f8aadbfa30b386449 100644 (file)
@@ -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,
index 34571f7ee00e8873fd436cc634927cb4a216257d..af7123cb5cd2600caab355de6a01117190d35a5c 100644 (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) {
index 1f1556eafe4a9947eae3c3dae2ae2fc5cc5fa055..722079df9a7f360ab8b7a5f208b293c4ba4ed5c3 100644 (file)
@@ -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,
index a150dbe7ca4d6e025408c6548541287050e0a435..c5c4534bfd19e3b2cd2d2001df8a15512d9910f3 100644 (file)
@@ -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)
 
 }