pointerify the things

This commit is contained in:
Nico 2020-11-14 19:51:21 +00:00
parent bd6fa12191
commit 053b7dc5c7
2 changed files with 7 additions and 7 deletions

View File

@ -38,10 +38,10 @@ func RenderHeading(obj GemtextObject) (string, error) {
return strings.Repeat("#", obj.Level) + " " + obj.Text, nil
}
// RenderGemtext takes a GemtextPage and renders it into Gemtext.
func RenderGemtext(p GemtextPage) (string, error) {
// RenderGemtext takes a *GemtextPage and renders it into Gemtext.
func RenderGemtext(p *GemtextPage) (string, error) {
str := ""
for _, o := range p {
for _, o := range *p {
switch {
case o.Type == TEXT:
str += o.Text + "\n"
@ -70,14 +70,14 @@ func RenderGemtext(p GemtextPage) (string, error) {
return str, nil
}
// RenderHTML renders a GemtextPage p to a string containing html.
func RenderHTML(p GemtextPage) (string, error) {
// RenderHTML renders a *GemtextPage p to a string containing html.
func RenderHTML(p *GemtextPage) (string, error) {
escape := html.EscapeString // for brevity
listmode := false
quotemode := false
premode := false
var s string
for _, item := range p {
for _, item := range *p {
if listmode {
if item.Type != LIST {
s += "</ul>"

View File

@ -48,7 +48,7 @@ func TestRenderHeading(t *testing.T) {
}
func TestRenderHTML(t *testing.T) {
out, _ := RenderHTML(testdocumenttree)
out, _ := RenderHTML(&testdocumenttree)
want := "<h1>Document</h1><p>This is paragraph text &amp; It exists</p><a href=\"https://example.com\">example.com</a><br /><ul><li>List Item 1</li><li>List Item 2</li></ul><pre>this should be preformatted.\n=&gt; https://example.com Not a link\n</pre><ul><li>A single list item</li></ul><pre>one line of pre\n</pre><pre></pre><blockquote>Something\n- someone\n</blockquote>"
if out != want {
t.Errorf("Got %#v want %#v", out, want)