Requirements:
- Pygments>=2.19.1,<3.0.0
- Optional: ckanext-admin_panel>=1.0.14 for admin config page
- Optional: Redis for caching
Installation:
pip install ckanext-pygments
With admin panel support:
pip install ckanext-pygments[admin]
Add to ckan.plugins:
pygments_view
Configuration:
Supported formats (default: sql html xhtml htm xslt py pyw pyi jy sage sc rs rs.in rst rest md markdown xml xsl rss xslt xsd wsdl wsf json jsonld yaml yml dtd php inc rdf ttl js)
ckanext.pygments.supported_formats = sql html xml py js json yaml md rst php
Maximum bytes to render from file (default: 1MB)
ckanext.pygments.max_size = 1048576
Include HTMX asset (default: true)
ckanext.pygments.include_htmx_asset = true
Default syntax highlighting theme (default: default)
Options: default, monokai, solarized-dark, solarized-light, vim, etc.
ckanext.pygments.default_theme = monokai
Enable cache (default: false - disabled to conserve Redis memory)
ckanext.pygments.cache.enable = true
Maximum preview size to cache in bytes (default: 20MB)
ckanext.pygments.cache.preview_max_size = 20971520
Cache TTL in seconds (default: 7200 = 2 hours)
ckanext.pygments.cache.ttl = 7200
Caching Notes:
- Disabled by default to prevent Redis memory exhaustion
- Large resources become even larger after Pygments processing
- Enable only if: you have sufficient Redis memory AND many users access same resources
- Benefits: Saves processing time for frequently accessed resources
- Drawbacks: High memory usage for large/many resources
Admin Configuration:
If using ckanext-admin-panel, configure settings via admin panel UI instead of ckan.ini.
Supported Formats (configurable):
- Programming: Python, JavaScript, PHP, Ruby, C/C++, Java, etc.
- Markup: HTML, XML, YAML, JSON, Markdown, RST
- Data: SQL, CSV, RDF, TTL
- Configuration: INI, TOML, properties
- And many more via Pygments lexers
Testing: pytest –ckan-ini=test.ini