Defines the reusable schema and rendering rules shared by a family of Anki notes. More...
Public Member Functions | |
| AnkiNoteType (string name, AnkiNoteTypeKind kind=AnkiNoteTypeKind.Standard, long? id=null) | |
| Initializes an unfrozen note type with no fields or templates and default card CSS. | |
| AnkiNoteType | AddField (string name) |
| Adds a uniquely named field at the end of the field order. | |
| AnkiNoteType | AddConfiguredField (AnkiField field) |
| Adds a configured field at the end of the field order. | |
| AnkiNoteType | AddTemplate (string name, string questionFormat, string answerFormat) |
| Adds a card template at the next ordinal. | |
| AnkiNoteType | AddConfiguredTemplate (AnkiCardTemplate template) |
| Adds a configured card template at the next card ordinal. | |
Properties | |
| long | Id [get] |
| Gets the persisted identity by which notes and package metadata refer to this definition. | |
| string | Name [get] |
| Gets the user-visible note-type name. | |
| AnkiNoteTypeKind | Kind [get] |
| Gets the immutable strategy used to turn one note into cards. | |
| string | Css [get, set] |
| Gets or sets CSS shared by every card rendered from this note type. | |
| bool | IsFrozen [get] |
| Gets whether fields, templates, and CSS can no longer be changed. | |
| IReadOnlyList< AnkiField > | Fields [get] |
| Gets fields in positional storage and Anki-editor order. | |
| IReadOnlyList< AnkiCardTemplate > | Templates [get] |
| Gets templates in zero-based card-ordinal order. | |
Defines the reusable schema and rendering rules shared by a family of Anki notes.
An Anki note type (called a “model” by some file formats) is comparable to a small schema: its ordered fields define what each note stores, its templates define the cards Standard notes generate, and its CSS styles every generated card. Reuse one instance for all notes that share that schema. Creating a new instance for every note gives each instance a different ID and can produce unnecessary duplicate note types after import.
Build the definition first, then create notes. Constructing the first AnkiNote freezes the instance permanently so later changes cannot shift positional field storage or card ordinals beneath existing notes. The Fields and Templates collections are ordered, live read-only views; their elements are immutable records. AnkiIO object graphs are not safe for concurrent mutation.
Field and template names are unique without regard to case, but note-value lookup uses the stored spelling exactly. AnkiIO validates structure and known field references before output; it does not render templates, sanitize HTML/CSS, run JavaScript, or promise that custom markup works in every Anki version.
Definition at line 45 of file AnkiNoteType.cs.
|
inline |
Initializes an unfrozen note type with no fields or templates and default card CSS.
| name | The non-blank name shown in Anki's note-type manager. |
| kind | AnkiNoteTypeKind.Standard for template-per-card generation, or AnkiNoteTypeKind.Cloze for deletion-index generation. |
| id | An optional stable numeric identifier for repeatable imports; when omitted, AnkiId.New generates one. |
Empty definitions are allowed while assembling a model, but validation rejects a used note type with no fields or templates. For a ready-made conventional definition, use AnkiNoteTypes.
| ArgumentException | name is empty or consists only of whitespace. |
| ArgumentNullException | name is null. |
Definition at line 71 of file AnkiNoteType.cs.
|
inline |
Adds a configured field at the end of the field order.
| field | The field definition to validate and add. |
The immutable record is retained as supplied, so its editor metadata remains available to serializers and package writers that support those attributes. Adding it after any note has been constructed is forbidden because that would change every note's positional field schema.
| ArgumentNullException | field or one of its required string values is null. |
| ArgumentException | The field name or font is blank, or the name duplicates an existing field without regard to case. |
| ArgumentOutOfRangeException | AnkiField.FontSize is less than one. |
| InvalidOperationException | The note type is frozen because a note already uses it. |
Definition at line 182 of file AnkiNoteType.cs.
|
inline |
Adds a configured card template at the next card ordinal.
| template | The template definition to validate and add. |
AnkiIO preserves all supplied markup, including optional browser-specific formats. Known-field checking is performed on the main front/back formats by AnkiValidator.Validate(AnkiDeck) after the note type is used, but that validation is not a full template renderer or HTML security check. See AnkiCardTemplate for supported conventions and limitations.
| ArgumentNullException | template , AnkiCardTemplate.Name, AnkiCardTemplate.QuestionFormat, or AnkiCardTemplate.AnswerFormat is null. |
| ArgumentException | The template name is blank or duplicates an existing template name without regard to case. |
| InvalidOperationException | The note type is frozen because a note already uses it. |
Definition at line 242 of file AnkiNoteType.cs.
|
inline |
Adds a uniquely named field at the end of the field order.
| name | The non-empty field name used by notes and template references. |
This overload creates a field with left-to-right, non-sticky, Arial 20-pixel editor defaults. Those settings affect the editor, not study-card CSS. Use AddConfiguredField for other metadata.
| ArgumentException | name is blank or duplicates a field name without regard to case. |
| ArgumentNullException | name is null. |
| InvalidOperationException | The note type is frozen because a note already uses it. |
Definition at line 155 of file AnkiNoteType.cs.
|
inline |
Adds a card template at the next ordinal.
| name | The non-empty template name, unique without regard to case. |
| questionFormat | Non-null Anki HTML and template markup for the front. |
| answerFormat | Non-null Anki HTML and template markup for the back. |
This overload leaves browser-specific formats unset. Markup is stored verbatim and field references are validated later; AnkiIO does not render the template or suppress cards whose conditional front would be empty.
| ArgumentNullException | Any argument is null. |
| ArgumentException | name is blank or duplicates a template name without regard to case. |
| InvalidOperationException | The note type is frozen because a note already uses it. |
Definition at line 210 of file AnkiNoteType.cs.
|
getset |
Gets or sets CSS shared by every card rendered from this note type.
Anki-compatible CSS. The default renders centered black Arial text on a white background.
The value is stored verbatim and emitted alongside the templates. It controls study-card rendering; editor-only font settings live on AnkiField. AnkiIO does not parse, sanitize, prefix, or normalize CSS, so callers accepting untrusted styles must apply their own content policy. Assignment is rejected after first use.
| ArgumentNullException | The assigned value is null. |
| InvalidOperationException | The note type is frozen because a note already uses it. |
Definition at line 107 of file AnkiNoteType.cs.
|
get |
Gets fields in positional storage and Anki-editor order.
A live read-only view that reflects fields added before the note type freezes.
Use this order when importing positional values. Field-value dictionaries are keyed by exact name, but legacy Anki databases serialize their values according to this list.
Definition at line 135 of file AnkiNoteType.cs.
|
get |
Gets the persisted identity by which notes and package metadata refer to this definition.
The caller-supplied identifier, or a process-generated positive identifier.
Preserve an imported ID when updating the same definition. Distinct definitions must not share an ID in one output, even if their names match; validation reports conflicting definitions. Explicit ID collision avoidance is the caller's responsibility.
Definition at line 88 of file AnkiNoteType.cs.
|
get |
Gets whether fields, templates, and CSS can no longer be changed.
true after this instance has been supplied to an AnkiNote constructor; otherwise, false.
Freezing is automatic and permanent. It protects every note that retains this shared definition from later changes to its field order, card ordinals, or rendering CSS.
Definition at line 127 of file AnkiNoteType.cs.
|
get |
Gets the immutable strategy used to turn one note into cards.
The immutable AnkiNoteTypeKind selected at construction.
Definition at line 96 of file AnkiNoteType.cs.
|
get |
Gets the user-visible note-type name.
The name supplied when this instance was constructed.
Definition at line 92 of file AnkiNoteType.cs.
|
get |
Gets templates in zero-based card-ordinal order.
A live read-only view that reflects templates added before the note type freezes.
Standard notes generate one card for each entry. Cloze notes use distinct positive deletion indexes instead; their conventional definition still needs a template describing how {{cloze:Text}} renders.
Definition at line 143 of file AnkiNoteType.cs.