Obsidian_to_Anki v3.4.0 - a feature-rich plugin that allows you to add notes from Obsidian to Anki

UPDATE: v2.5.0 has released.
Lots of new things in this update:

  • Updated GUI to make it even clearer
  • Script now has a setup file
  • IDs are now wrapped in HTML comments by default
  • Regex mode can now be configured to be on by default
  • Script now falls back to a command-line interface if Gooey isnā€™t installed

Bugfixes:

  • Fixed issue with generating field substitutions dictionary
  • Fixed math formatting being incorrectly interpreted as HTML tags
  • Documentation made slightly clearer in certain places

@DavidsonTwo Added your useful feature!

8 Likes

Tested it and working very well.
Keep with the great work!

1 Like

UPDATE: v2.7.0 just released! This is an ā€˜automation updateā€™ for the script:

  • There is now an option to have the script recursively scan subfolders
  • If you supply the path to the Anki executable and the name of your profile, the script can automatically open Anki when run (if Anki isnā€™t running already)
3 Likes

UPDATE: v2.8.0 just released! This update adds more syntax for working with cloze notes, via CurlyCloze. Ankiā€™s cloze syntax is now also supported when using CurlyCloze.

2 Likes

@Aonto The new url scheme in 0.9.0 will make this super easy, since I just need the file name, so Iā€™ll wait until that goes public before adding the feature.

Thanks man :smile:

Edit:
That is why I want to use URL link to combine anki with obsidian:

1 Like

UPDATE: v2.9.0 just released. v2.9 is focusing on adding some Obsidian integration. Currently, only a link to the file that generated the flashcard, but more features will likely come once the official plugin API is out. Iā€™m likely to pause the development of the script until then.

@Aonto This should hopefully suit your needs! Itā€™ll definitely make editing the cards easier if you have a link to the file that generated them.

1 Like

It must be a strong tool for me to remember my notes and my ideas, thanks!

1 Like

I want to thank @Pseudonium, @ryanjamurphy, @Klaas, and others for the terrific script. It has been useful already, but Iā€™m wondering whether it might be possible to extend it such that it is useful for Zettelkasten.

For those of us who use Obsidian as a Zettelkasten system, one challenge we face as our list of ā€˜zettelā€™ notes grows is how to review them over the course of weeks, months, and years. Anki seems like one way to accomplish that. By exporting the zettel notes, which can be one idea, an index of ideas, or MOCs per file, to Anki, Anki can be used for review, reminder, and serendipityā€“seeing connections between old notes and new.

My Obsidian vault contains over a thousand Research Notes and Literature Notes, and each note type is formatted just a little differently with Markdown on the basis of its purpose and how old it is (2-year old notes donā€™t look like Julyā€™s notes, unforunately). The differences among the notes make it challenging to use the Obsidian to Anki script and its standard regex expressions. Iā€™ve found a workaround to this problem that is 80% effective by cloning the vault and processing the cloned .md files through BBedit and various regex ā€œsearch and replaceā€ actions. That process is labor-intensive and doesnā€™t resolve the 20% of odd cases in my vault.

