fix note rendering

This commit is contained in:
Niko Abeler 2022-12-01 19:37:13 +01:00
parent c67535c1d9
commit 48a11ab6d7
4 changed files with 11 additions and 11 deletions

View File

@ -168,7 +168,7 @@ func (post *Post) Content() []byte {
return data
}
func (post *Post) RenderedContent() bytes.Buffer {
func (post *Post) RenderedContent() string {
data := post.Content()
// trim yaml block
@ -204,7 +204,7 @@ func (post *Post) RenderedContent() bytes.Buffer {
panic(err)
}
return buf
return buf.String()
}
@ -366,7 +366,7 @@ func (post *Post) ScanForLinks() error {
// this could be done in markdown parsing, but I don't want to
// rely on goldmark for this (yet)
postHtml := post.RenderedContent()
links, _ := post.user.repo.Parser.ParseLinksFromString(postHtml.String())
links, _ := post.user.repo.Parser.ParseLinksFromString(postHtml)
// add reply url if set
if post.Meta().Reply.Url != "" {
links = append(links, post.Meta().Reply.Url)

View File

@ -80,8 +80,7 @@ func TestNoRawHTMLIfDisallowedByRepo(t *testing.T) {
content += "<script>alert('foo')</script>\n"
os.WriteFile(post.ContentFile(), []byte(content), 0644)
html := post.RenderedContent()
html_str := html.String()
assertions.AssertNotContains(t, html_str, "<script>")
assertions.AssertNotContains(t, html, "<script>")
}
func TestRawHTMLIfAllowedByRepo(t *testing.T) {
@ -96,8 +95,7 @@ func TestRawHTMLIfAllowedByRepo(t *testing.T) {
content += "<script>alert('foo')</script>\n"
os.WriteFile(post.ContentFile(), []byte(content), 0644)
html := post.RenderedContent()
html_str := html.String()
assertions.AssertContains(t, html_str, "<script>")
assertions.AssertContains(t, html, "<script>")
}
func TestLoadMeta(t *testing.T) {

View File

@ -99,7 +99,7 @@ func renderPostContent(post *Post) (string, error) {
postHtml, err := renderEmbedTemplate("embed/post.html", PostRenderData{
Title: post.Title(),
Post: post,
Content: template.HTML(buf.String()),
Content: template.HTML(buf),
})
return postHtml, err
}

View File

@ -143,9 +143,11 @@ func TestCanRenderIndexPageNoTitle(t *testing.T) {
func TestRenderNoteAsFullContent(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPostFull(owl.PostMeta{Type: "note"}, "hi")
result, _ := owl.RenderPost(post)
assertions.AssertContains(t, result, "hi")
user.CreateNewPostFull(owl.PostMeta{Type: "note"}, "This is a note")
result, _ := owl.RenderPostList(user, &owl.PostList{
Include: []string{"note"},
})
assertions.AssertContains(t, result, "This is a note")
}
func TestIndexPageContainsHFeedContainer(t *testing.T) {