Skip to content

Commit 7265f5a

Browse files
committed
Added option to show/hide Source link in plot_directive
1 parent a528eaa commit 7265f5a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/matplotlib/sphinxext/plot_directive.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
plot_include_source
8383
Default value for the include-source option
8484
85+
plot_show_source_link
86+
Whether to show a link to the source in HTML.
87+
8588
plot_pre_code
8689
Code that should be executed before each plot.
8790
@@ -304,6 +307,7 @@ def setup(app):
304307
app.add_directive('plot', plot_directive, True, (0, 2, False), **options)
305308
app.add_config_value('plot_pre_code', None, True)
306309
app.add_config_value('plot_include_source', False, True)
310+
app.add_config_value('plot_show_source_link', True, True)
307311
app.add_config_value('plot_formats', ['png', 'hires.png', 'pdf'], True)
308312
app.add_config_value('plot_basedir', None, True)
309313
app.add_config_value('plot_html_show_formats', True, True)
@@ -388,9 +392,9 @@ def remove_coding(text):
388392
389393
{{ only_html }}
390394
391-
{% if source_link or (html_show_formats and not multi_image) %}
395+
{% if (source_link and show_source_link) or (html_show_formats and not multi_image) %}
392396
(
393-
{%- if source_link -%}
397+
{%- if source_link and show_source_link -%}
394398
`Source code <{{ source_link }}>`__
395399
{%- endif -%}
396400
{%- if html_show_formats and not multi_image -%}
@@ -805,6 +809,7 @@ def run(arguments, content, options, state_machine, state, lineno):
805809
dest_dir=dest_dir_link,
806810
build_dir=build_dir_link,
807811
source_link=src_link,
812+
show_source_link=config.plot_show_source_link,
808813
multi_image=len(images) > 1,
809814
only_html=only_html,
810815
only_latex=only_latex,

0 commit comments

Comments
 (0)