So, my question: Can either the script be modified or a new regex be developed that strips line 1 of every file as the front of an Anki card and then strips every subsequent line, to the end of the file, for the back of the card regardless of what markdown characters appear on lines 2ā€“>EOF (e.g., #, ##, ā€”, *, \n, \n\n\n, etc.)? I have tried to develop a regex to accomplish this myself by modifying the Header Paragraph Style regex, but I havenā€™t had much luck, perhaps because the original script is intended to pull multiple Anki notes from a single file rather than one Anki note from one file.

Any thoughts on either the use case I imagine here or how it might be accomplished are welcome.

Grateful again for the work that has gone into the script since August.

3 Likes

@FrumpyMonk Sorry for the late reply, Iā€™ve been pretty busy with university, so I havenā€™t had much time to work on the script! Your use case is interesting. I think this regex could work - ^(.+)\n([\s\S]+). That should make the first field the first line of the note, and the second field the rest of the file. Of course, if you already have formatted cards within the file, the matches would ā€˜overlapā€™ with this match, and so the script will not add this as a card. But for a new file, or one with no formatted cards, this should hopefully work fine.

I really like this script! But Iā€™ve noticed that the clozed note feature hasnā€™t been working on my end.

I input it like this;

{C1::clozed}

I would really appreciate your input on whether Iā€™ve made a mistake?

@Terry53 Sorry for the super late reply, Iā€™ve been busy with uni! Hmm, I think itā€™s just the use of the capital C, and the double colon. See if this works: {c1:clozed}.

Not sure where the best place to post this would be, but I wanted a kind of survey from users of Obsidian_to_Anki.

Initially, I used the START END syntax to denote blocks of the text marked as flashcards - it was the first thing I could think of! And at that time I wasnā€™t too familiar with regular expressions.

Now though, the use of custom syntax via regular expressions makes my notes look clean - in fact, apart from testing, Iā€™ve never actually used the standard START END syntax of the script in my own notes!

The START END syntax does also contribute to some confusion for new users I think - the fact that you have to specify the note type straight after, huge sections of the config file reserved just for ā€˜field substitutionsā€™ and ā€˜note substitutionsā€™ etc.

Iā€™m hesitant to remove this functionality from the script, since I know some people do prefer it - though I might be able to whip up some sort of regex converter that converts a START END block into something like a question-answer block. I do feel like I could simplify both the actual code and the config file this way though.

However, seeing as the plugin API has now come out, I do feel like it might be worth having the script be purely custom-regex based as a plugin (Iā€™m thinking I might have to rewrite it in Typescript or somethingā€¦). What do people think of this? I donā€™t think I can carry over that huge config file into a ā€˜settingsā€™ part of the plugin! Though I could still just have a button for ā€˜open config fileā€™ on the settings.

tl;dr - Iā€™m thinking of removing the START END functionality (and STARTI ENDI for inline notes) when I (eventually) make the script into a plugin, and possibly also remove it from the core python script itself (which will always be available, plugin or not). What do people think of this?

EDIT: Thank you @osgav, I figured out how to make a poll!

  • Keep START END syntax in both script and eventual plugin
  • Remove START END syntax from plugin, but keep it in the script
  • Remove START END syntax completely

0 voters

Hello,

Really awesome script!

I was wondering if it would be possible to change my cloze REGEX to recognize a character other than { }. Specifically, I was hoping to change it to ## ##. I examined the REGEX provided for the config file but I honestly got a little lost with it.

If anyone has any thoughts on how to do this I would love to hear them!

First of all, thanks for the script.
I am using your script for a few weeks now, and I havenā€™t used the START END part in any of my notes, because it just doesnā€™t go well with the notes while reading.

I have modified the regex you had provided and created different card types for different use I may see.
e.g using your # styled notes, I made a small change (I dont know regex at all) and made it look for ā€˜Def:ā€™ in the next line for definition type notes. Similarly I make it look for ā€˜Meaning:ā€™ for word-meaning type notes.
I can have word meanings anywhere, I just have to write:

### Word
Meaning: Something I don't know

It makes my notes look good and at the same time pushes it to ANKI in a particuler card type that can be customized as per the need of the content type.

Though, I am struggling with cloze type notes. The script sends in the whole page into ANKI which is a huge blow for me. As I have raised an issue (rather a request) on Github too, I wanted to know if its a possibility that we can have some for of a break indicater. Like maybe two linebreaks to move the clozes in two paragraphs into two separate notes. It would make life easier. By a lot!

Thanks again :slight_smile:

Hey, love the script! Iā€™m studying for exams in my first semester of grad school and I couldnā€™t have discovered it at a better time.

I anticipate Iā€™ll be frequently embedding images and I noticed that right now, obsidianā€™s syntax of ![[attachment name]] doesnā€™t work. I glanced at Trello and was psyched to see that you have a medium term task to ā€˜Add support for Obsidian style image embeds (need plugin API to do this)ā€™ and that the API plugin has come out. Iā€™m fine just pasting attachment file paths with regular Markdown syntax - ![figure name](file path) - but I was wondering if and when you plan on releasing that feature and if there is some kind of workaround that would make obsidianā€™s file embedding syntax work?

Hi maybe you could temporary change in general Obsidian options how the images are pasted? (Uncheck ā€œUse wikilinksā€ in the ā€œFiles and Linksā€™ settingsā€)

Guys how do you deal with content structure that repeats and the missing context?

Let me explain better. I guess that there are pretty much two approaches when a similar structure is used across multiple notes.

Easiness of writing and reading

For example my approach when writing stuff and studying, Iā€™ve found out that follows a repetitive structure. Something like:

# Title
## Assumption/Context        #flashcard
Random text...
### Problem                  #flashcard
Random text...
#### Solutions               #flashcard
Random text...
##### Solution 1             #flashcard
Random text...
###### Pros vs Cons          #flashcard
Random text...
##### Solution 2             #flashcard
Random text...

This approach is amazing when writing. But there are two problems:

  • the first is that if multiple files follows the same structure, then multiple cards will have the same question, and thatā€™s a duplicate
  • the second is that when reviewing you do not have a lot of context about it

Easiness for reviewing

# Title (with a thorough description)
Random text...
## Assumption/Context (with a thorough description)       #flashcard
Random text...
### Problem (with a thorough description)                 #flashcard
Random text...
#### Solutions (with a thorough description)              #flashcard
Random text...
##### Solution 1  (with a thorough description)           #flashcard
Random text...
###### Pros vs Cons (with a thorough description)         #flashcard
Random text...
##### Solution 2 (with a thorough description)            #flashcard
Random text...

This approach works, but it does not help the writing. And a lot of us are here for this reason.

I guess, an optimal solution to the problem, would be to have both of the solution when generating a flashcard. And the idea, is to have the style of first way but providing even context when generating flashcards. Letā€™s suppose I want to generate the flashcard about ### Solution 2, then the generated flashcard would be something like:

Q: Title > Assumption/Context > Problem > Solutions > Solution 2
A: Random textā€¦ (that should be the answer to solution 2)

This pretty much it means that there should be a hierarchy. And of course, this can be applied to lists (ul, ol) too.

I generally use cloze deletetions for such cases. I simply put the contents inside the curly braces. it works well.

Even if there are multiple lines of solution:

       # Title
      ## Pros and Cons 
              * {1| Some text}
              * {2| other text}

Something like thatā€¦

1 Like

Thatā€™s a good idea and I had high hopes when I tried it out, but I still got the error ā€˜No such file or directory.ā€™ Thanks for the suggestion!