Skip to content

Commit

Permalink
update: update format selector config option, allow using any format
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantsan committed Sep 11, 2024
1 parent 1145804 commit 4b9ac02
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
10 changes: 1 addition & 9 deletions ckanext/pygments/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,7 @@


def is_format_supported(fmt: str) -> bool:
"""Check if the format is supported by the pygments library"""
if fmt not in tk.config[CONF_SUPPORTED_FORMATS]:
return False

for formats in pygment_utils.LEXERS:
if fmt in formats:
return True

return False
return fmt in tk.config[CONF_SUPPORTED_FORMATS].split(",")


def bytes_to_render() -> int:
Expand Down
3 changes: 1 addition & 2 deletions ckanext/pygments/config_declaration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ groups:
- annotation: ckanext-pygments
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
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
editable: true

- key: ckanext.pygments.max_size
Expand Down
11 changes: 5 additions & 6 deletions ckanext/pygments/config_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ fields:
help_text: Specify a list of supported formats
required: true
choices_helper: pygments_supported_formats_options
form_select_attrs:
data-module: autocomplete
data-module-tags: ""
# data-module-createtags: "true"
multiple: 1
class: ""
validators: not_missing unicode_safe
form_snippet: tom_select.html
form_attrs:
multiple: "true"
data-module-load-url: "/api/action/pygments_formats_list"

- field_name: ckanext.pygments.max_size
label: Max Size
Expand Down
14 changes: 14 additions & 0 deletions ckanext/pygments/logic/action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from ckan.plugins import toolkit as tk

import ckanext.pygments.utils as pygment_utils


@tk.side_effect_free
def pygments_formats_list(context, data_dict):
result = []

for formats, _ in pygment_utils.LEXERS.items():
for res_format in formats:
result.append({"value": res_format, "text": res_format})

return result
1 change: 1 addition & 0 deletions ckanext/pygments/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@tk.blanket.validators
@tk.blanket.config_declarations
@tk.blanket.blueprints
@tk.blanket.actions
class PygmentsPlugin(p.SingletonPlugin):
p.implements(p.IConfigurer)
p.implements(p.IResourceView, inherit=True)
Expand Down
7 changes: 5 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = ckanext-pygments
version = 1.1.2
version = 1.1.3
description = Provides previews with syntax highlight for multiple formats
long_description = file: README.md
long_description_content_type = text/markdown
Expand All @@ -19,7 +19,8 @@ keywords = CKAN
[options]
packages = find:
namespace_packages = ckanext
install_requires = Pygments~=2.16.1
install_requires =
Pygments~=2.16.1
include_package_data = True

[options.entry_points]
Expand All @@ -30,6 +31,8 @@ babel.extractors =
ckan = ckan.lib.extract:extract_ckan

[options.extras_require]
admin =
ckanext-admin_panel>=1.0.14

[extract_messages]
keywords = translate isPlural
Expand Down

0 comments on commit 4b9ac02

Please sign in to comment.