pointerify the things
This commit is contained in:
parent
bd6fa12191
commit
053b7dc5c7
12
render.go
12
render.go
|
@ -38,10 +38,10 @@ func RenderHeading(obj GemtextObject) (string, error) {
|
||||||
return strings.Repeat("#", obj.Level) + " " + obj.Text, nil
|
return strings.Repeat("#", obj.Level) + " " + obj.Text, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderGemtext takes a GemtextPage and renders it into Gemtext.
|
// RenderGemtext takes a *GemtextPage and renders it into Gemtext.
|
||||||
func RenderGemtext(p GemtextPage) (string, error) {
|
func RenderGemtext(p *GemtextPage) (string, error) {
|
||||||
str := ""
|
str := ""
|
||||||
for _, o := range p {
|
for _, o := range *p {
|
||||||
switch {
|
switch {
|
||||||
case o.Type == TEXT:
|
case o.Type == TEXT:
|
||||||
str += o.Text + "\n"
|
str += o.Text + "\n"
|
||||||
|
@ -70,14 +70,14 @@ func RenderGemtext(p GemtextPage) (string, error) {
|
||||||
return str, nil
|
return str, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderHTML renders a GemtextPage p to a string containing html.
|
// RenderHTML renders a *GemtextPage p to a string containing html.
|
||||||
func RenderHTML(p GemtextPage) (string, error) {
|
func RenderHTML(p *GemtextPage) (string, error) {
|
||||||
escape := html.EscapeString // for brevity
|
escape := html.EscapeString // for brevity
|
||||||
listmode := false
|
listmode := false
|
||||||
quotemode := false
|
quotemode := false
|
||||||
premode := false
|
premode := false
|
||||||
var s string
|
var s string
|
||||||
for _, item := range p {
|
for _, item := range *p {
|
||||||
if listmode {
|
if listmode {
|
||||||
if item.Type != LIST {
|
if item.Type != LIST {
|
||||||
s += "</ul>"
|
s += "</ul>"
|
||||||
|
|
|
@ -48,7 +48,7 @@ func TestRenderHeading(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRenderHTML(t *testing.T) {
|
func TestRenderHTML(t *testing.T) {
|
||||||
out, _ := RenderHTML(testdocumenttree)
|
out, _ := RenderHTML(&testdocumenttree)
|
||||||
want := "<h1>Document</h1><p>This is paragraph text & 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=> 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>"
|
want := "<h1>Document</h1><p>This is paragraph text & 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=> 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 {
|
if out != want {
|
||||||
t.Errorf("Got %#v want %#v", out, want)
|
t.Errorf("Got %#v want %#v", out, want)
|
||||||
|
|
Reference in New Issue