I've been meaning to write a blog for a long time now, but when it comes to actually writing something I just keep putting it off over and over again. Interestingly, this post is, in a way, about just that. I've again procrastinated from writing any posts - this time by instead building an org-mode parser in go. Because that's totally necessary to start writing, d'uh!
You can find the results on github. There are even some examples on github pages
And here it is running in your browser 1 because go 1.11 supports compiling to wasm - how awesome is that? I'm really starting to dig go.
I love org-mode. It's the best thing since sliced bread. Sadly, blogging with org-mode is harder than it should be. I don't know why, but everything out there that supports org feels overcomplicated or not powerful enough. And I don't even want that much:
There are some solutions, but nothing clicked for me. And then there's hugo. Hugo checks all of my requirements - and it's written in go, which I'm currently trying to learn! So hugo would be perfect - if only the org-mode support was any good. But alas, goorgeous has been abandoned and doesn't look like something I would want to maintain.
Luckily, it's not that hard to replace goorgeous in hugo - and this blog
post is rendered using the result of that. Here's the PR. For now I'm just
using go run -tags 'extended' ~/go/src/github.com/gohugoio/hugo serve
for my
blog with the changeset applied locally.
I'm still (very) actively working on it and adding new features as I find a use for them. The plan is to polish things a little more and then adding it to hugo proper. But I'm afraid that won't be a backwards compatible change without quite a lot of work, so I'm not sure that will ever happen.
Let's see if I'll write more stuff now. At least I had a lot of fun learning about parsing and go and got this post out of it.
Parsing is done in 3 steps:
code
and bold and stuff. As that markup can span multiple lines we
can only parse it once we have the complete text content of the node.We also create an outline (tree of headlines / sections) and a map of footnotes and stuff like that during parsing. But that's not really necessary, we could just build those out of the resulting AST - it's just nicer this way.
Once we have our AST we can convert it into different formats using the Writer
interface. I decided to keep the formatting separate of the node interface
(i.e. not add Org()
and HTML()
methods to each node) to make it easier /
more consistent to add new export formats outside of go-org
.