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

alt option for image() #559

Merged
merged 6 commits into from
Apr 13, 2021
Merged
Changes from 1 commit
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: 6 additions & 2 deletions macros/PGbasicmacros.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2929,6 +2929,8 @@ sub image {
width => 100,
height => '',
tex_size => 800,
# default value for alt is undef, since an empty string is the explicit indicator of a decorative image
alt => undef,
extra_html_tags => '',
);
# handle options
Expand All @@ -2944,6 +2946,7 @@ sub image {
my $width = $out_options{width};
my $height = $out_options{height};
my $tex_size = $out_options{tex_size};
my $alt = $out_options{alt};
my $width_ratio = $tex_size*(.001);
my @image_list = ();

Expand Down Expand Up @@ -2994,10 +2997,11 @@ sub image {
|| $displayMode eq 'HTML_asciimath'
|| $displayMode eq 'HTML_LaTeXMathML'
|| $displayMode eq 'HTML_img') {
$out = qq!<IMG SRC="$imageURL" class="image-view-elt" tabindex="0" role="button" WIDTH="$width" $height_attrib $out_options{extra_html_tags}>!
my $altattrib = (defined $alt) ? ('alt="' . ($alt =~ s/"/&quot;/gr) . '"') : '';
$out = qq!<IMG SRC="$imageURL" class="image-view-elt" tabindex="0" role="button" WIDTH="$width" $height_attrib $out_options{extra_html_tags} $altattrib>!
drgrice1 marked this conversation as resolved.
Show resolved Hide resolved
} elsif ($displayMode eq 'PTX') {
my $ptxwidth = 100*$width/600;
$out = qq!<image width="$ptxwidth%" source="$imageURL" />!
$out = (defined $alt) ? qq!<image width="$ptxwidth%" source="$imageURL"><description>$alt</description></image>! : qq!<image width="$ptxwidth%" source="$imageURL" />!
} else {
$out = "Error: PGbasicmacros: image: Unknown displayMode: $displayMode.\n";
}
Expand Down