ext:pygmentize — Syntax highlight a listing with pygmentize.



ext:pygmentize($listing as xs:string) as xs:string
ext:pygmentize($listing as xs:string,
$options as item()) as xs:string
ext:pygmentize($listing as xs:string,
$options as item(),
$pygments-options as map(xs:string,xs:string)) as xs:string


This extension function runs the pygmentize command to add syntax highlighting to a listing.

The second argument can either be map, in which case the key-value pairs of the map constitute the options, or it can be a single string. If it’s a single string, it’s interpreted as if it was a map with the key “language” and the string as the value.

The third argument must be a map. Each key-value pair will be passed to pygmentize as “-Pkey=value”.

The function returns the string output from pygmentize. It must be parsed with parse-xml if you wish to process it as XML.

Be aware that pygmentize strips leading blank lines off of the source listing. If you’re selecting portions of a listing with XInclude, make sure not to select leading blank lines in the listing if you are trying to accurately count the lines.