AnkiIO 1.0.2
Build, validate, import, and export Anki-compatible decks from .NET
Loading...
Searching...
No Matches
AnkiIO.AnkiCardTemplate(string Name, string QuestionFormat, string AnswerFormat, string? BrowserQuestionFormat=null, string? BrowserAnswerFormat=null) Class Referencesealed

Defines one study direction by mapping note fields to a card front and back. More...

Properties

string Name = Name [get]
 Gets the display name shown for this card type in Anki.
string QuestionFormat = QuestionFormat [get]
 Gets the unsanitized Anki HTML/template markup used for the card front.
string AnswerFormat = AnswerFormat [get]
 Gets the unsanitized Anki HTML/template markup used for the card back.
string? BrowserQuestionFormat = BrowserQuestionFormat [get]
 Gets the optional markup used for the question column in Anki's card browser.
string? BrowserAnswerFormat = BrowserAnswerFormat [get]
 Gets the optional markup used for the answer column in Anki's card browser.

Detailed Description

Defines one study direction by mapping note fields to a card front and back.

Parameters
NameThe non-blank name shown in Anki's card-type editor, unique within its note type ignoring case.
QuestionFormatAnki HTML/template markup for the front, for example {{German}}. The value must be non-null but may be empty.
AnswerFormatAnki HTML/template markup for the back. {{FrontSide}} reuses the already-rendered front.
BrowserQuestionFormatOptional markup for Anki's browser question column, or null to emit no browser-specific override.
BrowserAnswerFormatOptional markup for Anki's browser answer column, or null to emit no browser-specific override.

The formats use Anki's template language, not C# interpolation. Common expressions insert a field, conditionally show a section based on a field, reuse {{FrontSide}}, or apply modifiers such as {{type:Field}} and, for Cloze models, {{cloze:Text}}. Values may also contain ordinary HTML and media references.

AnkiIO stores markup verbatim and never renders, HTML-sanitizes, or executes it. Validation reports unknown field references in the main question/answer formats, but it is not a full Anki template compiler: it does not prove that conditional sections are balanced, that HTML is safe, or that browser-specific formats render. Test custom templates in the Anki version you support.

A Standard note normally receives one card per template in insertion order. AnkiIO creates that card eagerly and does not evaluate conditional templates to decide whether an empty card should be omitted. A Cloze note instead receives one card per distinct positive cloze index in its Text field; adding more templates does not create more Cloze cards.

Constructing this immutable record does not validate its arguments. Attach it with AnkiNoteType.AddConfiguredTemplate to validate required values and uniqueness before use.

var template = new AnkiCardTemplate(
"Recognition",
"{{Word}}",
"{{FrontSide}}<hr id=\"answer\">{{Meaning}}",
BrowserQuestionFormat: "{{Word}}",
BrowserAnswerFormat: "{{Meaning}}");
Defines one study direction by mapping note fields to a card front and back.
string? BrowserAnswerFormat
Gets the optional markup used for the answer column in Anki's card browser.
string? BrowserQuestionFormat
Gets the optional markup used for the question column in Anki's card browser.

Definition at line 48 of file AnkiCardTemplate.cs.

Property Documentation

◆ AnswerFormat

string AnkiIO.AnkiCardTemplate.AnswerFormat = AnswerFormat
get

Gets the unsanitized Anki HTML/template markup used for the card back.

The answer format supplied to the primary constructor.

Definition at line 65 of file AnkiCardTemplate.cs.

◆ BrowserAnswerFormat

string? AnkiIO.AnkiCardTemplate.BrowserAnswerFormat = BrowserAnswerFormat
get

Gets the optional markup used for the answer column in Anki's card browser.

The browser answer format, or null when no browser-specific override is emitted.

Definition at line 73 of file AnkiCardTemplate.cs.

◆ BrowserQuestionFormat

string? AnkiIO.AnkiCardTemplate.BrowserQuestionFormat = BrowserQuestionFormat
get

Gets the optional markup used for the question column in Anki's card browser.

The browser question format, or null when no browser-specific override is emitted.

Definition at line 69 of file AnkiCardTemplate.cs.

◆ Name

string AnkiIO.AnkiCardTemplate.Name = Name
get

Gets the display name shown for this card type in Anki.

The name supplied to the primary constructor; validated when attached to a note type.

Definition at line 57 of file AnkiCardTemplate.cs.

◆ QuestionFormat

string AnkiIO.AnkiCardTemplate.QuestionFormat = QuestionFormat
get

Gets the unsanitized Anki HTML/template markup used for the card front.

The question format supplied to the primary constructor.

Definition at line 61 of file AnkiCardTemplate.cs.


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