Skip to content

A simple NodeJS utility to create ANKI cards from a regular markdown file.

Notifications You must be signed in to change notification settings

anatoly314/markdown2anki

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MarkDown to ANKI

A simple NodeJS utility to create ANKI cards from a regular markdown file.

Reason

ANKI is a great tool to learn something new or refresh your knowledge. But creating ANKI cards manually and editing it one by one can be a tedious task. So, I decided to make this simple NodeJS utility to automate it. You write your markdown file once. Mark by special marks where your questions/answers begin, run this tool and it will create new cards via REST API thanks to this ANKI extension ANKI Connect

  • Example of markdown file example.md:
DECK=JavaScript Test
MODEL=Basic Code Highlight

#QUESTION#
What is the JavaScript?
#ANSWER#
JavaScript is the programming language.

#QUESTION#
Write a simple programm which prints "Hello World" in JavaScript
#ANSWER#
    ```
    console.log("Hello World")
    ```
  • This file above will generate 2 ANKI cards with corresponded questions and answers.
  • #QUESTION# and #ANSWER# selectors defining the starting of question and answer respectively.
  • DECK and MODEL defining deck name and model name (note type) respectively.
  • Thanks to highlight.js source code will be highlighted in the right way.

Prerequisites

  • ANKI
  • ANKI Connect
  • NodeJS >= 10 (I always used the latest NodeJS library but guess that older will work as well)

Usage

Configuration

The configuration is done in the .env file located in the root folder.

ANKI_URI=http://localhost:8765
ANKI_API_VERSION=6
MARKDOWN_QUESTION_SELECTORS=#QUESTION#
MARKDOWN_ANSWER_SELECTORS=#ANSWER#
MARKDOWN_PATH_TO=/Users/anatoly/Documents/git/anki-cards/
OVERRIDE_NOTE=false
  • Most settings are self explaining.
  • MARKDOWN_QUESTION_SELECTORS and MARKDOWN_ANSWER_SELECTORS are selectors which defining the start of the question and answer, see example.md above. They both can contain multiple selectors separated by a comma.
  • MARKDOWN_PATH_TO, path to directory where markdown file placed. Right now only single markdown file supported. Images must be places in this directory in images sub-directory
  • OVERRIDE_NOTE, if true it will override answer for the note with the same Front field
  • I advice you to clone the Basic model (note type) and add to its styling section the one of the following CSS styles supported by highlight.js to support highlighting.
  • To support inline highlight you should use the following workaround, manually add the following CSS to styling section:
.inline-code {
    padding: .2em .4em;
    margin: 0;
    font-size: 85%;
    background-color: rgba(27,31,35,.05);
    border-radius: 6px;
}

For more details, look at this issue when using renderInline, highlight doesn't work.

About

A simple NodeJS utility to create ANKI cards from a regular markdown file.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published