Skip to main content

Crate ankit_builder

Crate ankit_builder 

Source
Expand description

TOML-based Anki deck builder with .apkg generation and AnkiConnect import.

This crate provides a unified way to define Anki decks using TOML and then either:

  • Generate .apkg files for direct import into Anki
  • Import directly into a running Anki instance via AnkiConnect

§Features

  • apkg (default): Enable .apkg file generation
  • connect (default): Enable AnkiConnect import

§Example TOML Format

[package]
name = "Spanish Vocabulary"
version = "1.0.0"
author = "Your Name"

[[models]]
name = "Basic Spanish"
fields = ["Spanish", "English", "Example"]

[[models.templates]]
name = "Spanish -> English"
front = "{{Spanish}}"
back = "{{FrontSide}}<hr>{{English}}"

[[decks]]
name = "Spanish::Vocabulary"
description = "Core Spanish vocabulary"

[[notes]]
deck = "Spanish::Vocabulary"
model = "Basic Spanish"
tags = ["chapter1"]

[notes.fields]
Spanish = "el gato"
English = "the cat"
Example = "El gato es negro."

§Usage

§Generate .apkg file

use ankit_builder::{DeckDefinition, ApkgBuilder};

let definition = DeckDefinition::from_file("my_deck.toml").unwrap();
let builder = ApkgBuilder::new(definition);
builder.write_to_file("my_deck.apkg").unwrap();

§Import via AnkiConnect

use ankit_builder::{DeckDefinition, ConnectImporter};

let definition = DeckDefinition::from_file("my_deck.toml")?;
let importer = ConnectImporter::new(definition);
let result = importer.import().await?;
println!("Created {} notes", result.notes_created);

Re-exports§

pub use error::Error;
pub use error::Result;
pub use schema::DeckDef;
pub use schema::DeckDefinition;
pub use schema::MediaDef;
pub use schema::ModelDef;
pub use schema::NoteDef;
pub use schema::PackageInfo;
pub use schema::TemplateDef;

Modules§

cloze
Cloze deletion helpers for creating flashcards with fill-in-the-blank sections.
error
Error types for ankit-builder.
markdown
Markdown to HTML conversion for note fields.
schema
TOML schema types for deck definitions.

Structs§

ApkgBuilder
Builder for creating .apkg files from deck definitions.
ConnectImporter
Imports deck definitions into Anki via AnkiConnect.
DeckBuilder
Unified builder that can output to either .apkg or AnkiConnect.
DeckDiff
Result of comparing a TOML definition against Anki state.
DeckExporter
Exports decks from Anki to TOML format.
FieldChange
A field that differs between TOML and Anki.
ImportResult
Result of an import operation.
ModifiedNote
A note that exists in both TOML and Anki but has differences.
NoteDiff
A note that exists in only one place.
ResolvedConflict
A conflict that was resolved.
SyncConflict
A conflict where a note differs between TOML and Anki.
SyncError
An error that occurred during sync.
SyncNote
A note involved in sync.
SyncPlan
A plan for what sync would do, without executing it.
SyncResult
Result of a sync operation.
SyncStrategy
Strategy for how to handle sync operations.
SyncedNote
A note that was synced.
TagChanges
Tag differences between TOML and Anki.

Enums§

ConflictResolution
How to resolve conflicts when a note differs between TOML and Anki.