Skip to content

Commit d95fbe5

Browse files
authored
Merge pull request #1323 from drgrice1/bugfix/feedback-in-image-displaymode
Fix feedback previews when the display mode is "images".
2 parents f5bb0b5 + 57d5500 commit d95fbe5

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

lib/WeBWorK/PG.pm

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,12 @@ sub new_helper ($invocant, %options) {
160160
);
161161
}
162162

163-
# HTML_dpng uses an ImageGenerator. We have to render the queued equations. This must be done before the post
164-
# processing, since the image tags output by the image generator initially include markers which are invalid html.
165-
# Mojo::DOM will change these markers into attributes with values and this will fail.
166-
if ($image_generator) {
167-
$image_generator->render(
168-
refresh => $options{refreshMath2img} // 0,
169-
body_text => $translator->r_text,
170-
);
171-
}
172-
173163
$translator->post_process_content if ref($translator->{rh_pgcore}) eq 'PGcore';
174164
$translator->stringify_answers;
175165

166+
$image_generator->render(body_text => $translator->r_text, refresh => $options{refreshMath2img} // 0)
167+
if $image_generator;
168+
176169
# Add the result summary set in post processing into the result.
177170
$result->{summary} = $translator->{rh_pgcore}{result_summary}
178171
if ref($translator->{rh_pgcore}) eq 'PGcore'

lib/WeBWorK/PG/ImageGenerator.pm

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ sub add ($self, $string, $mode = 'inline') {
250250
# Determine what the image's "number" is.
251251
if ($useCache) {
252252
$imageNum = $self->{equationCache}->lookup($realString);
253-
$aligntag = 'MaRkEr' . $imageNum if $self->{useMarkers};
254-
$depths->{$imageNum} = 'none' if $self->{store_depths};
253+
$aligntag = qq{data-imagegen-alignment-marker="$imageNum"} if $self->{useMarkers};
254+
$depths->{$imageNum} = 'none' if $self->{store_depths};
255255
# Insert a slash after 2 characters. This effectively divides the images into 16^2 = 256 subdirectories.
256256
substr($imageNum, 2, 0) = '/';
257257
} else {
@@ -461,11 +461,16 @@ sub fix_markers ($self) {
461461

462462
my %depths = %{ $self->{depths} };
463463
for my $depthkey (keys %depths) {
464+
# The data-imagegen-alignment-marker value may be quoted with double quotes or with " if the image is
465+
# inside another HTML element attribute (such as for images in the feedback button). So both quote types need
466+
# to be checked, and the replaced style attribute needs to use the same quoting that it comes in with.
464467
if ($depths{$depthkey} eq 'none') {
465-
${ $self->{body_text} } =~ s/MaRkEr$depthkey/style="vertical-align:$self->{dvipng_align}"/g;
468+
${ $self->{body_text} } =~
469+
s/data-imagegen-alignment-marker=("|")$depthkey\1/style=$1vertical-align:$self->{dvipng_align}$1/g;
466470
} else {
467471
my $ndepth = 0 - $depths{$depthkey};
468-
${ $self->{body_text} } =~ s/MaRkEr$depthkey/style="vertical-align:${ndepth}px"/g;
472+
${ $self->{body_text} } =~
473+
s/data-imagegen-alignment-marker=("|")$depthkey\1/style=$1vertical-align:${ndepth}px$1/g;
469474
}
470475
}
471476
return;

0 commit comments

Comments
 (0)