Skip to content

Instantly share code, notes, and snippets.

@dbridges
Last active May 21, 2019 20:43
Show Gist options
  • Save dbridges/0905f07cebe69640987142eec40079c1 to your computer and use it in GitHub Desktop.
Save dbridges/0905f07cebe69640987142eec40079c1 to your computer and use it in GitHub Desktop.
func (c Content) HTML() template.HTML {
// Remove CDATA tags
cdata := regexp.MustCompile(`(?s)<!\[CDATA\[(.*?)\]\]>`)
body := cdata.ReplaceAllString(c.Body, "$1")
// Make path to images absolute
pat := regexp.MustCompile(`<img src="\/`)
body = pat.ReplaceAllString(body, "<img src=\"" + c.BaseURI + "/")
return template.HTML(html.UnescapeString(body))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment