Mochitto / Markdown2Anki

A CLI tool and an apkg template to allow you to create flashcards from markdown and have a better experience while using anki for your studies. 🌸
105 stars 3 forks source link

Cloze deletion doesn't work as expected #1

Closed Mochitto closed 1 year ago

Mochitto commented 1 year ago

Cloze deletion uses \b{word}\b as pattern. The border makes it fail when the characters are symbols. For example: {{c1::This cloze !}}. https://github.com/Mochitto/Markdown2Anki/blob/6019cf83db46d86336740c26a3cb3e71512760e0/src/markdown2anki/md_2_anki/process_clozes/__init__.py#L81 At the same line, the matches are also not escaped before being used, so a cloze with * will count it as a regex character.

It also fails when the cloze is very small and present in a lot of parts of the card (think of a cloze on a vim command card, which can be a single letter a), due to searching in all of the text.


A solution could be to rework the clozes system to store index position when looking for clozes and give up on the feature of turning all words into clozes. By stopping at the first regex match and starting right before the cloze, it's possible to precisely only get the right cloze and no other words, even for single-letter clozes.

Mochitto commented 1 year ago

Solved by c72316d