Repository: sphinx-gallery/sphinx-gallery

Issue:
Thumbnail title regression since 0.11.0
#906 changed the way thumbnail views of galleries are created. It now exposes the rst formatting in the caption:

[Current](https://matplotlib.org/devdocs/tutorials/index.html#intermediate):

![image](https://user-images.githubusercontent.com/19879328/189995776-e11a23b2-5f03-4f9b-bf51-e8bc0d9076f4.png)

[Previous:](https://matplotlib.org/2.2.5/tutorials/index.html)

![grafik](https://user-images.githubusercontent.com/19879328/190082348-9c0e7231-f4b0-41ea-a7ac-4f069d9867db.png)
See also https://github.com/sphinx-gallery/sphinx-gallery/issues/998#issuecomment-1245912973

Comments:

Patch:
diff --git a/.gitignore b/.gitignore
index 2ca5414..5c35e97 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
 __pycache__/
 *.py[cod]
 .coverage*
+.vscode
 
 # C extensions
 *.so
diff --git a/README.rst b/README.rst
index 5f868ad..ee844f3 100644
--- a/README.rst
+++ b/README.rst
@@ -25,40 +25,39 @@ HTML gallery of examples from any set of Python scripts.
 Who uses Sphinx-Gallery
 =======================
 
-* `Sphinx-Gallery <https://sphinx-gallery.github.io/stable/auto_examples/index.html>`_
+An incomplete list:
 
 .. projects_list_start
 
-* `Scikit-learn <http://scikit-learn.org/stable/auto_examples/index.html>`_
-* `Nilearn <https://nilearn.github.io/stable/auto_examples/index.html>`_
-* `MNE-python <https://mne.tools/stable/auto_examples/index.html>`_
-* `PyStruct <https://pystruct.github.io/auto_examples/index.html>`_
+* `Apache TVM <https://tvm.apache.org/docs/tutorial/index.html>`_
+* `Astropy <https://docs.astropy.org/en/stable/generated/examples/index.html>`_
+* `Biotite <https://www.biotite-python.org/examples/gallery/index.html>`_
+* `Auto-sklearn <https://automl.github.io/auto-sklearn/master/examples/index.html>`_
+* `Cartopy <https://scitools.org.uk/cartopy/docs/latest/gallery/>`_
+* `Fury <https://fury.gl/latest/auto_examples/index.html>`_
 * `GIMLi <https://www.pygimli.org/_examples_auto/index.html>`_
+* `Matplotlib <https://matplotlib.org/stable/index.html>`_:
+* `MNE-python <https://mne.tools/stable/auto_examples/index.html>`_
 * `Nestle <http://kylebarbary.com/nestle/examples/index.html>`_
+* `NetworkX <https://networkx.org/documentation/stable/auto_examples/index.html>`_
+* `Neuraxle <https://www.neuraxle.org/stable/examples/index.html>`_
+* `Nilearn <https://nilearn.github.io/stable/auto_examples/index.html>`_
+* `OpenML-Python <https://openml.github.io/openml-python/main/examples/index.html>`_
+* `Optuna <https://optuna.readthedocs.io/en/stable/tutorial/index.html>`_
+* `PlasmaPy <https://docs.plasmapy.org/en/latest/examples.html>`_
 * `pyRiemann <https://pyriemann.readthedocs.io/en/latest/index.html>`_
-* `scikit-image <https://scikit-image.org/docs/dev/auto_examples/>`_
-* `Astropy <https://docs.astropy.org/en/stable/generated/examples/index.html>`_
-* `SunPy <https://docs.sunpy.org/en/stable/generated/gallery/index.html>`_
+* `PyStruct <https://pystruct.github.io/auto_examples/index.html>`_
 * `PySurfer <https://pysurfer.github.io/>`_
-* `Matplotlib <https://matplotlib.org/stable/index.html>`_:
-  `Examples <https://matplotlib.org/stable/gallery/index.html>`_ and
-  `Tutorials <https://matplotlib.org/stable/tutorials/index.html>`_
 * `PyTorch tutorials <https://pytorch.org/tutorials>`_
-* `Cartopy <https://scitools.org.uk/cartopy/docs/latest/gallery/>`_
 * `PyVista <https://docs.pyvista.org/examples/>`_
+* `Radis <https://radis.readthedocs.io/en/latest/auto_examples/index.html>`_
+* `scikit-image <https://scikit-image.org/docs/dev/auto_examples/>`_
+* `Scikit-learn <http://scikit-learn.org/stable/auto_examples/index.html>`_
 * `SimPEG <https://docs.simpeg.xyz/content/examples/>`_
-* `PlasmaPy <https://docs.plasmapy.org/en/latest/examples.html>`_
-* `Fury <https://fury.gl/latest/auto_examples/index.html>`_
-* `NetworkX <https://networkx.org/documentation/stable/auto_examples/index.html>`_
-* `Optuna <https://optuna.readthedocs.io/en/stable/tutorial/index.html>`_
-* `Auto-sklearn <https://automl.github.io/auto-sklearn/master/examples/index.html>`_
-* `OpenML-Python <https://openml.github.io/openml-python/main/examples/index.html>`_
-* `TorchIO <https://torchio.readthedocs.io/auto_examples/index.html>`_
-* `Neuraxle <https://www.neuraxle.org/stable/examples/index.html>`_
-* `Biotite <https://www.biotite-python.org/examples/gallery/index.html>`_
-* `Apache TVM <https://tvm.apache.org/docs/tutorial/index.html>`_
+* `Sphinx-Gallery <https://sphinx-gallery.github.io/stable/auto_examples/index.html>`_
 * `Tonic <https://tonic.readthedocs.io/en/latest/auto_examples/index.html>`_
-* `Radis <https://radis.readthedocs.io/en/latest/auto_examples/index.html>`_
+* `TorchIO <https://torchio.readthedocs.io/auto_examples/index.html>`_
+* `SunPy <https://docs.sunpy.org/en/stable/generated/gallery/index.html>`_
 
 .. projects_list_end
 
@@ -87,8 +86,8 @@ the file sizes of the generated PNG files.
 
 .. installation-end-content
 
-Install as a Sphinx-Gallery developer
--------------------------------------
+Contributing
+============
 
 You can get the latest development source from our `Github repository
 <https://github.com/sphinx-gallery/sphinx-gallery>`_. You need
@@ -99,10 +98,17 @@ you can do:
 
     $ git clone https://github.com/sphinx-gallery/sphinx-gallery
     $ cd sphinx-gallery
-    $ pip install -r dev-requirements.txt
+    $ pip install -r requirements.txt -r dev-requirements.txt
+    $ conda install graphviz  # if using conda, you can get graphviz this way
     $ pip install -e .
 
 
+Check that you are all set by running:
+
+.. code-block:: console
+
+    $ pytest sphinx_gallery
+
 How to cite
 ===========
 
diff --git a/sphinx_gallery/backreferences.py b/sphinx_gallery/backreferences.py
index 01015e6..7085218 100644
--- a/sphinx_gallery/backreferences.py
+++ b/sphinx_gallery/backreferences.py
@@ -265,7 +265,7 @@ THUMBNAIL_TEMPLATE = """
 .. only:: html
 
   .. image:: /{thumbnail}
-    :alt: {title}
+    :alt:
 
   :ref:`sphx_glr_{ref_name}`
 
diff --git a/sphinx_gallery/gen_rst.py b/sphinx_gallery/gen_rst.py
index 24a5153..e0aea51 100644
--- a/sphinx_gallery/gen_rst.py
+++ b/sphinx_gallery/gen_rst.py
@@ -210,6 +210,17 @@ def _sanitize_rst(string):
     string = re.sub(p + r'`([^`]+)`' + e, r'\1\2\3', string)
     # `whatever thing` --> whatever thing
     string = re.sub(p + r'([^`]+)' + e, r'\1\2\3', string)
+
+    # **string** --> string
+    string = re.sub(r'\*\*([^\*]*)\*\*', r'\1', string)
+    # *string* --> string
+    string = re.sub(r'\*([^\*]*)\*', r'\1', string)
+    # `link text <url>`_ --> link text
+    string = re.sub(r'`([^`<>]+) <[^`<>]+>`\_\_?', r'\1', string)
+
+    # :anchor:`the term` --> the term
+    string = re.sub(r':[a-z]+:`([^`<>]+)( <[^`<>]+>)?`', r'\1', string)
+
     return string
 
 
@@ -244,6 +255,9 @@ def extract_intro_and_title(filename, docstring):
     intro = _sanitize_rst(intro)
     if len(intro) > 95:
         intro = intro[:95] + '...'
+
+    title = _sanitize_rst(title)
+
     return intro, title
 
 


Test patch:
diff --git a/sphinx_gallery/tests/test_backreferences.py b/sphinx_gallery/tests/test_backreferences.py
index 4aa8e44..ce5fe07 100644
--- a/sphinx_gallery/tests/test_backreferences.py
+++ b/sphinx_gallery/tests/test_backreferences.py
@@ -21,7 +21,7 @@ REFERENCE = r"""
 .. only:: html
 
   .. image:: /fake_dir/images/thumb/sphx_glr_test_file_thumb.png
-    :alt: test title
+    :alt:
 
   :ref:`sphx_glr_fake_dir_test_file.py`
 
diff --git a/sphinx_gallery/tests/test_full.py b/sphinx_gallery/tests/test_full.py
index 7c4f9fa..a90defc 100644
--- a/sphinx_gallery/tests/test_full.py
+++ b/sphinx_gallery/tests/test_full.py
@@ -866,19 +866,19 @@ def test_alt_text_thumbnail(sphinx_app):
     generated_examples_index = op.join(out_dir, 'auto_examples', 'index.html')
     with codecs.open(generated_examples_index, 'r', 'utf-8') as fid:
         html = fid.read()
-    assert 'alt="&quot;SVG&quot;:-`graphics_`"' in html
+    assert 'alt=""' in html
     # check backreferences thumbnail, html
     backref_html = op.join(out_dir, 'gen_modules',
                            'sphinx_gallery.backreferences.html')
     with codecs.open(backref_html, 'r', 'utf-8') as fid:
         html = fid.read()
-    assert 'alt="Link to other packages"' in html
+    assert 'alt=""' in html
     # check gallery index thumbnail, rst
     generated_examples_index = op.join(src_dir, 'auto_examples',
                                        'index.rst')
     with codecs.open(generated_examples_index, 'r', 'utf-8') as fid:
         rst = fid.read()
-    assert ':alt: Trivial module to provide a value for plot_numpy_matplotlib.py' in rst  # noqa: E501
+    assert ':alt:' in rst
 
 
 def test_backreference_labels(sphinx_app):
diff --git a/sphinx_gallery/tests/test_gen_rst.py b/sphinx_gallery/tests/test_gen_rst.py
index 46622e4..158cb14 100644
--- a/sphinx_gallery/tests/test_gen_rst.py
+++ b/sphinx_gallery/tests/test_gen_rst.py
@@ -295,7 +295,7 @@ def test_extract_intro_and_title():
     # Title with punctuation (gh-517)
     intro, title = sg.extract_intro_and_title('<string>',
                                               '    ------------\n"-`Header"-with:; `punct` mark\'s\n----------------')  # noqa: E501
-    assert title == '"-`Header"-with:; `punct` mark\'s'
+    assert title == '"-`Header"-with:; punct mark\'s'
 
     # Long intro paragraph gets shortened
     intro_paragraph = '\n'.join(['this is one line' for _ in range(10)])