Extension Pygments


Extension Basics

Title
Pygments
Name
ckanext-pygments
Type
Public extension
Description
Provides syntax-highlighted previews for multiple text resource formats using Pygments library
CKAN versions

~2.9, ~2.10, ~2.11

Show details
Download-Url (zip)
Download-Url commit date
2025-04-24
Url to repo
Category
Visualization & Analytics


Background Infos

Description (long)
Show details

The pygments extension provides syntax-highlighted preview functionality for multiple text resource formats in CKAN using the Pygments library. It supports a wide range of formats including SQL, HTML, Python, JavaScript, JSON, YAML, XML, Markdown, PHP, and many more (configurable list of supported formats). Features include optional Redis-based caching (disabled by default to conserve memory), configurable maximum file size for rendering (default 1MB), configurable maximum preview size for caching (default 20MB), customizable syntax highlighting themes, TTL configuration for cache (default 2 hours), and optional HTMX asset inclusion. Admin configuration page available when using ckanext-admin-panel extension. Caching is disabled by default because big resources processed with Pygments can consume significant memory, but can be enabled for performance when many users access the same resources.

Version
1.2.3
Version release date
2025-04-24
Contact name
DataShades
Contakt email
Contact Url
(not set)


Installation Guide

Configuration hints

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

Plugins to configure (ckan.ini)
pygments_view
CKAN Settings (ckan.ini)
# ckanext.pygments.supported_formats = sql html xml py js json yaml md rst php # ckanext.pygments.max_size = 1048576 # ckanext.pygments.include_htmx_asset = true # ckanext.pygments.default_theme = monokai # ckanext.pygments.cache.enable = true # ckanext.pygments.cache.preview_max_size = 20971520 # ckanext.pygments.cache.ttl = 7200
DB migration to be executed
(not set)
<< back to Extensions