Support Org syntax (org-mode) as an alternative to Markdown
Support for Org syntax would be very useful. It would allow Clerk notebooks to be integrated in Org knowledgebases, such as Org-roam.
I'll have a go at implementing this 👍
Feel free to assign me
Hi @olavfosse!
I’d consider supporting Org as out of scope for Clerk but it should be easy to build it as an add-on. It’s possible that we should make some small tweaks to Clerk to make this easier, this will become obvious as we’re trying this.
I know of prior art where folks integrated Org with Clerk via Pandoc. Happy to dig this up next week if you’re interested.
Ok, I'll continue my work with implementing it directly in the source code and then I'll look into implementing it as an add-on once an add-on API comes around :^)
@olavfosse and anyone else wanting something like this, I wrote a quick monkey patch against version 0.17.1102 (on Clojure 1.12.0) that converts org documents with pandoc before being parsed. Haven't tested it much yet, but it works with some simple examples I've thrown at it so far.
;;
;; Put this in the root of your classpath as clerk_org_patch.clj
;; and eval (load "/clerk_org_patch") in your project to install.
;;
(load "/nextjournal/clerk/parser")
(in-ns 'nextjournal.clerk.parser)
(require '[clojure.java.process])
(defn ^:private slurp-org-file
[file]
(clojure.java.process/exec "pandoc" "--to" "gfm" file))
(defn parse-file
([file] (parse-file {} file))
([opts file]
(cond
(str/ends-with? file ".org") (parse-markdown-string (assoc opts :file file) (slurp-org-file file))
(str/ends-with? file ".md") (parse-markdown-string (assoc opts :file file) (slurp file))
:else (parse-clojure-string (assoc opts :file file) (slurp file)))))
Might extend this to blocks if I can get my head around it, but my primary use-case is to include some existing documents alongside other notebooks. This is good enough for me to start with.
As it stands, might just go to markdown for this project. I'll leave the snippet if someone else wants to try.