Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion htdocs/js/MathJaxConfig/mathjax-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if (!window.MathJax) {
window.MathJax = {
tex: { packages: { '[+]': ['noerrors'] } },
tex: { packages: { '[+]': webworkConfig?.showMathJaxErrors ? [] : ['noerrors'] } },
loader: { load: ['input/asciimath', '[tex]/noerrors'] },
startup: {
ready() {
Expand Down
4 changes: 3 additions & 1 deletion htdocs/js/PGProblemEditor/pgproblemeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
requestData.set('send_pg_flags', 1);
requestData.set(button.name, button.value);
requestData.set('set_id', document.getElementsByName('hidden_set_id')[0]?.value ?? 'Unknown Set');
requestData.set('showMathJaxErrors', 1);

await renderProblem(requestData);

Expand Down Expand Up @@ -473,7 +474,8 @@
displayMode: document.getElementById('action_view_displayMode_id')?.value ?? 'MathJax',
language: document.querySelector('input[name="hidden_language"]')?.value ?? 'en',
send_pg_flags: 1,
view_problem_debugging_info: 1
view_problem_debugging_info: 1,
showMathJaxErrors: 1
})
).then(() => resolve());
});
Expand Down
1 change: 1 addition & 0 deletions lib/FormatRenderedProblem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ sub formatRenderedProblem {
showCorrectAnswersOnlyButton => $ws->{inputs_ref}{showCorrectAnswersOnlyButton} // 0,
showFooter => $ws->{inputs_ref}{showFooter} // '',
problem_data => encode_json($rh_result->{PERSISTENCE_HASH}),
showMathJaxErrors => $ws->{inputs_ref}{showMathJaxErrors} // 0,
pretty_print => \&pretty_print
);

Expand Down
16 changes: 6 additions & 10 deletions lib/WeBWorK/ContentGenerator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use MIME::Base64;
use Scalar::Util qw(weaken);
use HTML::Entities;
use Encode;
use Mojo::JSON qw(encode_json);

use WeBWorK::File::Scoring qw(parse_scoring_file);
use WeBWorK::Localize;
Expand Down Expand Up @@ -682,20 +683,15 @@ sub page_title ($c) {
return route_title($c, $c->current_route, 1);
}

=item webwork_url
=item webwork_js_config

Defined in this package.

Outputs the $webwork_url defined in site.conf, unless $webwork_url is equal to
"/", in which case this outputs the empty string.

This is used to set a value in a global webworkConfig javascript variable,
that can be accessed in javascript files.
Outputs the webwork2 JavaScript configuration. This configuration can be
accessed by JavaScript files to obtain various webwork2 settings.

=cut

sub webwork_url ($c) {
return $c->location;
sub webwork_js_config ($c) {
return encode_json({ webwork_url => $c->location });
}

=item warnings()
Expand Down
2 changes: 1 addition & 1 deletion templates/ContentGenerator/SampleProblemViewer.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<%= javascript $c->url({
type => 'webwork', name => 'htdocs', file => 'node_modules/minisearch/dist/umd/index.js'
}), defer => undef =%>
<script>const webworkConfig = { webwork_url: '<%= $c->webwork_url %>' };</script>
<script>const webworkConfig = <%== $c->webwork_js_config %>;</script>
<%= javascript $c->url({
type => 'webwork', name => 'htdocs', file => 'js/SampleProblemViewer/documentation-search.js'
}), defer => undef =%>
Expand Down
1 change: 1 addition & 0 deletions templates/RPCRenderFormats/default.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
% for (@$extra_css_files) {
%= stylesheet $_->{file}
% }
<script>const webworkConfig = <%= $showMathJaxErrors ? '{ showMathJaxErrors: true }' : 'null' %>;</script>
% for (@$third_party_js) {
%= javascript $_->[0], %{ $_->[1] // {} }
% }
Expand Down
2 changes: 1 addition & 1 deletion templates/layouts/system.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
% }
%
% # Webwork configuration for javascript
<script>const webworkConfig = { webwork_url: '<%= $c->webwork_url %>' };</script>
<script>const webworkConfig = <%== $c->webwork_js_config %>;</script>
%
% # JS Loads
<%= javascript $c->url({ type => 'webwork', name => 'htdocs', file => 'js/MathJaxConfig/mathjax-config.js' }),
Expand Down