Use Pygments from Clojure
Clojure Shell
Latest commit 8ce7f0d Feb 29, 2016 @bfontaine license year bump

README.md

clygments

Build Status Coverage Status

clygments is a Clojure wrapper for Pygments.

Usage

Add the dependency in your project.clj:

[clygments "0.1.1"]

Then:

(ns your-project.core
  (:use 'clygments.core))

It exposes only one function, highlight. Give it your code as a string, its language and the desired output and it’ll do that for you :)

It’ll return a string or nil if there was an error, like an unsupported language or output.

Example

(highlight "(def x (+ 20 22))" :clojure :html)
;; => <div class=\"highlight\"><pre><span class=\"p\">(</span><span class=\"k\">def </span><span class=\"nv\">x</span> <span class=\"mi\">42</span><span class=\"p\">)</span>\n</pre></div>

Support

Langages

See Pygments’ list for a list of available languages.

Output

  • :bbcode
  • :html
  • :latex
  • :null (no formatting, this leaves the code unchanged)
  • :raw
  • :rtf
  • :svg
  • :terminal256
  • :terminal

Images outputs are not supported. See also Pygments docs for the full list.

Options

All lexers’ and formatters’ options are supported since version 0.1.1. They are given as a map to highlight and support hyphens for a better readability. See Pygments’ docs for more info.

Example

;; expand tabs to 4 spaces
(highlight "def foo():\n\tpass" :python :html {:tab-size 4})

;; generate a full standalone HTML document with a custom title
(highlight "int i = 2+2;" :C :html {:full true, :title "This is my code"})

License

Copyright © 2014-2016 Baptiste Fontaine

Distributed under the Eclipse Public License either version 1.0 or any later version.