ckanext-pygments


Nameckanext-pygments JSON
Version 1.2.1 PyPI version JSON
download
home_pageNone
SummaryProvides previews with syntax highlight for multiple formats
upload_time2024-10-24 13:28:39
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseAGPL
keywords ckan
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            [![Tests](https://github.com/mutantsan/ckanext-pygments/workflows/Tests/badge.svg?branch=main)](https://github.com/mutantsan/ckanext-pygments/actions)

# 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](https://github.com/mutantsan/ckanext-admin-panel) extension, you can configure the pygments settings from the admin panel.

![Configuration page](doc/config.png)

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

## Config settings

Supported config options:

```yaml
- 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](https://www.gnu.org/licenses/agpl-3.0.en.html)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ckanext-pygments",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": "DataShades <datashades@linkdigital.com.au>",
    "keywords": "CKAN",
    "author": null,
    "author_email": "DataShades <datashades@linkdigital.com.au>, Sergey Motornyuk <sergey.motornyuk@linkdigital.com.au>, Oleksandr Cherniavskyi <mutantsan@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/3c/81/7dd71d8b7c2e86dea1b0df2e29f13e4827c1ffa7f4d0e4b0f9a897a9fa2a/ckanext_pygments-1.2.1.tar.gz",
    "platform": null,
    "description": "[![Tests](https://github.com/mutantsan/ckanext-pygments/workflows/Tests/badge.svg?branch=main)](https://github.com/mutantsan/ckanext-pygments/actions)\n\n# ckanext-pygments\n\nThis extension provides a preview with syntax highlight for multiple text resources formats.\n\n## Caching\nThere 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.\n\n### Why cache is disabled by default?\nWe 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.\nIt'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.\n\n### Admin configuration page\nIf you're using the [ckanext-admin-panel](https://github.com/mutantsan/ckanext-admin-panel) extension, you can configure the pygments settings from the admin panel.\n\n![Configuration page](doc/config.png)\n\nOtherwise, you can configure it in the `ckan.ini` file.\n\n## Config settings\n\nSupported config options:\n\n```yaml\n- key: ckanext.pygments.supported_formats\n  type: list\n  description: Specify a list of supported formats\n  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\n\n- key: ckanext.pygments.max_size\n  type: int\n  description: Specify how many bytes we are going to render from file. Default to 1MB\n  default: 1048576\n\n- key: ckanext.pygments.include_htmx_asset\n  description: Include HTMX asset\n  default: true\n  type: bool\n\n- key: ckanext.pygments.default_theme\n  description: Default theme for preview\n  default: default\n\n- key: ckanext.pygments.cache.enable\n  description: Enable cache\n  default: false\n  type: bool\n\n- key: ckanext.pygments.cache.preview_max_size\n  description: Specify what is the maximum size of a preview we are going to cache\n  default: 20971520 # 20MB\n  type: int\n\n- key: ckanext.pygments.cache.ttl\n  description: Specify the time to live of the cache\n  default: 7200 # 2 hours\n  type: int\n```\n\n## Tests\n\nTo run the tests, do:\n\n    pytest --ckan-ini=test.ini\n\n## License\n\n[AGPL](https://www.gnu.org/licenses/agpl-3.0.en.html)\n",
    "bugtrack_url": null,
    "license": "AGPL",
    "summary": "Provides previews with syntax highlight for multiple formats",
    "version": "1.2.1",
    "project_urls": {
        "Homepage": "https://github.com/DataShades/ckanext-pygments"
    },
    "split_keywords": [
        "ckan"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5c6088786244071cc1150faf1d0541beb1dce0d7432d832ed98f863a396ac8f8",
                "md5": "9d6ac757b25c5a7233920db19a980757",
                "sha256": "69c39f94cd4911674c996ca73c6f14b5e339cc336b745b5dd90f69478d4ce8fd"
            },
            "downloads": -1,
            "filename": "ckanext_pygments-1.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9d6ac757b25c5a7233920db19a980757",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 47714,
            "upload_time": "2024-10-24T13:28:38",
            "upload_time_iso_8601": "2024-10-24T13:28:38.485942Z",
            "url": "https://files.pythonhosted.org/packages/5c/60/88786244071cc1150faf1d0541beb1dce0d7432d832ed98f863a396ac8f8/ckanext_pygments-1.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3c817dd71d8b7c2e86dea1b0df2e29f13e4827c1ffa7f4d0e4b0f9a897a9fa2a",
                "md5": "645e9f3e5bb8e704f82c2083ad476aec",
                "sha256": "1231424b609d76e58ef0f6e12adb7badc7dc3e8e3ae93723568081eab7ed5ad7"
            },
            "downloads": -1,
            "filename": "ckanext_pygments-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "645e9f3e5bb8e704f82c2083ad476aec",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 43692,
            "upload_time": "2024-10-24T13:28:39",
            "upload_time_iso_8601": "2024-10-24T13:28:39.709432Z",
            "url": "https://files.pythonhosted.org/packages/3c/81/7dd71d8b7c2e86dea1b0df2e29f13e4827c1ffa7f4d0e4b0f9a897a9fa2a/ckanext_pygments-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-24 13:28:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "DataShades",
    "github_project": "ckanext-pygments",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "lcname": "ckanext-pygments"
}
        
Elapsed time: 0.73398s