Merge branch 'feat/1.0.6/fixbug' into test

This commit is contained in:
aichy126 2023-02-22 18:40:45 +08:00
commit 010cd7501d
2 changed files with 12 additions and 1 deletions

View File

@ -309,7 +309,7 @@ func (req *UpdateInfoRequest) Check() (errFields []*validator.FormErrorField, er
return errFields, errors.BadRequest(reason.UsernameInvalid)
}
}
req.BioHTML = converter.Markdown2HTML(req.Bio)
req.BioHTML = converter.Markdown2BasicHTML(req.Bio)
return nil, nil
}

View File

@ -35,6 +35,17 @@ func Markdown2HTML(source string) string {
return buf.String()
}
// Markdown2BasicHTML convert markdown to html ,Only basic syntax can be used
func Markdown2BasicHTML(source string) string {
content := Markdown2HTML(source)
filter := bluemonday.NewPolicy()
filter.AllowElements("p", "b", "br")
filter.AllowAttrs("src").OnElements("img")
filter.AddSpaceWhenStrippingTag(true)
content = filter.Sanitize(content)
return content
}
type DangerousHTMLFilterExtension struct {
}