Markdown2Anki
Markdown2Anki copied to clipboard
Issue/feedback for cloze card
Hello @Mochitto,
I recently came across your project while searching for a library that can transform markdown to Anki cards and I must say it's a really nice project. However, I encountered some issues when trying out the cloze card. I think the problem with Anki cloze is that in your current design, HandleClozes will eventually create the same content for both the front and back strings. But in the card/model template, the front card has {{cloze:Front}}
, and the back card has {{cloze:Back}}
. I believe this is not what Anki expects. It may work if you force import the card with an apkg file, but if you are using AnkiConnect, the addNote
call will fail. If I go to anki GUI and try to add the card with the content, it won't let me and pops out: Cloze deletion can only be used in fields which use the ‘cloze:’ filter
error.
I found a workaround by modifying the card template's back and changing {{cloze:Back}}
to {{cloze:Front}}
. This way, the backside of the card will just use the same content as the front side, which is likely what cloze deletion operation expects. Then, I am not setting the Back field when making the addNote
call.
Also, I had some trouble getting cloze cards to work at the beginning as I was doing something like:
clozes_handler = clozes.HandleClozes(markdown_content)
card_result = clozes_handler.inject_clozes(clozes_handler.hashed_markdown)
When I uploaded the card, it threw an exception, because you have the line:
t=document.querySelectorAll(e);if(!t.length)throw document.body.innerHTML=s,new Error(`Couldn't find any element matching ${e}`);return t}
And I realize the card model template is expecting the tab-group. After searching around the lib, I finally realize the correct calls are:
clozes_handler = clozes.HandleClozes(markdown_content)
# process_card is necessary to wrap around the handler output!
formatted_card_with_hashes = process_card(clozes_handler.hashed_markdown, vault)
card_result = clozes_handler.inject_clozes(formatted_card_with_hashes)
I feel like if cloze hashes and wrapping with process_card
to add the tab-group are necessary, they should have been wrapped into one function as an exposed interface, basically mimicking the process_card
counterpart:
def process_cloze(markdown_content, vault, linenos):
clozes_handler = clozes.HandleClozes(markdown_content)
formatted_card_with_hashes = clozes_handler.hashed_markdown, vault, linenos=linos)
return clozes_handler.inject_clozes(formatted_card_with_hashes)
I hope this feedback is useful to you, and I'm looking forward to hearing your thoughts on this. Thank you for your time and effort on this project.