summaryrefslogtreecommitdiff
path: root/gemini/gemtext/mdconv/convert_test.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-01-17 16:41:04 -0700
committertjpcc <tjp@ctrl-c.club>2023-01-17 16:41:04 -0700
commit6586db782ea6dcb5f2eb191a690ec7e7df51161f (patch)
tree36158a53a6d8aad9f5a873c6c43d598ce5647b97 /gemini/gemtext/mdconv/convert_test.go
parent2ef530daa47b301a40c1ee93cd43b8f36fc68c0b (diff)
Updates
* update README * move "gemtext" to within "gemini"
Diffstat (limited to 'gemini/gemtext/mdconv/convert_test.go')
-rw-r--r--gemini/gemtext/mdconv/convert_test.go103
1 files changed, 103 insertions, 0 deletions
diff --git a/gemini/gemtext/mdconv/convert_test.go b/gemini/gemtext/mdconv/convert_test.go
new file mode 100644
index 0000000..c8fd53c
--- /dev/null
+++ b/gemini/gemtext/mdconv/convert_test.go
@@ -0,0 +1,103 @@
+package mdconv_test
+
+import (
+ "bytes"
+ "testing"
+ "text/template"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+
+ "tildegit.org/tjp/gus/gemini/gemtext"
+ "tildegit.org/tjp/gus/gemini/gemtext/mdconv"
+)
+
+var gmiDoc = `
+# top-level header line
+
+## subtitle
+
+This is some non-blank regular text.
+
+* an
+* unordered
+* list
+
+=> gemini://google.com/ as if
+=> https://google.com/
+
+> this is a quote
+> -tjp
+
+`[1:] + "```pre-formatted code\ndoc := gemtext.Parse(req.Body)\n```ignored closing alt-text\n"
+
+func TestConvert(t *testing.T) {
+ mdDoc := `
+# top-level header line
+
+## subtitle
+
+This is some non-blank regular text.
+
+* an
+* unordered
+* list
+
+=> [as if](gemini://google.com/)
+
+=> [https://google.com/](https://google.com/)
+
+> this is a quote
+
+> -tjp
+
+` + "```\ndoc := gemtext.Parse(req.Body)\n```\n"
+
+ doc, err := gemtext.Parse(bytes.NewBufferString(gmiDoc))
+ require.Nil(t, err)
+
+ buf := &bytes.Buffer{}
+ require.Nil(t, mdconv.Convert(buf, doc, nil))
+
+ assert.Equal(t, mdDoc, buf.String())
+}
+
+func TestConvertWithOverrides(t *testing.T) {
+ mdDoc := `
+# h1: top-level header line
+text:
+## h2: subtitle
+text:
+text: This is some non-blank regular text.
+text:
+* li: an
+* li: unordered
+* li: list
+text:
+=> link: [as if](gemini://google.com/)
+=> link: [https://google.com/](https://google.com/)
+text:
+> quote: this is a quote
+> quote: -tjp
+text:
+`[1:] + "```\npf: doc := gemtext.Parse(req.Body)\n```\n"
+
+ overrides := template.Must(template.New("overrides").Parse((`
+ {{define "textline"}}text: {{.}}{{end}}
+ {{define "linkline"}}=> link: [{{if eq .Label ""}}{{.URL}}{{else}}{{.Label}}{{end}}]({{.URL}})` + "\n" + `{{end}}
+ {{define "preformattedtextlines"}}` + "```\n" + `{{range . }}pf: {{.}}{{end}}` + "```\n" + `{{end}}
+ {{define "heading1line"}}# h1: {{.Body}}` + "\n" + `{{end}}
+ {{define "heading2line"}}## h2: {{.Body}}` + "\n" + `{{end}}
+ {{define "heading3line"}}### h3: {{.Body}}` + "\n" + `{{end}}
+ {{define "listitemlines"}}{{range .}}* li: {{.Body}}` + "\n" + `{{end}}{{end}}
+ {{define "quoteline"}}> quote: {{.Body}}` + "\n" + `{{end}}
+ `)[1:]))
+
+ doc, err := gemtext.Parse(bytes.NewBufferString(gmiDoc))
+ require.Nil(t, err)
+
+ buf := &bytes.Buffer{}
+ require.Nil(t, mdconv.Convert(buf, doc, overrides))
+
+ assert.Equal(t, mdDoc, buf.String())
+}