-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Expand file tree
/
Copy pathcustom_roles.py
More file actions
26 lines (19 loc) · 890 Bytes
/
custom_roles.py
File metadata and controls
26 lines (19 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from docutils import nodes
from os.path import sep
from matplotlib import rcParamsDefault
def rcparam_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
rendered = nodes.Text(f'rcParams["{text}"]')
source = inliner.document.attributes['source'].replace(sep, '/')
rel_source = source.split('/doc/', 1)[1]
levels = rel_source.count('/')
refuri = ('../' * levels +
'tutorials/introductory/customizing.html' +
f"?highlight={text}#a-sample-matplotlibrc-file")
ref = nodes.reference(rawtext, rendered, refuri=refuri)
node_list = [nodes.literal('', '', ref)]
if text in rcParamsDefault:
node_list.append(nodes.Text(f' (default: {rcParamsDefault[text]!r})'))
return node_list, []
def setup(app):
app.add_role("rc", rcparam_role)
return {"parallel_read_safe": True, "parallel_write_safe": True}