From 1c2dd4695fb088153c25c2edc2e720d1972d13ed Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Thu, 4 Feb 2021 18:22:31 -0700 Subject: [PATCH] Enable table and dictonary markdown extensions --- CHANGELOG.md | 1 + pkg/transpile/common_test.go | 17 ++++++++++++++++- pkg/transpile/puzzle.go | 10 +++++++++- pkg/transpile/puzzle_test.go | 9 +++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0023db2..2441eac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 It still works the same way if you register a team in `teamids.txt`, but now you can use anything and it will put you on an already existing team named ``. +- switched from `blackfriday` to `goldmark`, to support CommonMark ## [v4.0.2] - 2020-10-29 ### Added diff --git a/pkg/transpile/common_test.go b/pkg/transpile/common_test.go index c2c9d94..4428a0c 100644 --- a/pkg/transpile/common_test.go +++ b/pkg/transpile/common_test.go @@ -24,6 +24,21 @@ answer: RFC822 answer RFC822 body `) +var testMothMarkdown = []byte(`--- +answers: + - answer +pre: + authors: + - Fred +--- + +one | two +--- | --- +1 | 2 + +Term +: definition of that term +`) func newTestFs() afero.Fs { fs := afero.NewMemMapFs() @@ -31,7 +46,7 @@ func newTestFs() afero.Fs { afero.WriteFile(fs, "cat0/1/moo.txt", []byte("Moo."), 0644) afero.WriteFile(fs, "cat0/2/puzzle.md", testMothRfc822, 0644) afero.WriteFile(fs, "cat0/3/puzzle.moth", testMothYaml, 0644) - afero.WriteFile(fs, "cat0/4/puzzle.md", testMothYaml, 0644) + afero.WriteFile(fs, "cat0/4/puzzle.md", testMothMarkdown, 0644) afero.WriteFile(fs, "cat0/5/puzzle.md", testMothYaml, 0644) afero.WriteFile(fs, "cat0/10/puzzle.md", []byte(`--- Answers: diff --git a/pkg/transpile/puzzle.go b/pkg/transpile/puzzle.go index 75101e8..c02ff8f 100644 --- a/pkg/transpile/puzzle.go +++ b/pkg/transpile/puzzle.go @@ -20,6 +20,7 @@ import ( "github.com/spf13/afero" "github.com/yuin/goldmark" + "github.com/yuin/goldmark/extension" "gopkg.in/yaml.v2" ) @@ -285,7 +286,14 @@ func (fp FsPuzzle) staticPuzzle() (StaticPuzzle, []byte, error) { } body := new(bytes.Buffer) - goldmark.Convert(bodyBuf.Bytes(), body) + + md := goldmark.New( + goldmark.WithExtensions( + extension.Table, + extension.DefinitionList, + ), + ) + md.Convert(bodyBuf.Bytes(), body) return static, body.Bytes(), err } diff --git a/pkg/transpile/puzzle_test.go b/pkg/transpile/puzzle_test.go index a6fc813..4779eef 100644 --- a/pkg/transpile/puzzle_test.go +++ b/pkg/transpile/puzzle_test.go @@ -3,6 +3,7 @@ package transpile import ( "bytes" "io" + "strings" "testing" "github.com/spf13/afero" @@ -63,6 +64,14 @@ func TestPuzzle(t *testing.T) { t.Error("Legacy `puzzle.moth` file:", err) } + if puzzle, err := NewFsPuzzlePoints(catFs, 4).Puzzle(); err != nil { + t.Error("Markdown test file:", err) + } else if !strings.Contains(puzzle.Pre.Body, "") { + t.Error("Markdown table extension isn't making tables") + } else if !strings.Contains(puzzle.Pre.Body, "
") { + t.Error("Markdown dictionary extension isn't making tables") + } + if _, err := NewFsPuzzlePoints(catFs, 99).Puzzle(); err == nil { t.Error("Non-existent puzzle", err) }