helpers.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package helpers
  2. import (
  3. "github.com/gomarkdown/markdown"
  4. "github.com/gomarkdown/markdown/html"
  5. "github.com/gomarkdown/markdown/parser"
  6. )
  7. const TECHNICAL = "technical"
  8. const CONFIGURATION = "configuration"
  9. const BLOG = "blog"
  10. const CREATIVE = "creative"
  11. const DIGITAL_ART = "digital_art"
  12. const HOMEPAGE = "homepage"
  13. var Topics = []string{
  14. TECHNICAL,
  15. BLOG,
  16. CREATIVE,
  17. HOMEPAGE,
  18. }
  19. type HeaderCollection struct {
  20. Category string `json:"category"`
  21. Elements []HeaderElem `json:"elements"`
  22. }
  23. type HeaderElem struct {
  24. Png string `json:"png"`
  25. Link string `json:"link"`
  26. }
  27. type ImageElement struct {
  28. ImgUrl string `json:"img_url"`
  29. }
  30. type MenuElement struct {
  31. Png string `json:"png"`
  32. Category string `json:"category"`
  33. MenuLinks []MenuLinkPair `json:"menu_links"`
  34. }
  35. type DocumentOld struct {
  36. Ident Identifier `json:"identifier"`
  37. Created string `json:"created"`
  38. Body string `json:"body"`
  39. Category string `json:"category"`
  40. Sample string
  41. }
  42. type AdminPage struct {
  43. Tables map[string][]TableData `json:"tables"`
  44. }
  45. type TableData struct { // TODO: add this to the database io interface
  46. DisplayName string `json:"display_name"`
  47. Link string `json:"link"`
  48. }
  49. /*
  50. convert markdown to html
  51. :param md: the byte array containing the Markdown to convert
  52. */
  53. func MdToHTML(md []byte) []byte {
  54. extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock
  55. p := parser.NewWithExtensions(extensions)
  56. doc := p.Parse(md)
  57. htmlFlags := html.CommonFlags | html.HrefTargetBlank
  58. opts := html.RendererOptions{Flags: htmlFlags}
  59. renderer := html.NewRenderer(opts)
  60. return markdown.Render(doc, renderer)
  61. }