A simple page for all your links.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

50 lines
1.4 KiB

  1. package publicbio
  2. import (
  3. "github.com/microcosm-cc/bluemonday"
  4. "github.com/writeas/saturday"
  5. "github.com/writeas/web-core/converter"
  6. "html/template"
  7. )
  8. // Profile is a publicly-viewable user, containing only the data necessary
  9. // to display a profile.
  10. type Profile struct {
  11. AvatarURL string `json:"avatar_url"`
  12. Username string `json:"username"`
  13. Name converter.NullJSONString `json:"name"`
  14. Header converter.NullJSONString `json:"header"`
  15. Bio converter.NullJSONString `json:"bio"`
  16. Links []Link `json:"links"`
  17. }
  18. func (p *Profile) RenderedBio() template.HTML {
  19. return template.HTML(applyMarkdown(p.Bio.String))
  20. }
  21. func applyMarkdown(data string) string {
  22. mdExtensions := 0 |
  23. blackfriday.EXTENSION_TABLES |
  24. blackfriday.EXTENSION_FENCED_CODE |
  25. blackfriday.EXTENSION_AUTOLINK |
  26. blackfriday.EXTENSION_STRIKETHROUGH |
  27. blackfriday.EXTENSION_SPACE_HEADERS |
  28. blackfriday.EXTENSION_HEADER_IDS
  29. htmlFlags := 0 |
  30. blackfriday.HTML_USE_SMARTYPANTS |
  31. blackfriday.HTML_SMARTYPANTS_DASHES
  32. // Generate Markdown
  33. md := blackfriday.Markdown([]byte(data), blackfriday.HtmlRenderer(htmlFlags, "", ""), mdExtensions)
  34. // Strip out bad HTML
  35. policy := bluemonday.UGCPolicy()
  36. policy.AllowAttrs("target").OnElements("a")
  37. policy.AllowAttrs("style", "class", "id").Globally()
  38. return string(policy.SanitizeBytes(md))
  39. }
  40. type Link struct {
  41. Title string `json:"title"`
  42. URL string `json:"url"`
  43. }