This is a rewrite of anki-simple-cloze-overlapper in modern JS. For an overview of features, please take a look at a usage example in that repository.
In addition to anki-simple-cloze-overlapper
features, support was added for:
- Nested clozes.
- Clozes in MathJax.
It has been tested only on Anki Desktop. In principle, it should be usable on AnkiDroid, Anki Web and Anki Mobile (but it hasn't been tested). If you want to test on Android, make sure you have the latest Android System WebView installed.
- Place the _cloze-overlapper.mjs into Anki's collection.media folder.
- Create a new note type by cloning the built-in Cloze.
- Add a rendering configuration field named
Before|After|OnlyContext|RevelAll|InactiveHints
. - Put the content of front.html into note's Front Template.
- Put the content of back.html into note's Back Template.
Template's field Before|After|OnlyContext|RevelAll|InactiveHints
controls the rendering
of clozes. Individual parameters are separated by either spaces, commas, pipes or dots.
Omitted rightmost parameters all take default values.
The parameters are as follows:
Before
(non-negative integer, defaults to 1)- The number of clozes before the currently active ones to uncover.
After
(non-negative integer, defaults to 0)- The number of clozes after the currently active ones to uncover.
OnlyContext
(Booleantrue
orfalse
, defaults tofalse
)- Show clozes only within the context (before + current + after).
Set to
true
for e.g. long lyrics/poems. RevelAll
(Booleantrue
orfalse
, defaults tofalse
)- Reveal all clozes on the back of the card. By default only currently active clozes are revealed. (Context clozes are revealed even on cards' fronts.)
InactiveHints
(Booleantrue
orfalse
, defaults tofalse
)- Use user-provided hints (i.e.
{{c#::...::user provided hint}}
) for all clozes. By default, only the currently active clozes use provided hints, others use[...]
.
Context takes nesting of clozes into account: only clozes at the same level of nesting or above can be considered before of after the current one. In the following example:
{{c1::outer 1 {{c2::inner {{c3::deep 1}} {{c4::deep 2}} }} }} {{c5::outer 2}}
c1
,c2
andc3
have no clozes before,c5
has no clozes after,c3
is beforec4
, and similarly,c4
is afterc3
,c5
is afterc1
,c2
andc4
, but onlyc1
is beforec5
.
If you need an extra card that asks you for all the clozes at once, add another cloze
with ask-all
in its content, e.g. {{c99::ask-all}}
.
JavaScript modules, such as _cloze-overlapper.mjs
, are loaded exactly once and never reloaded
(unless you restart Anki). However, you can use dummy query parameter too reload the module
without restarting Anki:
import { renderClozes } from '/_cloze-overlapper.mjs?dev=1';
dev
-counter must be incremented after every modification of _cloze-overlapper.mjs
.
When the development is complete, dev
query parameter can be removed and Anki restarted.