14 Module reference
14.1 Cache
14.2 Decode
14.3 File
14.4 Pagetree
14.5 Pygments
14.6 Render
14.7 Template
14.8 Tag
14.9 Top
14.10 World
On this page:
highlight
6.2.901.900

14.5 Pygments

 (require pollen/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.

procedure

(highlight language lines-of-code ...)  txexpr?

  language : symbol?
  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.

Sample input:

#lang pollen
(require pollen/pygments)
highlight['python]{
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")