Skip to content

Instantly share code, notes, and snippets.

@iku000888
Last active August 25, 2018 04:08
Show Gist options
  • Save iku000888/1e4a3da9edb42bec594761c300fe8336 to your computer and use it in GitHub Desktop.
Save iku000888/1e4a3da9edb42bec594761c300fe8336 to your computer and use it in GitHub Desktop.
Rendering html from asciidoc with Clojure

Motivation

For giggles :)

Steps

  1. Add this to your dependency:
[org.asciidoctor/asciidoctorj "1.5.5"]
  1. Minimal code snippet
(require '[clojure.java.io :as io])
(import 'org.asciidoctor.Asciidoctor)
(import 'org.asciidoctor.Asciidoctor$Factory)
(import 'java.util.HashMap)

(let [inst (Asciidoctor$Factory/create)
      src  (slurp (io/file "some-file.adoc"))]
  (.convert inst src (HashMap.)))

Remarks

  • Note the '$' from Asciidoctor$Factory; that is an inner class that must be accessed with the ugly '$' character.

  • There are many flavors of the .convert method. The one used here simply returns the rendered html as a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment