diff options
author | Julian Berman <Julian@GrayVines.com> | 2020-10-20 09:51:54 -0400 |
---|---|---|
committer | Julian Berman <Julian@GrayVines.com> | 2020-10-20 11:37:51 -0400 |
commit | 7be95e66f5a0679eeea16da0bd9e8a3d3f1fe7af (patch) | |
tree | 6aaf9d95c5ea473237c2a7aa4faccfe94cc8ebdc /docs | |
parent | 049e9956c8f9865b666f0f8e16af1c95c109fa8e (diff) | |
download | jsonschema-7be95e66f5a0679eeea16da0bd9e8a3d3f1fe7af.tar.gz |
Tidy up the URLs in the docutils role.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/jsonschema_role.py | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/docs/jsonschema_role.py b/docs/jsonschema_role.py index 8a4feaa..bb40129 100644 --- a/docs/jsonschema_role.py +++ b/docs/jsonschema_role.py @@ -1,4 +1,5 @@ from datetime import datetime +from urllib.parse import urljoin import errno import os import urllib.request @@ -10,7 +11,11 @@ import certifi import jsonschema __version__ = "1.1.0" -VALIDATION_SPEC = "https://json-schema.org/draft-07/json-schema-validation.html" + +BASE_URL = "https://json-schema.org/draft-07/" +VALIDATION_SPEC = urljoin(BASE_URL, "json-schema-validation.html") +REF_URL = urljoin(BASE_URL, "json-schema-core.html#rfc.section.8.3") +SCHEMA_URL = urljoin(BASE_URL, "json-schema-core.html#rfc.section.7") def setup(app): @@ -34,7 +39,7 @@ def setup(app): path = os.path.join(app.config.cache_path, "spec.html") spec = fetch_or_load(path) - app.add_role("validator", docutils_sucks(spec)) + app.add_role("validator", docutils_does_not_allow_using_classes(spec)) return dict(version=__version__, parallel_read_safe=True) @@ -77,18 +82,15 @@ def fetch_or_load(spec_path): return html.parse(spec) -def docutils_sucks(spec): +def docutils_does_not_allow_using_classes(spec): """ Yeah. - It doesn't allow using a class because it does stupid stuff like try to set - attributes on the callable object rather than just keeping a dict. + It doesn't allow using a class because it does annoying stuff like + try to set attributes on the callable object rather than just + keeping a dict. """ - base_url = VALIDATION_SPEC - ref_url = "https://json-schema.org/draft-07/json-schema-core.html#rfc.section.8.3" - schema_url = "https://json-schema.org/draft-07/json-schema-core.html#rfc.section.7" - def validator(name, raw_text, text, lineno, inliner): """ Link to the JSON Schema documentation for a validator. @@ -124,9 +126,9 @@ def docutils_sucks(spec): """ if text == "$ref": - return [nodes.reference(raw_text, text, refuri=ref_url)], [] + return [nodes.reference(raw_text, text, refuri=REF_URL)], [] elif text == "$schema": - return [nodes.reference(raw_text, text, refuri=schema_url)], [] + return [nodes.reference(raw_text, text, refuri=SCHEMA_URL)], [] # find the header in the validation spec containing matching text header = spec.xpath("//h1[contains(text(), '{0}')]".format(text)) @@ -135,7 +137,7 @@ def docutils_sucks(spec): inliner.reporter.warning( "Didn't find a target for {0}".format(text), ) - uri = base_url + uri = VALIDATION_SPEC else: if len(header) > 1: inliner.reporter.info( @@ -143,7 +145,7 @@ def docutils_sucks(spec): ) # get the href from link in the header - uri = base_url + header[0].find("a").attrib["href"] + uri = urljoin(VALIDATION_SPEC, header[0].find("a").attrib["href"]) reference = nodes.reference(raw_text, text, refuri=uri) return [reference], [] |