diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2022-05-20 14:30:09 -0600 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2022-05-20 14:30:26 -0600 |
commit | af434077ef3a971494fb0bc69ec9617c3b365abd (patch) | |
tree | 2a7c47c9450c2a6b5ac5bcae5c17b33f9a326db9 /srv/src/http/posts.go | |
parent | 16cfbd19157df76e7296dddb287412f1099feb33 (diff) |
Implement image macro for rendering images
Diffstat (limited to 'srv/src/http/posts.go')
-rw-r--r-- | srv/src/http/posts.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/srv/src/http/posts.go b/srv/src/http/posts.go index fd583ea..0aea3e3 100644 --- a/srv/src/http/posts.go +++ b/srv/src/http/posts.go @@ -1,6 +1,7 @@ package http import ( + "bytes" "errors" "fmt" "html/template" @@ -23,13 +24,24 @@ type postTplPayload struct { } func (a *api) postToPostTplPayload(storedPost post.StoredPost) (postTplPayload, error) { + + bodyTpl, err := a.parseTpl(storedPost.Body) + if err != nil { + return postTplPayload{}, fmt.Errorf("parsing post body as template: %w", err) + } + + bodyBuf := new(bytes.Buffer) + if err := bodyTpl.Execute(bodyBuf, nil); err != nil { + return postTplPayload{}, fmt.Errorf("executing post body as template: %w", err) + } + parserExt := parser.CommonExtensions | parser.AutoHeadingIDs parser := parser.NewWithExtensions(parserExt) htmlFlags := html.CommonFlags | html.HrefTargetBlank htmlRenderer := html.NewRenderer(html.RendererOptions{Flags: htmlFlags}) - renderedBody := markdown.ToHTML([]byte(storedPost.Body), parser, htmlRenderer) + renderedBody := markdown.ToHTML(bodyBuf.Bytes(), parser, htmlRenderer) tplPayload := postTplPayload{ StoredPost: storedPost, |