You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+56-26Lines changed: 56 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
1
# Obsidian_to_Anki
2
-
Script to add flashcards from an Obsidian markdown file to Anki.
2
+
Script to add flashcards from a properly-formatted file to Anki. Run from the command line. Built with Obsidian markdown syntax in mind.
3
3
4
4
## Setup
5
5
1. Install [Python](https://www.python.org/downloads/). Note that the script was written in Python3.8 - I don't think it would work on older versions (confirmed that it doesn't work on Python2 via [this issue](https://github.com/Pseudonium/Obsidian_to_Anki/issues/6#issue-690905446))
6
6
2. Download the desired release.
7
7
3. Place the script "obsidian_to_anki.py" in a convenient folder. You may wish to consider placing it in a Scripts folder, and adding the folder to your PATH
8
-
4. Start up Anki, and navigate to your desired profile
8
+
4. Start up [Anki](https://apps.ankiweb.net/), and navigate to your desired profile
9
9
5. Ensure that you've installed [AnkiConnect](https://github.com/FooSoft/anki-connect).
10
10
6. Install the `python-markdown` library - see installation instructions [here](https://github.com/Python-Markdown/markdown). `pip install markdown` should work.
11
11
7. Check the Permissions tab below to ensure the script is able to run.
@@ -20,16 +20,35 @@ The script needs to be able to:
20
20
* Rename files in the directory the script is used
21
21
* Remove a backup file in the directory the script is used
22
22
23
+
## Features
24
+
25
+
Current features:
26
+
*[Custom note types](#note-formatting)
27
+
* Updating notes from file
28
+
* Substitutions - see [Config](#config)
29
+
*[Tags](#tag-formatting)
30
+
* Adding to user-specified [decks](#deck-formatting), on a *per-file* basis
31
+
*[Markdown](https://www.markdownguide.org/getting-started/) formatting - see [this](#markdown-formatting) for examples
32
+
*[Embedded images](#image-formatting) (GIFs should work too)
33
+
*[Auto-deleting notes](#deleting-notes) from the file
34
+
* Reading from all files in a directory automatically - not recursively however.
35
+
36
+
Not available:
37
+
* Audio
38
+
39
+
23
40
## Usage
24
41
For simple documentation, run the script with the `-h` flag.
25
42
26
-
To edit the config file, run `obsidian_to_anki.py -c`. This will attempt to open the config file for editing, but isn't guaranteed to work. If it doesn't work, you'll have to navigate to the config file and edit it manually. For more information, see [Config](#config)
43
+
**Apart from editing the config file, all operations of the script require Anki to be running.**
27
44
28
-
**All other operations of the script require Anki to be running.**
45
+
To add notes to Anki from a properly-formatted file, or a directory of files, run `obsidian_to_anki.py [path]`, replacing `[path]` with the path to the file or directory.
46
+
For example, running `obsidian_to_anki.py .` should add notes from all properly-formatted files in the current directory.
47
+
To avoid unexpected behaviour, the script will only scan files from a directory if they have either a `.md` or `.txt` extension. If you feel like this will be a major issue, please let me know, and I can add this as something to be configured.
29
48
30
-
To update the config file with new note types from Anki, run `obsidian_to_anki -u`
49
+
To edit the config file, run `obsidian_to_anki.py -c`. This will attempt to open the config file for editing, but isn't guaranteed to work. If it doesn't work, you'll have to navigate to the config file and edit it manually. For more information, see [Config](#config)
31
50
32
-
To add appropriately-formatted notes from a file, run `obsidian_to_anki -f {FILENAME}`
51
+
To update the config file with new note types from Anki, run `obsidian_to_anki.py -u`
33
52
34
53
## Deck formatting
35
54
Anywhere within the file, format the deck that you want the notes to go into as follows:
@@ -40,7 +59,7 @@ For example:
40
59
> TARGET DECK
41
60
> Mathematics
42
61
43
-
You may place more than one TARGET DECK, but only the first instance will be read and used.
62
+
You may place more than one TARGET DECK in the same file, but only the first instance will be read and used.
44
63
45
64
## Note formatting
46
65
@@ -54,7 +73,12 @@ In the markdown file, you must format your notes as follows:
54
73
55
74
### Markdown formatting
56
75
57
-
Standard markdown formatting is supported. GitHub-flavoured code blocks are supported (but Anki won't show syntax highlighting)
76
+
Standard markdown formatting is supported.
77
+
You can check [test.md](./test.md) as an example.
78
+
Front produced:
79
+

80
+
Back produced:
81
+

58
82
59
83
### Image formatting
60
84
@@ -64,6 +88,14 @@ Embedded images are supported if the following criteria are met:
64
88
65
89
### Tag formatting
66
90
91
+
For reference, the note formatting style is:
92
+
93
+
> START
94
+
> {Note Type}
95
+
> {Note Fields}
96
+
> Tags:
97
+
> END
98
+
67
99
Note that the Tags: line is optional - if you don't want tags, you may leave out the line.
68
100
69
101
Tags should be formatted as such:
@@ -82,7 +114,7 @@ Apart from the first field, each field must have a prefix to indicate to the pro
82
114
> Back: Test successful!
83
115
> END
84
116
85
-
When the script successfully adds a note, it will append an ID to the Note Data. This allows you to update existing notes by running the script again.
117
+
When the script successfully adds a note, it will append an ID to the Note Data. This allows you to *update existing notes by running the script again*.
86
118
87
119
Example output:
88
120
@@ -93,6 +125,21 @@ Example output:
93
125
> ID: 1566052191670
94
126
> END
95
127
128
+
### Deleting notes
129
+
130
+
The script can delete notes that *it has added* automatically. To do this:
131
+
1. Find the formatted note in your file:
132
+
> START
133
+
> {Note Type}
134
+
> {Note Data}
135
+
> ID: {Identifier}
136
+
> END
137
+
2. Change this to read:
138
+
> START
139
+
> ID: {Identifier}
140
+
> END
141
+
3. If you run the script on the file, it will interpret this as "delete the note with ID {identifier}". For convenience, it will also delete the unnecessary START END block from the file.
142
+
96
143
### Default
97
144
By default, the script:
98
145
- Adds notes with the tag "Obsidian_to_Anki" (+ other specified tags, if applicable)
@@ -137,20 +184,3 @@ Then you now format your notes like this:
137
184
> B
138
185
> {Note Data}
139
186
> END
140
-
141
-
## Features
142
-
143
-
Current features:
144
-
* Custom note types
145
-
* Updating notes from Obsidian
146
-
* Substitutions (see above)
147
-
* Auto-convert math formatting
148
-
* Tags
149
-
* Adding to decks other than Default
150
-
* Markdown formatting
151
-
* Embedded images (GIFs should work too)
152
-
153
-
Not available:
154
-
* Audio
155
-
* Deleting notes from Obsidian
156
-
* Reading from all files in a directory automatically - script works on a per-file basis
0 commit comments