From 24cdef43b48974efd4155c5dd0076952e0373c96 Mon Sep 17 00:00:00 2001 From: ImportanceOfBeingErnest Date: Fri, 23 Aug 2019 17:08:49 +0200 Subject: [PATCH 1/3] highlight rcparams --- .gitignore | 2 ++ doc/_static/mpl.css | 4 ++++ doc/sphinxext/custom_roles.py | 5 +++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index bf34ab6778bb..bbd62a042419 100644 --- a/.gitignore +++ b/.gitignore @@ -56,6 +56,8 @@ Thumbs.db ################################### lib/matplotlib/mpl-data/matplotlib.conf lib/matplotlib/mpl-data/matplotlibrc +tutorials/intermediate/CL01.png +tutorials/intermediate/CL02.png # Documentation generated files # ################################# diff --git a/doc/_static/mpl.css b/doc/_static/mpl.css index d4245992ad0d..dbc2abb14210 100644 --- a/doc/_static/mpl.css +++ b/doc/_static/mpl.css @@ -594,6 +594,10 @@ span.linkdescr { font-size: 90%; } +.highlight span.c1 span.highlighted { + background-color: #fce5a6; +} + ul.search { margin: 10px 0 0 20px; padding: 0; diff --git a/doc/sphinxext/custom_roles.py b/doc/sphinxext/custom_roles.py index 2232f1032424..17690757e6a3 100644 --- a/doc/sphinxext/custom_roles.py +++ b/doc/sphinxext/custom_roles.py @@ -3,14 +3,15 @@ def rcparam_role(name, rawtext, text, lineno, inliner, options={}, content=[]): - rendered = nodes.Text('rcParams["{}"]'.format(text)) + 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#matplotlib-rcparams') + 'tutorials/introductory/customizing.html' + + f"?highlight={text}#a-sample-matplotlibrc-file") ref = nodes.reference(rawtext, rendered, refuri=refuri) return [nodes.literal('', '', ref)], [] From 27ce8327d3c4ec027943cb34baaf9dc1a3f43cde Mon Sep 17 00:00:00 2001 From: ImportanceOfBeingErnest Date: Sat, 24 Aug 2019 16:26:27 +0200 Subject: [PATCH 2/3] Include default rcparam in rc role --- doc/sphinxext/custom_roles.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/sphinxext/custom_roles.py b/doc/sphinxext/custom_roles.py index 17690757e6a3..8037f42b10bf 100644 --- a/doc/sphinxext/custom_roles.py +++ b/doc/sphinxext/custom_roles.py @@ -1,9 +1,15 @@ 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}"]') + + param = rcParamsDefault.get(text) + if isinstance(param, str): + txt = f' : "{param}"' + else: + txt = f' : {param}' + rendered = nodes.Text(f'rcParams["{text}"]' + txt) source = inliner.document.attributes['source'].replace(sep, '/') rel_source = source.split('/doc/', 1)[1] From 75ce5920b9bde39e7c1cdde481cbbef70f5e9f8e Mon Sep 17 00:00:00 2001 From: ImportanceOfBeingErnest Date: Sat, 24 Aug 2019 16:48:26 +0200 Subject: [PATCH 3/3] Include default rcparam in rc role, flake --- doc/sphinxext/custom_roles.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/doc/sphinxext/custom_roles.py b/doc/sphinxext/custom_roles.py index 8037f42b10bf..88dddb6a2e4b 100644 --- a/doc/sphinxext/custom_roles.py +++ b/doc/sphinxext/custom_roles.py @@ -2,14 +2,10 @@ from os.path import sep from matplotlib import rcParamsDefault + def rcparam_role(name, rawtext, text, lineno, inliner, options={}, content=[]): - param = rcParamsDefault.get(text) - if isinstance(param, str): - txt = f' : "{param}"' - else: - txt = f' : {param}' - rendered = nodes.Text(f'rcParams["{text}"]' + txt) + rendered = nodes.Text(f'rcParams["{text}"] = {param!r}') source = inliner.document.attributes['source'].replace(sep, '/') rel_source = source.split('/doc/', 1)[1]