Merge pull request #660 from writefreely/fix-alt-text

Loosen restrictions on rendered img alt attribute
This commit is contained in:
Matt Baer 2023-04-07 11:26:43 -04:00 committed by GitHub
commit 2ba840634b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -270,6 +270,7 @@ func getSanitizationPolicy() *bluemonday.Policy {
policy.AllowAttrs("target").OnElements("a") policy.AllowAttrs("target").OnElements("a")
policy.AllowAttrs("title").OnElements("abbr") policy.AllowAttrs("title").OnElements("abbr")
policy.AllowAttrs("style", "class", "id").Globally() policy.AllowAttrs("style", "class", "id").Globally()
policy.AllowAttrs("alt").OnElements("img")
policy.AllowElements("header", "footer") policy.AllowElements("header", "footer")
policy.AllowURLSchemes("http", "https", "mailto", "xmpp") policy.AllowURLSchemes("http", "https", "mailto", "xmpp")
return policy return policy
@ -284,12 +285,13 @@ func sanitizePost(content string) string {
// choosing what to generate. In case a post has a title, this function will // choosing what to generate. In case a post has a title, this function will
// fail, and logic should instead be implemented to skip this when there's no // fail, and logic should instead be implemented to skip this when there's no
// title, like so: // title, like so:
// var desc string //
// if title == "" { // var desc string
// desc = postDescription(content, title, friendlyId) // if title == "" {
// } else { // desc = postDescription(content, title, friendlyId)
// desc = shortPostDescription(content) // } else {
// } // desc = shortPostDescription(content)
// }
func postDescription(content, title, friendlyId string) string { func postDescription(content, title, friendlyId string) string {
maxLen := 140 maxLen := 140