Last active
May 21, 2019 20:43
-
-
Save dbridges/0905f07cebe69640987142eec40079c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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