Skip to content

Fix alt and caption handling in Sphinx directives #29689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2025

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Feb 27, 2025

PR summary

We currently template new reST to be re-parsed after the plot is created, but incorrectly copied the alt and caption values when they were wrapped.
In the future, we should probably drop this template and directly create the nodes we need, but I assume that TEMPLATE is not private right now for the purpose of letting people modify it.

Additionally, change figmpl to use Sphinx/docutils' tag creation functions. These functions correctly escape attributes and so fixes invalid HTML when alt text contains quotes. I also dropped some attributes if they were empty (e.g., we no longer get style="" class="" if those aren't specified.)
For example, this is broken on the dark colour map image which has quoted colour map names in the alt text.

Fixes #29649

PR checklist

We currently template new reST to be re-parsed after the plot is
created, but incorrectly copied the `alt` and `caption` values when they
were wrapped.

Additionally, change `figmpl` to use Sphinx/docutils' tag creation
functions. These functions correctly escape attributes and so fixes
invalid HTML when alt text contains quotes.
@timhoffm timhoffm merged commit ed3b739 into matplotlib:main Feb 28, 2025
40 of 41 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Feb 28, 2025
@QuLogic QuLogic deleted the alt-plot branch February 28, 2025 22:08
timhoffm added a commit that referenced this pull request Mar 1, 2025
…689-on-v3.10.x

Backport PR #29689 on branch v3.10.x (Fix alt and caption handling in Sphinx directives)
@ksunden ksunden mentioned this pull request May 9, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: plot directive not handling indentation of long option strings
4 participants