yogthos / markdown-clj

Markdown parser in Clojure
Eclipse Public License 1.0
540 stars 120 forks source link

feat: add callback on codeblocks #191

Closed youkwhd closed 11 months ago

youkwhd commented 11 months ago

Changed the writing behavior of codeblock transformer (buffering it first)

An example of a use case:

(markdown/md-to-html-string "```python\ndef f(x):\n    return x * 2\n```"
                       :codeblock-callback (fn
                                             [code language]
                                             (trim (clygments/highlight code language :html))))

Code above would syntax highlight codeblocks without being bothered to convert the Markdown to HTML first then calling libraries like highlight.js with JavaScript

References:

yogthos commented 11 months ago

Thanks for the pr, just pushed out 1.11.5 with the feature to Clojars.