Skip to main content

Provides previews with syntax highlight for multiple formats

Project description

Tests

ckanext-pygments

This extension provides a preview with syntax highlight for multiple text resources formats.

Caching

There is a caching mechanism implemented in this extension. It is disabled by default. To enable it, set ckanext.pygments.cache.enable to True. You can also set the time to live for the cache in seconds with ckanext.pygments.cache.ttl. The default is 7200 seconds (2 hours). You can also set the maximum size of the resource to cache in bytes with ckanext.pygments.cache.resouce_max_size. The default is 20MB.

Why cache is disabled by default?

We use Redis for caching and it uses memory. If you have a lot of resources and they are big, you can run out of memory. That's why it is disabled by default. It's still debatable if we need cache at all. Big resource processed with pygments will be even bigger. So we can have a lot of memory usage. But if we have a lot of resources and many users access it, we can save a lot of time on processing.

Admin configuration page

If you're using the ckanext-admin-panel extension, you can configure the pygments settings from the admin panel.

Configuration page

Otherwise, you can configure it in the ckan.ini file.

Config settings

Supported config options:

- key: ckanext.pygments.supported_formats
  type: list
  description: Specify a list of 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

- key: ckanext.pygments.max_size
  type: int
  description: Specify how many bytes we are going to render from file. Default to 1MB
  default: 1048576

- key: ckanext.pygments.include_htmx_asset
  description: Include HTMX asset
  default: true
  type: bool

- key: ckanext.pygments.default_theme
  description: Default theme for preview
  default: default

- key: ckanext.pygments.cache.enable
  description: Enable cache
  default: false
  type: bool

- key: ckanext.pygments.cache.preview_max_size
  description: Specify what is the maximum size of a preview we are going to cache
  default: 20971520 # 20MB
  type: int

- key: ckanext.pygments.cache.ttl
  description: Specify the time to live of the cache
  default: 7200 # 2 hours
  type: int

Tests

To run the tests, do:

pytest --ckan-ini=test.ini

License

AGPL

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ckanext_pygments-1.1.4.tar.gz (41.4 kB view details)

Uploaded Source

Built Distribution

ckanext_pygments-1.1.4-py3-none-any.whl (45.2 kB view details)

Uploaded Python 3

File details

Details for the file ckanext_pygments-1.1.4.tar.gz.

File metadata

  • Download URL: ckanext_pygments-1.1.4.tar.gz
  • Upload date:
  • Size: 41.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for ckanext_pygments-1.1.4.tar.gz
Algorithm Hash digest
SHA256 a73cd597e16f8645f98ad0fc07b8a8f1ef612bd963b0946f5b68d765e3406487
MD5 e03339884804ff2e59316c1d87fdd0e0
BLAKE2b-256 538d8d2c1c3b6aaa7594de6c2ec82959a09519f1e22e002b645961a77c3eb739

See more details on using hashes here.

File details

Details for the file ckanext_pygments-1.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for ckanext_pygments-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 962ba16c1243816c3c335668d05905ca0deb73b4b7e5cd335c3abc283f2bfad1
MD5 0f925779d8f2b6a65cc8124040f1f985
BLAKE2b-256 6175e94857e085a45e204989575eb308d1c1e6c2831d7ede338b2062e485de26

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page