forked from michalrus/anki-simple-cloze-overlapper
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfront.template.anki
71 lines (64 loc) · 2.2 KB
/
front.template.anki
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<cloze-generator></cloze-generator>
<template id="anki-cloze">{{cloze:Text}}</template>
<template id="cloze-config">{{Before|After|OnlyContext|RevealAll|InactiveHints}}</template>
<template id="cloze-source">
<!--
Uncomment and adjust if MathJax style autodetection doesn't work for you.
<div style="display: none">
\[
\renewcommand\AnkiClozeQ[1]{\boldsymbol{\color{blue} #1}}
\renewcommand\AnkiClozeA[1]{\AnkiClozeQ{#1}}
\]
</div>
-->
{{Text}}
</template>
<div id="rendered-cloze"></div>
<script>(() => {
// anki-export-media: '_cloze-overlapper.mjs'
'use strict';
const CLOZE_CONTAINER = document.getElementById('rendered-cloze');
function reportError(e) {
CLOZE_CONTAINER.textContent = e;
}
async function renderClozes(typesetMathJax = false) {
try {
// https://github.com/ankidroid/Anki-Android/pull/7764
const mediaRoot = globalThis.AnkiDroidJS
? 'https://appassets.androidplatform.net'
: globalThis.ankiPlatform === 'desktop' ? '' : '.';
const ClozeOverlapper = await import(`${mediaRoot}/_cloze-overlapper.js`);
await ClozeOverlapper.renderClozes(
undefined, typesetMathJax ? ClozeOverlapper.typesetMathJax : undefined);
} catch (e) {
reportError(e);
}
}
function getUpdateHook() {
if (typeof require !== 'undefined') {
try {
return require('anki/reviewer').onUpdateHook;
} catch (e) {
if (!e?.message.includes('Cannot require')) {
throw e;
}
}
}
if (typeof onUpdateHook !== 'undefined') {
return onUpdateHook;
}
}
try {
const updateHook = getUpdateHook();
if (updateHook) {
updateHook.push(renderClozes);
} else if (typeof MathJax !== 'undefined') {
// AnkiDroid loads MathJax only if \( and/or \[ are present.
MathJax.startup.promise.then(() => renderClozes(true));
} else {
renderClozes();
}
} catch (e) {
reportError(e);
}
})();</script>