Skip to content

long image descriptions #1247

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

Open
wants to merge 1 commit into
base: PG-2.20
Choose a base branch
from

Conversation

Alex-Jordan
Copy link
Contributor

This lets you pass to an image call a longer description of an image (longer than typical alt text). Typically this would only contain paragraphs and perhaps a table, and it would describe the image content in depth.

For HTML, this makes a details/summary element.

For PTX, this puts the longer description into a description child of the image. It also fixes an issue where the alt text was being put into a description element, but should go into a shortdescription element.

Here is a problem file to load and play with. The same image is inserted multiple times in different ways.

DOCUMENT();

loadMacros(
    "PGstandard.pl",    # Standard macros for PG language
    "PGML.pl",          # PGML markup and Math Objects
    "PGcourse.pl",      # Customization file for the course
);

$description = <<'END_DESC';
This image shows the WeBWorK spiderweb logo.

Here is some data that has nothing to do with the image, but pretend that it did. And some math: [`~~pi`].

[#
    [.1.] [.2.] [.3.]*
    [.4.] [.5.] [.6.]
#]
END_DESC

BEGIN_TEXT

\{image(['webwork_logo.png','webwork_logo.png'], long_description => [PGML::Format($description), 'Hello!'])\}

END_TEXT


BEGIN_PGML
----
Enter a value for [`\pi`].

[!alt text!]{'webwork_logo.png'}{long_description => PGML::Format($description)}

[!alt text!]{'webwork_logo.png'}{long_description => "This image shows the WeBWorK spiderweb logo.${PAR}Here is some data that has nothing to do with the image, but pretend that it did. And some math: ${BM}\\pi${EM}.${PAR}" . DataTable([[1..3],[4..6]])}


[#
    [.Now a table with an image in a cell..]
    [.[!alt text!]{'webwork_logo.png'}{long_description => PGML::Format($description)}.]
#]

[#
    [.Now a table with an image in a cell..]
    [.[!alt text!]{'webwork_logo.png'}{long_description => PGML::Format($description)}.]
#]*

END_PGML

ENDDOCUMENT();

@Alex-Jordan Alex-Jordan force-pushed the image-descriptions branch 7 times, most recently from acb109c to a80c823 Compare June 18, 2025 03:23
@Alex-Jordan
Copy link
Contributor Author

OK, I think this can be looked at. We sorted out known issues. Possible things to change are cosmetic, or something overlooked with accessibility.

@Alex-Jordan Alex-Jordan force-pushed the image-descriptions branch 3 times, most recently from af2c4bc to ea4af6c Compare June 18, 2025 03:53
@pstaabp
Copy link
Member

pstaabp commented Jun 18, 2025

If the long_description isn't placed as an option, there are unexpected results.

[!alt text!]{'webwork_logo.png'}{500}

still shows the "image description", but with HASH(0x120ba8ad8) as the description.

If the size is dropped. the image doesn't show anymore.

my $width = $item->{width} || '';
my $height = $item->{height} || '';
my $image_options = $item->{image_options} || {};
my $long_description = $item->{long_description} || {};
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be:

	my $long_description = $item->{long_description} || '';

@Alex-Jordan
Copy link
Contributor Author

Thanks @pstaabp , @somiaj . I made the change that Jaimos found.

@drgrice1
Copy link
Member

Something needs to be done about inline images still. I suggest adding

	.image-container {
		display: inline-block;
	}

to htdocs/js/Problem/problem.scss.

Here is a minimal example of a problem that renders differently with the current PG-2.20 branch (or before) and this pull request:

DOCUMENT();
loadMacros('PGstandard.pl', 'PGML.pl');
BEGIN_PGML
[!webwork logo!]{'webwork_logo.png'}{320}
[!default icon!]{'defaulticon.png'}{100}
END_PGML
ENDDOCUMENT();

@drgrice1
Copy link
Member

Also, I noticed that you didn't add the description for the answer graphs for the graphtool. Are you going to add that, or leave that for another pull request?

@Alex-Jordan Alex-Jordan force-pushed the image-descriptions branch 2 times, most recently from ee0410f to 8c70739 Compare June 19, 2025 17:40
@Alex-Jordan
Copy link
Contributor Author

Now this reveals the details in a fixed position, centered at the bottom of the page. There is a button that can be used to dismiss the details (in addition to the summary button). When you open a second details, it dismisses the first one, so you can't have two open at the same time.

I set it up to pass the details element to graphTool as longDescription, but I did not work on how to actually make use of it over there. @drgrice1, is that something you would want to look into? I looked in parserGraphTool.pl but I'm not sure how to make use of this in the right way. You need to get a unique id for the current instance of printing a solution graph, and replace 'LONG-DESCRIPTION-ID' with that ID, and then put an aria-details attribute on the graph's svg element.

@Alex-Jordan
Copy link
Contributor Author

The z-index on the details content is now 10. And the POD for using image() has been updated.

@somiaj
Copy link
Contributor

somiaj commented Jun 19, 2025

Looks good to me, though I think @drgrice1 might still need to add this to the GraphTool answer graphs if used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants