On this page:

15.1 Pygments

 (require pollen/unstable/pygments) package: pollen

A simple interface to syntax highlighting using Pygments. You must already have Pygments installed to use this module. See the mini-tutorial Using Pygments with Pollen.


(highlight language    
  [#:python-executable python-executable    
  #:line-numbers? line-numbers?    
  #:css-class css-class    
  #:lines lines]    
  lines-of-code ...)  txexpr?
  language : symbol?
  python-executable : path-string? = "python"
  line-numbers? : boolean? = #t
  css-class : string? = "source"
  lines : (listof number?) = '()
  lines-of-code : string?
Use Pygments to highlight the code in lines-of-code according to the semantics of language. Does not apply any visual styling, just the markup. The optional python-executable controls which Python Pollen should use (which will be useful when you install Pygments in a non-default version of Python). The optional line-numbers? controls whether or not the syntax highlight should include line numbers. The optional css-class controls the CSS class name for the syntax highlight. The optional lines will tag the specified lines of code with the CSS class hll.

Sample input:

#lang pollen
(require pollen/unstable/pygments)
for x in range(3):
    print x

Output from this sample:

'(div ((class "highlight")) (table ((class "sourcetable")) (tbody () (tr () (td ((class "linenos")) (div ((class "linenodiv")) (pre () "1\n2"))) (td ((class "code")) (div ((class "source")) (pre () (span ((class "k")) "for") " " (span ((class "n")) "x") " " (span ((class "ow")) "in") " " (span ((class "nb")) "range") (span ((class "p")) "(") (span ((class "mi")) "3") (span ((class "p")) "):") "\n " (span ((class "k")) "print") " " (span ((class "n")) "x") "\n")) "\n")))) "\n")