A little code.
Something to remember.
Explore the source, flip the cards, and open the generated decks in Anki. These web previews use the same fields as the downloads.
Read the complete sourceBasic
A Spanish greeting with a question, an answer, and an explicit stable ID. Start here for simple front-and-back cards.
let (front, back) = ("hola", "hello");
let mut deck = Deck::new("Spanish");
deck.basic().note(front, back).stable_id("es:hola").add()?;
let report = deck.write_apkg(output.join("spanish.apkg"))?;
report.ensure_success()?;hola
What does this mean?Question shown.
Cloze
Hide a word in context with Anki’s cloze syntax. This note has one deletion, so it generates one card.
let text = "A sound's pitch depends on its {{c1::frequency}}.";
let extra = "More cycles per second, higher pitch.";
let mut project = Project::new("Sound")
.stable_id("website-sound")
.default_deck("Sound");
project.add_note(Note::cloze(text).extra(extra).stable_id("sound:pitch"))?;
let report = project.write_apkg(output.join("sound.apkg"))?;
report.ensure_success()?;A sound's pitch depends on its […].
Question shown.
Media
An image and a playable tone, packaged with the note. This excerpt uses an ear-training note type defined in the full source.
let (prompt, answer) = ("Name this pitch.", "A4, 440 Hz");
let picture = project
.media_mut()
.add_file(output.join("waveform.svg"))?
.export_as("waveform.svg")?;
let audio = project
.media_mut()
.add_file(output.join("concert-a.wav"))?
.export_as("concert-a.wav")?;
project.add_note(
Note::new("ear-training")
.stable_id("sound:a4")
.text("prompt", prompt)
.text("answer", answer)
.image("picture", picture)
.sound("audio", audio),
)?;
let report = project.write_apkg(output.join("ear-training.apkg"))?;
report.ensure_success()?;Name this pitch.
Question shown.
One note, two versions.
The second build changes the answer from “hello” to “hello; hi”. It compares against the first package and checks that the note identity is preserved.
let report = project.build(BuildOptions::new().output(&next).compare_to(&previous))?;
report.ensure_success()?;es:holahola
hello
Try a content change.
Anki’s import settings and local edits affect how updates are applied. The previews show content and identity; card styling and review behavior come from Anki.