Reveal cloze answers in MathJax preview

Closes #1862
This commit is contained in:
Damien Elmes 2022-05-19 12:47:49 +10:00
parent 515e77b0f4
commit 8b1afc7e3a

View File

@ -36,6 +36,7 @@ export function convertMathjax(
nightMode: boolean, nightMode: boolean,
fontSize: number, fontSize: number,
): [string, string] { ): [string, string] {
input = revealClozeAnswers(input);
const style = getStyle(getCSS(nightMode, fontSize)); const style = getStyle(getCSS(nightMode, fontSize));
if (input.trim().length === 0) { if (input.trim().length === 0) {
@ -78,3 +79,9 @@ export function escapeSomeEntities(value: string): string {
export function unescapeSomeEntities(value: string): string { export function unescapeSomeEntities(value: string): string {
return value.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&"); return value.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
} }
function revealClozeAnswers(input: string): string {
// one-line version of regex in cloze.rs
const regex = /\{\{c(\d+)::(.*?)(?:::(.*?))?\}\}/gis;
return input.replace(regex, "[$2]");
}