From bde3751fab0120b6722e5532a97bdc7e12a71406 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 21 Jan 2023 18:36:28 +0100 Subject: Convert markdow to gemtext in gmi server --- src/gmi/tpl.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/gmi/tpl.go') 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 { -- cgit v1.2.3