Skip to content
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

add support for alt tags for jpeg and png images #1112

Merged
merged 1 commit into from
Oct 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions nbconvert/templates/html/basic.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ height={{ height }}
{%- if output | get_metadata('unconfined', 'image/png') %}
class="unconfined"
{%- endif %}
{%- set alttext=(output | get_metadata('alt', 'image/png')) or (cell | get_metadata('alt')) -%}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the cell has multiple images? Are we ok with all images getting the cell | get_metadata('alt')?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a cell has multiple image outputs, the alt-text should be added to the output's metadata, not the cell's metadata. But there's no way to edit an output's metadata using Jupyter notebook or Jupyter lab. We can only edit the cell's metadata. We can use IPython.display.Image to programmatically set the output metadata, but that doesn't help people creating figures with matplotlib because you can't set the output metadata through matplotlib, and even if you could, not everyone would want to type out the alt-text in their code like that.

People who want or need to add alt-text to their notebooks for accessibility reasons can limit their cell outputs to one figure per cell, which isn't much of a limitation since that's what a lot of people do anyway. And without this change, all notebooks have zero alt-text added to figures and images, making Jupyter notebook blog posts less accessible to the blind or low vision community.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that's a fair compromise. Just wanted to make sure it was thought out.

Thanks for the improvement!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are welcome!

I'd also like to update the documentation somewhere so people know about this feature. Can you advise how I should go about that? Which github project should I update and where should the documentation go?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's this repo -- you can find to root of the docs here: https://github.com/jupyter/nbconvert/tree/master/docs

{%- if alttext is not none %}
alt="{{ alttext }}"
{%- endif %}
>
</div>
{%- endblock data_png %}
Expand All @@ -177,6 +181,10 @@ height={{ height }}
{%- if output | get_metadata('unconfined', 'image/jpeg') %}
class="unconfined"
{%- endif %}
{%- set alttext=(output | get_metadata('alt', 'image/jpeg')) or (cell | get_metadata('alt')) -%}
{%- if alttext is not none %}
alt="{{ alttext }}"
{%- endif %}
>
</div>
{%- endblock data_jpg %}
Expand Down