summaryrefslogtreecommitdiff
path: root/gemtext/htmlconv/convert_test.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-01-15 19:59:58 -0700
committertjpcc <tjp@ctrl-c.club>2023-01-15 19:59:58 -0700
commit4c2630752f7367fff491a6ba53303e9102da7da0 (patch)
tree7819a03ddd08e9ee017e7245dfd58cde9f51857d /gemtext/htmlconv/convert_test.go
parentcec3718bdd089bcf58575740c5ae4f86b27226d1 (diff)
Completed markdown and HTML conversion.
Diffstat (limited to 'gemtext/htmlconv/convert_test.go')
-rw-r--r--gemtext/htmlconv/convert_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/gemtext/htmlconv/convert_test.go b/gemtext/htmlconv/convert_test.go
new file mode 100644
index 0000000..967cece
--- /dev/null
+++ b/gemtext/htmlconv/convert_test.go
@@ -0,0 +1,46 @@
+package htmlconv_test
+
+import (
+ "bytes"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+
+ "tildegit.org/tjp/gus/gemtext"
+ "tildegit.org/tjp/gus/gemtext/htmlconv"
+)
+
+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) {
+ htmlDoc := `
+<html><body><h1>top-level header line</h1><h2>subtitle</h2><p>This is some non-blank regular text.
+</p><ul><li>an</li><li>unordered</li><li>list</li></ul><p>=> <a href="gemini://google.com/">as if</a></p><p>=> <a href="https://google.com/">https://google.com/</a></p><blockquote> this is a quote</blockquote><blockquote> -tjp</blockquote><pre>doc := gemtext.Parse(req.Body)
+</pre></body></html>`[1:]
+
+ doc, err := gemtext.Parse(bytes.NewBufferString(gmiDoc))
+ require.Nil(t, err)
+
+ buf := &bytes.Buffer{}
+ require.Nil(t, htmlconv.Convert(buf, doc, nil))
+
+ assert.Equal(t, htmlDoc, buf.String())
+}