diff --git a/Anime.go b/Anime.go index 5158e37..c8e5228 100644 --- a/Anime.go +++ b/Anime.go @@ -3,6 +3,7 @@ package arn import ( "errors" "fmt" + "github.com/aerogo/markdown" "sort" "strconv" "strings" @@ -98,6 +99,8 @@ type Anime struct { // SynopsisSource string `json:"synopsisSource" editable:"true"` // Hashtag string `json:"hashtag"` + + html string } // NewAnime creates a new anime. @@ -788,6 +791,16 @@ func FilterAnime(filter func(*Anime) bool) []*Anime { return filtered } +// HTML returns the HTML representation of the anime summary. +func (anime *Anime) HTML() string { + if anime.html != "" { + return anime.html + } + + anime.html = markdown.Render(anime.Summary) + return anime.html +} + // // SetID performs a database-wide ID change. // // Calling this will automatically save the anime. // func (anime *Anime) SetID(newID string) { diff --git a/AnimeAPI.go b/AnimeAPI.go index 36dbd2b..0d40dc6 100644 --- a/AnimeAPI.go +++ b/AnimeAPI.go @@ -3,6 +3,7 @@ package arn import ( "errors" "fmt" + "github.com/aerogo/markdown" "os" "path" "reflect" @@ -98,6 +99,7 @@ func (anime *Anime) Authorize(ctx *aero.Context, action string) error { func (anime *Anime) AfterEdit(ctx *aero.Context) error { anime.Edited = DateTimeUTC() anime.EditedBy = GetUserFromContext(ctx).ID + anime.html = markdown.Render(anime.Summary) return nil }