Convert Anki Flashcards into Gitbook

Anki is a great flashcard tool for memorizing new words, and here how to convert the flashcard desk in anki to wordlists in pdf, epub and html. This procedure is done on Mac OSX 10.10, and probably work similarly on other Unix system.

Recently I’ve been working on GRE vocabulary, and Anki is a well-known multi-platform app for this. There are many great sets of cards and sometimes you just want to use them else where such as creating some wordlist. And this time, I need some wordlists from GRE3000, a popular book in China. I bought the printed version, but it is in alphabetical order. Luckily someone has made an Anki desk for it!

The vocabulary desks .apkg files are just .zip packages, you can just unzip it with command line:

1
unzip the_desk_name.apkg

There are several files there, what we need is the .anki2 file which is basically a sqlite database. Change the extension to sqlite and you can do anything with it! I just open it up with the Firefox extension - SQLite Manager.

img SQLite Manager

Run the following SQL query to get the data we need, and then save it as csv(with or without header).

1
SELECT sfld, flds FROM notes

Then we need to set up the gitbook engine. Firstly, nodejs and npm is needed, following the guide on the website. And then install gitbook-cli and initialize a project.

1
npm install gitbook-cli -g
cd your_workspace
mkdir book
cd book
gitbook init
cp list.csv .

And then, I wrote a ruby script to generate the markdown files needed to create the book.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'csv'

#size of the wordlists
list_size = 20.0
words = CSV.read('list.csv')
words.delete_at(0) #if there is a header line
words = words.shuffle



summary = File.new('SUMMARY.md', 'w')
summary.puts "#Content\n"

for i in 1..(words.length/list_size).ceil
file = File.new('./src/List'+i.to_s+'.md', 'w')
file.puts "#List#{i}"
summary.puts "* [List#{i}](src/List#{i}.md) "

#you might need to change this part to fit different desks
for i in 1..list_size
file.puts "\n\n---\n\n" unless i == 1
content = words.shift()
if content.nil?
break
end
file.puts content[1]
end
file.close
end

summary.close

Save this script and execute it at the folder. And don’t forget to write something in the README.md. Now you can use gitbook serve to see the web version of the book.

To make a file version, we need to download and install Calibre and use the ebook-convert tool inside. For Mac OSX, we need to add the tool to the $PATH.

1
export PATH=$PATH:/Applications/calibre.app/Contents/MacOS

Finally, we shall compile the book!

1
cd ..
gitbook epub /book

And then you’ll see the book inside your work folder.

Have fun!