Skip to content

Commit

Permalink
MBS-9429: Fix html encoded characters for spellchecking (#3)
Browse files Browse the repository at this point in the history
MBS-9429: Fix html encoded characters for spellchecking
  • Loading branch information
PhMemmel authored Oct 11, 2024
1 parent 60ec16e commit 7a87ebe
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion amd/build/spellcheck.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/spellcheck.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions amd/src/spellcheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,20 @@ export const renderDiff = (readonlyareaselector) => {
let fullspellcheck = '';

diff.forEach(part => {
// We need to replace the whitespaces, because otherwise they will be removed by
// calling parseFromString of the DOMParser.
part.value = part.value.replace(/ /g, ' ');
const parser = new DOMParser();
part.value = parser.parseFromString(part.value, 'text/html');
var cls = part.added ? 'qtype_aitext_spellcheck_new' :
part.removed ? 'qtype_aitext_spellcheck_wrong' : '';
if (part.added || part.removed) {
span = document.createElement('span');
span.classList = cls;
span.appendChild(document.createTextNode(part.value));
span.appendChild(part.value.documentElement);
fullspellcheck += span.outerHTML;
} else {
fullspellcheck += part.value;
fullspellcheck += part.value.documentElement.textContent;
}
});

Expand Down
2 changes: 1 addition & 1 deletion renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ protected function prepare_response($name, question_attempt $qa,
return '';
}

return format_text($step->get_qt_var($name), FORMAT_PLAIN);
return format_text($step->get_qt_var($name), $step->get_qt_var($name . 'format'), ['para' => false]);
}
}

Expand Down

0 comments on commit 7a87ebe

Please sign in to comment.