From ec70ab701556f8be0647da992ff23f7fd2a11bb0 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Fri, 29 Sep 2023 08:57:23 -0400 Subject: [PATCH] WIP --- docs/index.rst | 9 +++++---- sphinx_json_schema_spec/__init__.py | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 0c3379d..e621ca2 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -5,9 +5,10 @@ Usage ----- -The extension currently provides a single Sphinx `role`: +The extension currently provides a single Sphinx `domain` (named +**jsonschema**). It provides: -.. rst:role:: kw +.. rst:role:: jsonschema:keyword Link to the current JSON Schema specification's definition of the keyword provided. @@ -15,11 +16,11 @@ For instance, writing: .. code-block:: rst - Reference resolution in JSON Schema is done using the :kw:`$ref` keyword. + Reference resolution in JSON Schema is done using the :jsonschema:keyword:`$ref` keyword. will produce: - Reference resolution in JSON Schema is done using the :kw:`$ref` keyword. + Reference resolution in JSON Schema is done using the :jsonschema:keyword:`$ref` keyword. In addition, the extension automatically populates the Sphinx glossary with terms from the `JSON Schema Glossary `_, such that: diff --git a/sphinx_json_schema_spec/__init__.py b/sphinx_json_schema_spec/__init__.py index fa7acf7..b298ef8 100644 --- a/sphinx_json_schema_spec/__init__.py +++ b/sphinx_json_schema_spec/__init__.py @@ -15,6 +15,7 @@ from docutils import nodes from lxml import html +import sphinx.domains BASE_URL = "https://json-schema.org/draft/2020-12/" VOCABULARIES = { @@ -28,6 +29,18 @@ } +def create_domain(vocabularies): + class JSONSchema(sphinx.domains.Domain): + + name = "jsonschema" + label = "JSON Schema" + + roles = { + "keyword": docutils_does_not_allow_using_classes(vocabularies) + } + return JSONSchema + + def setup(app): """ Install the plugin. @@ -39,15 +52,14 @@ def setup(app): the Sphinx application context """ app.add_config_value("cache_path", "_cache", "") - CACHE = Path(app.config.cache_path) CACHE.mkdir(exist_ok=True) - documents = { url: fetch_or_load(cache_path=CACHE / f"{name}.html", url=url) for name, url in VOCABULARIES.items() } - app.add_role("kw", docutils_does_not_allow_using_classes(documents)) + + app.add_domain(create_domain(documents)) glossary = fetch_or_load( cache_path=CACHE / "glossary.html",