From 8b1afc7e3a7cd80b057afdec9eefb0726eade86f Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 19 May 2022 12:47:49 +1000 Subject: [PATCH] Reveal cloze answers in MathJax preview Closes #1862 --- ts/editable/mathjax.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ts/editable/mathjax.ts b/ts/editable/mathjax.ts index 00a6027d8..6ef29cb57 100644 --- a/ts/editable/mathjax.ts +++ b/ts/editable/mathjax.ts @@ -36,6 +36,7 @@ export function convertMathjax( nightMode: boolean, fontSize: number, ): [string, string] { + input = revealClozeAnswers(input); const style = getStyle(getCSS(nightMode, fontSize)); if (input.trim().length === 0) { @@ -78,3 +79,9 @@ export function escapeSomeEntities(value: string): string { export function unescapeSomeEntities(value: string): string { return value.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&"); } + +function revealClozeAnswers(input: string): string { + // one-line version of regex in cloze.rs + const regex = /\{\{c(\d+)::(.*?)(?:::(.*?))?\}\}/gis; + return input.replace(regex, "[$2]"); +}