跳转到主要内容

提供多种文本资源格式的高亮预览

项目描述

Tests

ckanext-pygments

此扩展提供了多种文本资源格式的高亮预览。

缓存

此扩展中实现了一种缓存机制。默认情况下它是禁用的。要启用它,将ckanext.pygments.cache.enable设置为True。您还可以使用ckanext.pygments.cache.ttl设置缓存的时间生存周期(以秒为单位)。默认值为7200秒(2小时)。您还可以使用ckanext.pygments.cache.resource_max_size设置要缓存的资源的最大大小(以字节为单位)。默认值为20MB。

为什么默认禁用缓存?

我们使用Redis进行缓存,它使用内存。如果您有很多资源并且它们很大,可能会耗尽内存。这就是为什么它默认禁用。我们还在讨论是否真的需要缓存。经过pygments处理的大资源将会更大。因此,我们可能会有大量的内存使用。但是,如果有很多资源和许多用户访问它们,我们可以在处理上节省很多时间。

管理员配置页面

如果您使用的是ckanext-admin-panel扩展,您可以从管理员面板配置pygments设置。

Configuration page

否则,您可以在ckan.ini文件中配置它。

配置设置

支持的配置选项

- 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

测试

要运行测试,请执行

pytest --ckan-ini=test.ini

许可协议

AGPL

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

ckanext_pygments-1.2.0.tar.gz (42.4 kB 查看哈希值)

上传时间

构建分发

ckanext_pygments-1.2.0-py3-none-any.whl (46.7 kB 查看哈希值)

上传时间 Python 3

由以下支持