Skip to content

Instantly share code, notes, and snippets.

@kurohuku
Created March 10, 2013 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurohuku/5127092 to your computer and use it in GitHub Desktop.
Save kurohuku/5127092 to your computer and use it in GitHub Desktop.

Markdownプロセッサ PegDown

JavaのMarkdown処理ライブラリ、PegDownを使ってみます。

;; leiningen :depencencies
[org.pegdown/pegdown "1.2.0"]

コンストラクタの引数に拡張機能を表すオプションを指定できます。

とりあえず Extensions/ALL を指定しておけば GitHub Flavored Markdown形式のコードブロックも処理できようです。

(import '[org.pegdown PegDownProcessor Extensions])

(defn md->html [source]
  (let [parser (PegDownProcessor. Extensions/ALL)]
    (.markdownToHtml parser source)))
(md->html "#hello\n```clojure\n(list 1 2)\n```")
;; => "<h1>hello</h1>\n<pre><code class=\"clojure\">(list 1 2)\n</code></pre>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment