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

Allow mathjax to fail without breaking annotations #4628

Merged
merged 1 commit into from
May 15, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,13 @@ export class UserAnnotation extends i18nMixin(ShadowlessLitElement) {
protected updated(_changedProperties: PropertyValues): void {
super.updated(_changedProperties);

// Ask MathJax to search for math in the annotations
window.MathJax.typeset();
try {
// Ask MathJax to search for math in the annotations
window.MathJax.typeset([this]);
} catch (e) {
// MathJax is not loaded
console.warn("MathJax is not loaded");
}
// Reinitialize tooltips
initTooltips(this);
}
Expand Down
7 changes: 6 additions & 1 deletion app/assets/javascripts/exercise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ function showLightbox(content): void {
lightbox.on("slide_changed", () => {
// There might have been math in the image captions, so ask
// MathJax to search for new math (but only in the captions).
window.MathJax.typeset([".gslide-description"]);
try {
window.MathJax.typeset( Array.from(document.querySelectorAll(".gslide-description")));
} catch (e) {
// MathJax is not loaded
console.warn("MathJax is not loaded");
}
});
lightbox.open();

Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare interface Window {
}

declare class MathJaxObject {
typeset?(args?: string[]) :void;
typeset?(args?: string[] | Node[]) :void;

tex: {
inlineMath: string[][];
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/renderers/feedback_code_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def add_messages(submission, messages, user)

@builder.script(type: 'application/javascript') do
@builder << <<~HEREDOC
window.MathJax.startup.promise.then(() => {
window.dodona.ready.then(() => {
window.dodona.codeListing.initAnnotations(#{submission.id}, #{submission.course_id.to_json}, #{submission.exercise_id}, #{user.id}, #{@code.to_json}, #{@code.lines.length}, #{user_is_student});
window.dodona.codeListing.addMachineAnnotations(#{messages.to_json});
#{'window.dodona.codeListing.initAnnotateButtons();' if user_perm}
Expand Down