pagr

A 'static site generator', built using dati.
Log | Files | Refs | Atom

commit b95802be16c6fe7523b0b3f72bbfaa205c8936b2
parent cd9d48736583f00813261822feec9c840375bc08
Author: gearsix <gearsix@tuta.io>
Date:   Thu, 31 Mar 2022 11:23:40 +0100

removed .gfm and .cm markdown support

Supporting multiple flavours of Markdown seemed pointless. I do want
to keep this tool flexible to the users needs but I decided on
removing github & (strictly) commonmark flavours of markdown for a
few reasons:
1. Nobody is going to recognise a .gfm or .cm extension
2. Different flavours of Markdown just ends up being confusing.
I believe Markdowns originally vague specification and John Grubers
(original markdown author) response to CommonMark (see codinghorrors
blog post apologizing to him for commonmark, lol) is that it should
be treated like an actual language - with different variations in
different domains (such as GitHub).

**TL;DR** I don't use .gfm or .cm and I'm making this tool for me.

Diffstat:
Mcontent.go | 59+++++++++--------------------------------------------------
Mcontent_test.go | 2--
Mpagr_test.go | 19++-----------------
3 files changed, 11 insertions(+), 69 deletions(-)

diff --git a/content.go b/content.go @@ -23,13 +23,11 @@ import ( // Content is the converted HTML string of a Content file type Content string -var contentExts = [6]string{ +var contentExts = [4]string{ "", // pre-formatted text ".txt", // plain-text ".html", // HTML ".md", // commonmark + extensions (linkify, auto-heading id, unsafe HTML) - ".gfm", // github-flavoured markdown - ".cm", // commonmark } func isContentExt(ext string) int { @@ -208,11 +206,7 @@ func NewContentFromFile(fpath string) (c Content, err error) { case ".txt": body = convertTextToHTML(bytes.NewReader(buf)) case ".md": - fallthrough - case ".gfm": - fallthrough - case ".cm": - body, err = convertMarkdownToHTML(lang, buf) + body, err = convertMarkdownToHTML(buf) case ".html": body = string(buf) default: @@ -275,48 +269,13 @@ func convertTextToHTML(in io.Reader) (html string) { // convertMarkdownToHTML initialises a `goldmark.Markdown` based on `lang` and // returns values from calling it's `Convert` function on `in`. -// Markdown `lang` options, see the code for specfics: -// - ".gfm" = github-flavoured markdown -// - ".cm" = standard commonmark -// - ".md" (and anything else) = commonmark + extensions (linkify, auto-heading id, unsafe HTML) -func convertMarkdownToHTML(lang string, buf []byte) (md string, err error) { - var markdown goldmark.Markdown - switch lang { - case ".gfm": - markdown = goldmark.New( - goldmark.WithExtensions( - goldmarkext.GFM, - goldmarkext.Table, - goldmarkext.Strikethrough, - goldmarkext.Linkify, - goldmarkext.TaskList, - ), - goldmark.WithParserOptions( - goldmarkparse.WithAutoHeadingID(), - ), - goldmark.WithRendererOptions( - goldmarkhtml.WithUnsafe(), - goldmarkhtml.WithHardWraps(), - ), - ) - case ".cm": - markdown = goldmark.New() - case ".md": - fallthrough - default: - markdown = goldmark.New( - goldmark.WithExtensions( - goldmarkext.Linkify, - ), - goldmark.WithParserOptions( - goldmarkparse.WithAutoHeadingID(), - ), - goldmark.WithRendererOptions( - goldmarkhtml.WithUnsafe(), - ), - ) - } - +// ".md" (and anything else) = commonmark + extensions (linkify, auto-heading id, unsafe HTML) +func convertMarkdownToHTML(buf []byte) (md string, err error) { + markdown := goldmark.New( + goldmark.WithExtensions(goldmarkext.Linkify), + goldmark.WithParserOptions(goldmarkparse.WithAutoHeadingID()), + goldmark.WithRendererOptions(goldmarkhtml.WithUnsafe()), + ) var out bytes.Buffer err = markdown.Convert(buf, &out) return out.String(), err diff --git a/content_test.go b/content_test.go @@ -38,8 +38,6 @@ func TestNewContentFromFile(test *testing.T) { contents := map[string]string{ "txt": `test`, "md": "**test**\ntest", - "gfm": "**test**\ntest", - "cm": "**test**", "html": `<b>test</b>`, } diff --git a/pagr_test.go b/pagr_test.go @@ -66,27 +66,12 @@ p2 p3 ` -const contentsGfm = `p1 -p2 - - pre1 - pre2 - -p3` -const contentsCm = `p1 -p2 - - pre1 - pre2 - -p3` var contents = map[string]string{ + "": contentsTxt, ".txt": contentsTxt, ".html": contentsHtml, ".md": contentsMd, - ".gfm": contentsGfm, - ".cm": contentsCm, } var asset = []byte{ // 5x5 black png image - unecessary but I think this is cool @@ -116,7 +101,7 @@ func createTestContents(dir string) (err error) { writef(filepath.Join(dir, "defaults.json"), "{ \"default\": \"data\" }") } else if l == 1 { dir = filepath.Join(dir, lang[1:]) - } else if l > 2 { + } else if l >= 2 { dir = filepath.Join(filepath.Dir(dir), lang[1:]) } if l >= 1 {