Skip to content

Commit d8f6400

Browse files
committed
Raise SuperFencesException instead of silent fail on invalid JSON schema
1 parent 55e2dac commit d8f6400

File tree

5 files changed

+9
-14
lines changed

5 files changed

+9
-14
lines changed

mkdocs_charts_plugin/fences.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pymdownx.superfences import _escape
2+
from pymdownx.superfences import SuperFencesException
23

34
from mkdocs.exceptions import PluginError
45

@@ -11,7 +12,7 @@ def fence_vegalite(source, language, class_name, options, md, **kwargs):
1112
""" # noqa
1213

1314
if not _validateJSON(source):
14-
raise PluginError(f"Your vegalite syntax is not valid JSON. Fix {source}")
15+
raise SuperFencesException from PluginError(f"Your vegalite syntax is not valid JSON. Fix:\n\n{source}")
1516

1617
classes = kwargs["classes"]
1718
id_value = kwargs["id_value"]

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="mkdocs-charts-plugin",
8-
version="0.0.6",
8+
version="0.0.7",
99
description="MkDocs plugin to add charts from data",
1010
long_description=long_description,
1111
long_description_content_type="text/markdown",
@@ -26,7 +26,7 @@
2626
"Programming Language :: Python :: 3.10",
2727
"License :: OSI Approved :: MIT License",
2828
],
29-
install_requires=["mkdocs>=1.1", "pymdown-extensions>=9.1"],
29+
install_requires=["mkdocs>=1.1", "pymdown-extensions>=9.2"],
3030
packages=find_packages(),
3131
entry_points={
3232
"mkdocs.plugins": ["charts = mkdocs_charts_plugin.plugin:ChartsPlugin"]

tests/fixtures/projects/invalid_json/docs/index.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ For full documentation visit [mkdocs.org](https://www.mkdocs.org).
55

66
## charts on invalid json
77

8+
This one should give a plugin error because we can parse the JSOn in python (notice the trailing komma on the last line makes the JSON invalid):
89

9-
This one should give a plugin error because we can parse the JSOn in python (notice the trailing komma makes the JSON invalid):
10-
11-
```chartvegalite
10+
```vegalite
1211
{
1312
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
1413
"data": {
@@ -29,5 +28,5 @@ This one should give a plugin error because we can parse the JSOn in python (not
2928
"contains": "padding",
3029
"resize": "true"
3130
}
32-
}
31+
},
3332
```

tests/fixtures/projects/invalid_json/mkdocs.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ site_name: My Docs
66
# - navigation.instant
77

88
plugins:
9-
# - search
109
- charts:
1110
vega_theme: dark
1211
vega_renderer: "canvas"
@@ -20,7 +19,7 @@ markdown_extensions:
2019
custom_fences:
2120
- name: vegalite
2221
class: vegalite
23-
format: !!python/name:mkdocs_charts_plugin.fence_vegalite_custom
22+
format: !!python/name:mkdocs_charts_plugin.fences.fence_vegalite
2423
- pymdownx.tabbed:
2524
alternate_style: true
2625

tests/test_building.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ def test_basic_build(tmp_path):
107107
check_build(tmp_path, "basic/mkdocs.yml")
108108

109109

110-
@pytest.mark.skip(reason="Custom fences currently cannot raise errors")
111-
def test_error_invalid_json(tmp_path):
110+
def test_error_invalid_json(tmp_path, capsys):
112111
"""
113112
Waiting for this feature.
114113
@@ -117,8 +116,5 @@ def test_error_invalid_json(tmp_path):
117116
tmp_proj = setup_clean_mkdocs_folder(
118117
"tests/fixtures/projects/invalid_json/mkdocs.yml", tmp_path
119118
)
120-
121119
result = build_docs_setup(tmp_proj)
122-
123120
assert result.exit_code == 1
124-
assert "Your vegalite syntax is not valid JSON." in result.output

0 commit comments

Comments
 (0)