Skip to content
/ ankiorg Public

Emacs anki-editor add-on which pulls Anki notes to Org

Notifications You must be signed in to change notification settings

orgtre/ankiorg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

AnkiOrg

AnkiOrg is an add-on to Emacs anki-editor which can pull notes from Anki, convert them to anki-editor’s org representation of an Anki note, and insert them into an org-mode buffer. It provides two ways of interfacing with Anki: either via Anki-Connect or by more directly accessing the Anki SQL database using emacs-sqlite3-api (this can be faster and works when Anki is not running). The html notes returned by Anki are converted to org using pandoc.

Currently, the code is still a bit messy (TODO), but I’ve been successfully using this to export all my existing Anki decks to org when migrating to anki-editor. From that moment on I’ve been managing all my Anki notes from Emacs using anki-editor. It works great! In my Emacs-Anki workflow, I also make use of org-transclusion for providing card context and math-preview for previewing MathJax equations.

Since I started working on this, org-anki has emerged as a feasible alternative to anki-editor (whose original repository is unmaintained) and the pull features provided in this package. However, org-anki does not provide all the features of anki-editor and AnkiOrg, so this might still be an alternative worth exploring. (TODO: Write more detailed comparison.)

Installation

First install the following dependencies outside Emacs: Emacs, Anki, Anki-Connect, curl, and pandoc. Make sure curl and pandoc are in the path used by Emacs. Optionally, to use the SQLite interface you also need emacs-sqlite3-api.

Note: Not all versions of Anki/Anki-Connect may work. Versions which have been tested and work include Anki version 2.1.54 and 24.04.1, and Anki-Connect version 22.7.14.0 and 24.2.26.0.

Next, install the latest version of anki-editor, anki-editor/anki-editor. (The original repository louietan/anki-editor is not maintained anymore.)

Finally, you should now have all dependencies and can install this package in whatever way you like.

I use the following to install this package and the other necessary Emacs packages with straight.el:

(use-package sqlite3
  :straight (:host github :repo "pekingduck/emacs-sqlite3-api"))

(use-package anki-editor  
  :straight (:host github :repo "anki-editor/anki-editor"))

(use-package ankiorg
  :straight (:host github :repo "orgtre/ankiorg")
  :custom
  (ankiorg-sql-database
   "my-path-to/collection.anki2")
  (ankiorg-media-directory
   "my-path-to/img"))

Usage

From an org buffer, run the command ankiorg-pull-notes and select the deck you want to pull. (TODO: Write function to pull all decks.) The org representations of the Anki notes will be inserted into the buffer. Next run command ankiorg-buffer-get-media-files from the same buffer to get the media files linked in the buffer from Anki and save them to your ankiorg-media-directory. (TODO: Make this one call.)

To use the SQL interface, enable ankiorg-sql-minor-mode. It is strongly recommended that you work with a (recent) copy of your Anki SQL database, whose path needs to be set in ankiorg-sql-database. Anki and Anki-Connect need to be running when using the Anki-Connect interface, and (for now) also when retrieving media files. (TODO: Allow retrieving media files via the SQL interface too.) (TODO: Write a detailed usage example.)

Limitations and known issues

ankiorg-pull-notes is not a perfect inverse of anki-editor-push-notes. The main issue is that some line breaks are not properly preserved. I use a bunch of regex’s in the output buffer to correct for most of this. (TODO: Integrate these into the package and fix this better.)

Also, if you use Anki’s buttons for creating nested lists (via the insert list and indent buttons), there is an unfixed Anki bug which causes pandoc to parse nested lists incorrectly. The default regex replacement in the variable ankiorg-anki-replacements should correct for this up to one level of nesting, but not further.

Pull requests, issue reports, and suggestions are most welcome! To encourage contributions, I have used the TODO keyword for marking some outstanding tasks both in this readme and the source code.

About

Emacs anki-editor add-on which pulls Anki notes to Org

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published