A (partial) Org Mode parser in Clojure.
This library parses Emacs Org Mode format to Hiccup, which is a tree representation of HTML in the form of nested Clojure vectors.
Add the above dependency to project.clj
:
Add to your project.clj
or deps.edn
:
[eigenhombre/clj-org "0.0.3"]
Then, use clj-org.org/parse-org
to convert a string of Org Mode text into
Hiccup.
(ns myproject.core
(:require [clj-org.org :refer [parse-org]]))
(parse-org "#+TITLE: This is an Org Mode file.
* This is the outer section
** This is an inner section
Inner section body -- /with italic text/! And *bold text* too.
- Plain List Item 1
- Plain List Item 2
[[http://eigenhombre.com][A link to a Web site]]
")
... yields:
{:title "This is an Org Mode file.",
:headers "\n#+TITLE: This is an Org Mode file.\n\n",
:content
[:div
[:h1 [:p "This is the outer section"]]
[:h2 [:p "This is an inner section"]]
[:span
[:p
[:span
[:span
"Inner section body – "
[:em "with italic text"]
"! And "]
[:strong "bold text"]
" too.\n"]]
[:ul
[:li [:p "Plain List Item 1\n"]]
[:li [:p "Plain List Item 2\n"]]]
[:p
[:span
[:a {:href "http://eigenhombre.com"} "A link to a Web site"]
"\n"]]]]}
Factored out of the blorg blog prototype, this parser started out as an Instaparse grammar. However, it proved too difficult to get good performance without ambiguities, so the parser has become what is basically a series of monster regular expressions (example here).
This repo does not cover all the functionality of Org Mode supported by Emacs, but may be enough for some use cases.
I don't use this much myself anymore, but others seem to find it useful so I'll continue to maintain, and occasionally improve, the repo so long as the time commitment isn't too onerous.
Contributions/PRs welcome, but please add appropriate tests if you submit changes, and ensure that the build passes on your branch.
Copyright © 2015-2023 John Jacobsen. MIT license.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.