summaryrefslogtreecommitdiff
path: root/gemini/gemtext/htmlconv/convert_test.go
blob: 641ffb8280241168c4812057714cf256c6446a69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package htmlconv_test

import (
	"bytes"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"

	"tildegit.org/tjp/gus/gemini/gemtext"
	"tildegit.org/tjp/gus/gemini/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())
}