10000 FIX: Remove newlines from title (#669) · sphinx-gallery/sphinx-gallery@96b5fed · GitHub
[go: up one dir, main page]

Skip to content

Commit 96b5fed

Browse files
authored
FIX: Remove newlines from title (#669)
1 parent 50004ab commit 96b5fed

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

examples/plot_1_exp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def main():
3535
plt.plot(x, -np.exp(-x))
3636
plt.xlabel('$x$')
3737
plt.ylabel('$-\exp(-x)$')
38-
plt.title('Negative exponential function')
38+
plt.title('Negative exponential\nfunction')
3939
# To avoid matplotlib text output
4040
plt.show()
4141

sphinx_gallery/scrapers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ def figure_rst(figure_list, sources_dir, fig_titles=''):
310310
# replace - & _ with \s
311311
file_name_final = re.sub(r'[-,_]', ' ', file_name_noext)
312312
alt = file_name_final
313+
alt = _single_line_sanitize(alt)
313314

314315
images_rst = ""
315316
if len(figure_paths) == 1:
@@ -322,6 +323,13 @@ def figure_rst(figure_list, sources_dir, fig_titles=''):
322323
return images_rst
323324

324325

326+
def _single_line_sanitize(s):
327+
"""Remove problematic newlines."""
328+
# For example, when setting a :alt: for an image, it shouldn't have \n
329+
# This is a function in case we end up finding other things to replace
330+
return s.replace('\n', ' ')
331+
332+
325333
# The following strings are used when we have several pictures: we use
326334
# an html div tag that our CSS uses to turn the lists into horizontal
327335
# lists.

sphinx_gallery/tests/tinybuild/examples/plot_matplotlib_alt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
axs[0].set_title('subplot 1')
1515
axs[0].set_xlabel('x label')
1616
axs[0].set_ylabel('y lab')
17-
fig.suptitle('This is a sup title')
17+
fig.suptitle('This is a\nsup title')
1818

1919
axs[1].plot([2, 3, 4])
2020
axs[1].set_title('subplot 2')

0 commit comments

Comments
 (0)
0