Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bfontaine/clygments
:art: Code highlighting using Pygments in Clojure
https://github.com/bfontaine/clygments
clojure library pygments syntax-highlighting
Last synced: 16 days ago
JSON representation
:art: Code highlighting using Pygments in Clojure
- Host: GitHub
- URL: https://github.com/bfontaine/clygments
- Owner: bfontaine
- License: epl-1.0
- Created: 2014-02-12T18:39:44.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2020-11-07T09:52:46.000Z (about 4 years ago)
- Last Synced: 2024-12-08T21:03:16.972Z (18 days ago)
- Topics: clojure, library, pygments, syntax-highlighting
- Language: Clojure
- Homepage:
- Size: 43 KB
- Stars: 30
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# clygments
[![Build Status](https://img.shields.io/travis/bfontaine/clygments.svg)](https://travis-ci.org/bfontaine/clygments)
[![Coverage Status](https://img.shields.io/coveralls/bfontaine/clygments.svg)](https://coveralls.io/r/bfontaine/clygments)
[![Clojars Project](https://img.shields.io/clojars/v/clygments.svg)](https://clojars.org/clygments)**clygments** is a Clojure wrapper for [Pygments][].
[Pygments]: http://pygments.org/
## Usage
Add the dependency in your `project.clj`:
```clj
[clygments "2.0.2"]
```Then:
```clj
(ns your-project.core
(:require [clygments.core :as clygments]))
```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
```clj
(clygments/highlight "(def x (+ 20 22))" :clojure :html)
;; =>(def x 42)\n
```## Support
Clygments 1.0.0+ only supports Java 7+.
### Langages
See [Pygments’ list][lexers] for a list of available languages.
If `nil` is passed as a language we use Pygments’ [`guess_lexer`](http://pygments.org/docs/api/#pygments.lexers.guess_lexer).
Note it takes more time and might not be accurate on small code snippets.### Output
* `:bbcode`
* `:html`
* `:latex`
* `:null` (no formatting, this leaves the code unchanged)
* `:raw`
* `:rtf`
* `:svg`
* `:terminal256`
* `:terminal`Images outputs are [not][issue-2] supported. See also
[Pygments docs][formatters] for the full list.[issue-2]: https://github.com/bfontaine/clygments/issues/2#issuecomment-35169407
### 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
```clj
;; expand tabs to 4 spaces
(cligments/highlight "def foo():\n\tpass" :python :html {:tab-size 4});; generate a full standalone HTML document with a custom title
(cligments/highlight "int i = 2+2;" :C :html {:full true, :title "This is my code"})
```[lexers]: http://pygments.org/docs/lexers/
[formatters]: http://pygments.org/docs/formatters/## License
Copyright © 2014-2020 Baptiste Fontaine
Distributed under the Eclipse Public License either version 1.0 or any later
version.