summaryrefslogtreecommitdiff
path: root/src/gmi
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2023-01-21 18:36:28 +0100
committerBrian Picciano <mediocregopher@gmail.com>2023-01-21 18:36:28 +0100
commitbde3751fab0120b6722e5532a97bdc7e12a71406 (patch)
tree2fb7013786ddc79e5be3ed76d54b68cee74984b5 /src/gmi
parentffdd9520b9803e141582ba647050682659075760 (diff)
Convert markdow to gemtext in gmi server
Diffstat (limited to 'src/gmi')
-rw-r--r--src/gmi/tpl.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/gmi/tpl.go b/src/gmi/tpl.go
index 7f41993..9e0bc64 100644
--- a/src/gmi/tpl.go
+++ b/src/gmi/tpl.go
@@ -16,6 +16,7 @@ import (
"git.sr.ht/~adnano/go-gemini"
"github.com/mediocregopher/blog.mediocregopher.com/srv/post"
"github.com/mediocregopher/mediocre-go-lib/v2/mctx"
+ gmnhg "github.com/tdemin/gmnhg"
)
//go:embed tpl
@@ -120,7 +121,19 @@ func (r renderer) PostBody(p post.StoredPost) (string, error) {
return "", fmt.Errorf("preprocessing post body: %w", err)
}
- return buf.String(), nil
+ bodyBytes := buf.Bytes()
+
+ if p.Format == post.FormatMarkdown {
+
+ gemtextBodyBytes, err := gmnhg.RenderMarkdown(bodyBytes, 0)
+ if err != nil {
+ return "", fmt.Errorf("converting from markdown: %w", err)
+ }
+
+ bodyBytes = gemtextBodyBytes
+ }
+
+ return string(bodyBytes), nil
}
func (r renderer) GetQueryValue(key, def string) string {