Fix rendering errors near script tags

This commit is contained in:
Brian Picciano 2022-05-21 13:54:14 -06:00
parent b136b42a44
commit 7335295dc0

View File

@ -66,14 +66,19 @@ func (a *api) postToPostTplPayload(storedPost post.StoredPost) (postTplPayload,
} }
bodyBuf := new(bytes.Buffer) bodyBuf := new(bytes.Buffer)
if err := bodyTpl.Execute(bodyBuf, nil); err != nil { if err := bodyTpl.Execute(bodyBuf, nil); err != nil {
return postTplPayload{}, fmt.Errorf("executing post body as template: %w", err) return postTplPayload{}, fmt.Errorf("executing post body as template: %w", err)
} }
// this helps the markdown renderer properly parse pages which end in a
// `</script>` tag... I don't know why.
_, _ = bodyBuf.WriteString("\n")
parserExt := parser.CommonExtensions | parser.AutoHeadingIDs parserExt := parser.CommonExtensions | parser.AutoHeadingIDs
parser := parser.NewWithExtensions(parserExt) parser := parser.NewWithExtensions(parserExt)
htmlFlags := html.CommonFlags | html.HrefTargetBlank htmlFlags := html.HrefTargetBlank
htmlRenderer := html.NewRenderer(html.RendererOptions{Flags: htmlFlags}) htmlRenderer := html.NewRenderer(html.RendererOptions{Flags: htmlFlags})
renderedBody := markdown.ToHTML(bodyBuf.Bytes(), parser, htmlRenderer) renderedBody := markdown.ToHTML(bodyBuf.Bytes(), parser, htmlRenderer)