AnkiIO 1.0.2
Build, validate, import, and export Anki-compatible decks from .NET
Loading...
Searching...
No Matches
AnkiIO.AnkiCloze Class Reference

Builds conservative Anki cloze-deletion markup for a Cloze note's Text field. More...

Static Public Member Functions

static string Wrap (string text, int index=1, string? hint=null)
 Wraps answer text in Anki cloze-deletion markup.

Detailed Description

Builds conservative Anki cloze-deletion markup for a Cloze note's Text field.

A cloze deletion hides part of a sentence during review. Deletions sharing an index appear on one card; different positive indexes create separate cards. This helper deliberately supports the common, non-nested form only so user content cannot accidentally terminate the marker. It returns markup text and neither HTML-escapes nor sanitizes it.

Use AnkiDeck.AddClozeNote for the matching conventional note type. Advanced Anki constructs—nested clozes, template markup inside an answer, or content containing {{, ::, or }}—must be authored as trusted raw field text with the low-level AnkiDeck.AddNote API and tested in the target Anki version.

var deck = new AnkiDeck("Biology");
string organelle = AnkiCloze.Wrap("mitochondria", index: 1, hint: "organelle");
string role = AnkiCloze.Wrap("ATP", index: 2);
deck.AddClozeNote($"{organelle} produce {role}.", tags: ["cell-biology"]);
// Two cards are generated: one for c1 and one for c2.
Builds conservative Anki cloze-deletion markup for a Cloze note's Text field.
Definition AnkiCloze.cs:27
static string Wrap(string text, int index=1, string? hint=null)
Wraps answer text in Anki cloze-deletion markup.
Definition AnkiCloze.cs:55
Builds one named deck hierarchy and acts as the root for validation and export.
Definition AnkiDeck.cs:31

Definition at line 26 of file AnkiCloze.cs.

Member Function Documentation

◆ Wrap()

string AnkiIO.AnkiCloze.Wrap ( string text,
int index = 1,
string? hint = null )
inlinestatic

Wraps answer text in Anki cloze-deletion markup.

Parameters
textThe answer hidden while the card is shown.
indexThe positive cloze index. Deletions with the same index appear on one card; different indexes create separate cards.
hintAn optional hint displayed in place of the hidden answer.
Returns
Cloze markup in the form {{c1::answer}}, or {{c1::answer::hint}} when a hint is supplied. The original answer and hint text are otherwise preserved exactly.

The returned value is markup rather than HTML-escaped text. To prevent ambiguous or malformed output, answer text and hints containing the structural delimiters {{, ::, or }} are rejected. Empty answer text is rejected; an empty hint is allowed and is emitted explicitly. The index is not capped at Anki's UI conventions, but it must fit a positive int and should remain reasonably small for interoperable decks.

string deletion = AnkiCloze.Wrap("mitochondria", index: 1, hint: "organelle");
// {{c1::mitochondria::organelle}}
Exceptions
ArgumentExceptiontext is empty, or text or hint contains a cloze delimiter.
ArgumentNullExceptiontext is null.
ArgumentOutOfRangeExceptionindex is less than one.

Definition at line 55 of file AnkiCloze.cs.


The documentation for this class was generated from the following file: