Replaced CVE/ticket roles with extlinks.
This commit is contained in:
parent
7b7fb2eca5
commit
44f98f7880
|
@ -1,27 +0,0 @@
|
||||||
"""
|
|
||||||
An interpreted text role to link docs to CVE issues. To use: :cve:`XXXXX`
|
|
||||||
"""
|
|
||||||
from docutils import nodes, utils
|
|
||||||
from docutils.parsers.rst import roles
|
|
||||||
|
|
||||||
|
|
||||||
def cve_role(name, rawtext, text, lineno, inliner, options=None, content=None):
|
|
||||||
if options is None:
|
|
||||||
options = {}
|
|
||||||
|
|
||||||
url_pattern = inliner.document.settings.env.app.config.cve_url
|
|
||||||
if url_pattern is None:
|
|
||||||
msg = inliner.reporter.warning("cve not configured: please configure cve_url in conf.py")
|
|
||||||
prb = inliner.problematic(rawtext, rawtext, msg)
|
|
||||||
return [prb], [msg]
|
|
||||||
|
|
||||||
url = url_pattern % text
|
|
||||||
roles.set_classes(options)
|
|
||||||
node = nodes.reference(rawtext, utils.unescape('CVE-%s' % text), refuri=url, **options)
|
|
||||||
return [node], []
|
|
||||||
|
|
||||||
|
|
||||||
def setup(app):
|
|
||||||
app.add_config_value('cve_url', None, 'env')
|
|
||||||
app.add_role('cve', cve_role)
|
|
||||||
return {'parallel_read_safe': True}
|
|
|
@ -1,39 +0,0 @@
|
||||||
"""
|
|
||||||
An interpreted text role to link docs to Trac tickets.
|
|
||||||
|
|
||||||
To use: :ticket:`XXXXX`
|
|
||||||
|
|
||||||
Based on code from psycopg2 by Daniele Varrazzo.
|
|
||||||
"""
|
|
||||||
from docutils import nodes, utils
|
|
||||||
from docutils.parsers.rst import roles
|
|
||||||
|
|
||||||
|
|
||||||
def ticket_role(name, rawtext, text, lineno, inliner, options=None, content=None):
|
|
||||||
if options is None:
|
|
||||||
options = {}
|
|
||||||
try:
|
|
||||||
num = int(text.replace('#', ''))
|
|
||||||
except ValueError:
|
|
||||||
msg = inliner.reporter.error(
|
|
||||||
"ticket number must be... a number, got '%s'" % text)
|
|
||||||
prb = inliner.problematic(rawtext, rawtext, msg)
|
|
||||||
return [prb], [msg]
|
|
||||||
|
|
||||||
url_pattern = inliner.document.settings.env.app.config.ticket_url
|
|
||||||
if url_pattern is None:
|
|
||||||
msg = inliner.reporter.warning(
|
|
||||||
"ticket not configured: please configure ticket_url in conf.py")
|
|
||||||
prb = inliner.problematic(rawtext, rawtext, msg)
|
|
||||||
return [prb], [msg]
|
|
||||||
|
|
||||||
url = url_pattern % num
|
|
||||||
roles.set_classes(options)
|
|
||||||
node = nodes.reference(rawtext, '#' + utils.unescape(text), refuri=url, **options)
|
|
||||||
return [node], []
|
|
||||||
|
|
||||||
|
|
||||||
def setup(app):
|
|
||||||
app.add_config_value('ticket_url', None, 'env')
|
|
||||||
app.add_role('ticket', ticket_role)
|
|
||||||
return {'parallel_read_safe': True}
|
|
12
docs/conf.py
12
docs/conf.py
|
@ -38,12 +38,16 @@ needs_sphinx = '1.6.0'
|
||||||
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||||
extensions = [
|
extensions = [
|
||||||
"djangodocs",
|
"djangodocs",
|
||||||
|
'sphinx.ext.extlinks',
|
||||||
"sphinx.ext.intersphinx",
|
"sphinx.ext.intersphinx",
|
||||||
"sphinx.ext.viewcode",
|
"sphinx.ext.viewcode",
|
||||||
"ticket_role",
|
|
||||||
"cve_role",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
extlinks = {
|
||||||
|
'cve': ('https://nvd.nist.gov/view/vuln/detail?vulnId=%s', 'CVE-'),
|
||||||
|
'ticket': ('https://code.djangoproject.com/ticket/%s', '#'),
|
||||||
|
}
|
||||||
|
|
||||||
# Spelling check needs an additional module that is not installed by default.
|
# Spelling check needs an additional module that is not installed by default.
|
||||||
# Add it only if spelling check is requested so docs can be generated without it.
|
# Add it only if spelling check is requested so docs can be generated without it.
|
||||||
if 'spelling' in sys.argv:
|
if 'spelling' in sys.argv:
|
||||||
|
@ -365,7 +369,3 @@ epub_cover = ('', 'epub-cover.html')
|
||||||
|
|
||||||
# If false, no index is generated.
|
# If false, no index is generated.
|
||||||
# epub_use_index = True
|
# epub_use_index = True
|
||||||
|
|
||||||
# -- custom extension options --------------------------------------------------
|
|
||||||
cve_url = 'https://nvd.nist.gov/view/vuln/detail?vulnId=%s'
|
|
||||||
ticket_url = 'https://code.djangoproject.com/ticket/%s'
|
|
||||||
|
|
Loading…
Reference in New Issue