You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: plot directive not handling indentation of long option strings #29649
In #29644, I couldn't wrap alt text because the alt field wasn't getting properly parsed by the plot directive. Instead it yeilded something like the following for every variant
Code for reproduction
.. plot:: _embedded_plots/hatch_classes.py:alt: 8 squares, each showing the pattern corresponding to the hatch symbol: symbol
'/' makes right leaning diagonals, '\\' makes left leaning diagonals, '|' makes vertical lines, '-' makes horizontal lines, '+' makes a grid, 'X' makes a grid rotated 90 degrees, 'o' makes small unfilled circles, 'O' makes large unfilled circles, '.' makes small filled circles, and '*' makes a start with 5 points :include-source: false
Actual outcome
Expected outcome
The alt text properly parsed so just the image shows and the alt txt is put into the html
@timhoffm tested the following and this works as expected, with all the alt text in the alt attribute of the image
.. image:: ../_static/anatomy.png:alt:
8 squares, each showing the pattern corresponding to the hatch symbol:
symbol '/' makes right leaning diagonals, '\\' makes left leaning diagonals,
'|' makes vertical lines, '-' makes horizontal lines, '+' makes a grid,
'X' makes a grid rotated 90 degrees, 'o' makes small unfilled circles,
'O' makes large unfilled circles, '.' makes small filled circles, and '*' makes
a star with 5 points
while this:
.. plot:: _embedded_plots/hatch_classes.py:alt:
8 squares, each showing the pattern corresponding to the hatch symbol:
symbol '/' makes right leaning diagonals, '\\' makes left leaning diagonals,
'|' makes vertical lines, '-' makes horizontal lines, '+' makes a grid, 'X' makes a grid rotated 90 degrees, 'o' makes small unfilled circles, 'O' makes large unfilled circles, '.' makes small filled circles, and '*' makes a star with 5 points
generates this output where there's alt text then directive information then alt text again, which to me points to a parsing error in .. plot::
For reasons I don't quite understand, the plot directive renders the plots, and then templates it out into new reST, which is inserted into the parser after it. This path through text again doesn't handle multi-line input and is what causes the breakage.
Activity
anntzer commentedon Feb 20, 2025
This is a rst field list, I suspect (but haven't checked) that the correct way to handle multilines is to also indent the first line, see https://docutils.sourceforge.io/docs/user/rst/quickref.html#field-lists (see
:Authors:in the example and the remark "Field lists are used as part of an extension syntax, such as options for directives etc.")story645 commentedon Feb 21, 2025
Unfortunatly that didn't work either far as I can tell (pushed this attempt to PR)
tacaswell commentedon Feb 21, 2025
I only took a very quick look, but I don't think we are doing any of the parsing ourselves:
matplotlib/lib/matplotlib/sphinxext/plot_directive.py
Lines 254 to 274 in 177f28c
we are leaving that to sphinx/docutils. Maybe adding a line continuation (
\) will work? If not I think this needs to go to sphinx and/or docutils.timhoffm commentedon Feb 21, 2025
Try an
.. image::directive with:alt:. That's a very basic docutils directive using the same definition as we dohttps://github.com/docutils/docutils/blob/f704fb58904d62bf5c6d7db82a9628f29e4ed246/docutils/docutils/parsers/rst/directives/images.py#L50
If that does not work either, it's a docutils issue - either a bug or an incorrect documentation.
story645 commentedon Feb 26, 2025
@timhoffm tested the following and this works as expected, with all the alt text in the alt attribute of the image
while this:
generates this output where there's alt text then directive information then alt text again, which to me points to a parsing error in
.. plot::QuLogic commentedon Feb 27, 2025
It is strange, because
Imagedefinesaltasunchanged, but so do we:matplotlib/lib/matplotlib/sphinxext/plot_directive.py
Line 262 in 0b7a88a
So there should be no difference in parsing.
QuLogic commentedon Feb 27, 2025
It must be a bug with
has_content = Truefor the directive (sinceimagedoesn't have content, butplotdoes.)QuLogic commentedon Feb 27, 2025
For reasons I don't quite understand, the plot directive renders the plots, and then templates it out into new reST, which is inserted into the parser after it. This path through text again doesn't handle multi-line input and is what causes the breakage.