GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix alt and caption handling in Sphinx directives by QuLogic · Pull Request #29689 · matplotlib/matplotlib

Conversation

@QuLogic

@QuLogic QuLogic commented Feb 27, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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

  • "closes #0000" is in the body of the PR description to link the related issue
  • new and changed code is tested
  • [n/a] Plotting related features are demonstrated in an example
  • [n/a] New Features and API Changes are noted with a directive and release note
  • Documentation complies with general and docstring guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

story645 reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@QuLogic QuLogic added the topic: sphinx extension label Feb 27, 2025
@QuLogic QuLogic added this to the v3.10.1 milestone Feb 27, 2025
@QuLogic
QuLogic force-pushed the alt-plot branch from db0b215 to 4862a77 Compare February 27, 2025 19:14
@QuLogic QuLogic modified the milestones: v3.10.1, v3.10.2 Feb 27, 2025
@story645 story645 added the accessibility label Feb 27, 2025
tacaswell
tacaswell approved these changes Feb 27, 2025
View reviewed changes
story645
story645 approved these changes Feb 27, 2025
View reviewed changes
@QuLogic
Fix alt and caption handling in Sphinx directives
15eaeb1
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.
@QuLogic
QuLogic force-pushed the alt-plot branch from 4862a77 to 15eaeb1 Compare February 28, 2025 09:56
timhoffm
timhoffm approved these changes Feb 28, 2025
View reviewed changes
@timhoffm
timhoffm merged commit ed3b739 into matplotlib:main Feb 28, 2025
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Feb 28, 2025
@timhoffm @meeseeksmachine
Backport PR matplotlib#29689: Fix alt and caption handling in Sphinx …
1bdc36a
…directives
@meeseeksmachine meeseeksmachine mentioned this pull request Feb 28, 2025
Backport PR #29689 on branch v3.10.x (Fix alt and caption handling in Sphinx directives) #29692
Merged
@QuLogic
QuLogic deleted the alt-plot branch February 28, 2025 22:08
timhoffm added a commit that referenced this pull request Mar 1, 2025
@timhoffm
Merge pull request #29692 from meeseeksmachine/auto-backport-of-pr-29…
b6f6e27
…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
merge up 3.10.3 #30031
Closed
5 tasks
@ksunden ksunden mentioned this pull request Jul 25, 2025
Manual Backport PR #30195 on branch v3.10.x (ci: Enable wheel builds on Python 3.14) #30356
Merged
5 tasks
@ksunden ksunden mentioned this pull request Aug 7, 2025
merge up v3.10.5 #30401
Merged
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@tacaswell tacaswell tacaswell approved these changes
@story645 story645 story645 approved these changes
@timhoffm timhoffm timhoffm approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

accessibility topic: sphinx extension

Projects

None yet

Milestone

v3.10.3

Development

Successfully merging this pull request may close these issues.

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

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@QuLogic @tacaswell @story645 @timhoffm
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.