Giter Club home page Giter Club logo

anki.net's Introduction

Anki.NET

NuGet NuGet

Create and export Anki collections, decks, notes and cards from your C# applications.

var noteType = new AnkiNoteType(
    name: "Basic",
    cardTypes: new[] {
        new AnkiCardType(
            Name: "Card 1",
            Ordinal: 0,
            QuestionFormat: "{{Front}}",
            AnswerFormat: "{{Front}}<hr id=\"answer\">{{Back}}"
        )
    },
    fieldNames: new[] { "Front", "Back" }
);

var collection = new AnkiCollection();

var noteTypeId = collection.CreateNoteType(noteType);
var deckId = collection.CreateDeck("My Anki Deck");

collection.CreateNote(deckId, noteTypeId, "Hello", "Bonjour");

await AnkiFileWriter.WriteToFileAsync("MyCollection.apkg", collection);

Acknowledgement

Anki.NET is a fork form the the archived AnkiSharp project from Clement-Jean. Thanks a lot for the hard work!

Usage

AnkiCollection

Start by creating an AnkiCollection. To add notes to the collection, you need a notes model (AnkiNoteType), you can pass in the constructor, like this. A note can correspond to one or several cards, if their model has several card tempates ('AnkiCardType').

var cardTypes = new[]
{
    new AnkiCardType(
        "Forwards",
        0,
        "{{Front}}<br/>{{hint:Help}}",
        "{{Front}}<hr id=\"answer\">{{Back}}"
    ),
    new AnkiCardType(
        "Backwards",
        1,
        "{{Back}}<br/>{{hint:Help}}",
        "{{Back}}<hr id=\"answer\">{{Front}}"
    )
};

var noteType = new AnkiNoteType(
    "Basic (With hints)",
    cardTypes,
    new[] { "Front", "Back", "Help" }
);
        
var collection = new AnkiCollection();
var noteTypeId = collection.CreateNoteType(noteType);

AnkiDeck

var collection = new AnkiCollection();

var deckId = collection.CreateDeck("French vocabulary");

bool deckExists = collection.TryGetDeckById(deckId, out var deck);

AnkiNote

With the above AnkiNoteType (which has two card types), each added note will generate 2 different cards.

collection.CreateNote(deckId, notetypeId, "Hello", "Bonjour", "");
collection.CreateNote(deckId, noteTypeId, "House", "Maison", "Starts with \"M\"");

Set CSS

var noteType = new AnkiNoteType(
    name: "Basic",
    cardTypes: cardTypes,
    fieldNames: names,
    css: @".card{
        color: red;
    }",
);

Read AnkiCollection from .apkg file

AnkiCollection collection = await AnkiFileReader.ReadFromFileAsync("collection.apkg");

Write AnkiCollection to .apkg file

var collection = new AnkiCollection();
await AnkiFileWriter.WriteToFileAsync("MyCollection.apkg", collection);

Resources

anki.net's People

Contributors

clement-jean avatar lysrt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.