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.

66 lines
2.4 KiB

  1. #+TITLE: chaseadamsio/goorgeous
  2. [[https://travis-ci.org/chaseadamsio/goorgeous.svg?branch=master]]
  3. [[https://coveralls.io/repos/github/chaseadamsio/goorgeous/badge.svg?branch=master]]
  4. /goorgeous is a Go Org to HTML Parser./
  5. [[file:gopher_small.gif]]
  6. *Pronounced: Go? Org? Yes!*
  7. #+BEGIN_QUOTE
  8. "Org mode is for keeping notes, maintaining TODO lists, planning projects, and authoring documents with a fast and effective plain-text system."
  9. - [[orgmode.org]]
  10. #+END_QUOTE
  11. The purpose of this package is to come as close as possible as parsing an =*.org= document into HTML, the same way one might publish [[http://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html][with org-publish-html from Emacs]].
  12. * Installation
  13. #+BEGIN_SRC sh
  14. go get -u github.com/chaseadamsio/goorgeous
  15. #+END_SRC
  16. * Usage
  17. ** Org Headers
  18. To retrieve the headers from a =[]byte=, call =OrgHeaders= and it will return a =map[string]interface{}=:
  19. #+BEGIN_SRC go
  20. input := "#+title: goorgeous\n* Some Headline\n"
  21. out := goorgeous.OrgHeaders(input)
  22. #+END_SRC
  23. #+BEGIN_SRC go
  24. map[string]interface{}{
  25. "title": "goorgeous"
  26. }
  27. #+END_SRC
  28. ** Org Content
  29. After importing =github.com/chaseadamsio/goorgeous=, you can call =Org= with a =[]byte= and it will return an =html= version of the content as a =[]byte=
  30. #+BEGIN_SRC go
  31. input := "#+TITLE: goorgeous\n* Some Headline\n"
  32. out := goorgeous.Org(input)
  33. #+END_SRC
  34. =out= will be:
  35. #+BEGIN_SRC html
  36. <h1>Some Headline</h1>/n
  37. #+END_SRC
  38. * Why?
  39. First off, I've become an unapologetic user of Emacs & ever since finding =org-mode= I use it for anything having to do with writing content, organizing my life and keeping documentation of my days/weeks/months.
  40. Although I like Emacs & =emacs-lisp=, I publish all of my html sites with [[https://gohugo.io][Hugo Static Site Generator]] and wanted to be able to write my content in =org-mode= in Emacs rather than markdown.
  41. Hugo's implementation of templating and speed are unmatched, so the only way I knew for sure I could continue to use Hugo and write in =org-mode= seamlessly was to write a golang parser for org content and submit a PR for Hugo to use it.
  42. * Acknowledgements
  43. I leaned heavily on russross' [[https://github.com/russross/blackfriday][blackfriday markdown renderer]] as both an example of how to write a parser (with some updates to leverage the go we know today) and reusing the blackfriday HTML Renderer so I didn't have to write my own!