lukesmurray/markdown-anki-decks

Allow updating question by smarter matching

louwers opened this issue · 2 comments

Cards are uniquely identified by their deck name and question. If you change the deck name or the question you will lose the card history.

Would be cool if some (invisible) id would get added to the Markdown file's questions, that will later allow you to update the question.

I see each question has a guid. A HTML comment can be added to the Markdown questions: <!-- gid:mI-SKG((J. -->

we could add support for parsing these comments but I'm hesitant to add any features that would modify the user's files. At the moment we leave input files unchanged which is a nice guarantee that we won't mess up user's markdown. Also reverting those changes could be difficult, and I could understand if users don't want to keep the comments in their files.

In terms of implementation there isn't anything to complicated if we only add parsing support.
Some code similar to the following could work to find comments using beautiful soup, and we could parse out comments that start with gid: and use them as GUIDs.

from bs4 import BeautifulSoup as BS
from bs4 import Comment
soup = BS(html, 'html.parser')
comments = soup.find_all(string=lambda text: isinstance(text, Comment))

If parsing only is an acceptable solution than I would definitely look at/potentially accept a pull request. At the moment I'm fairly busy on other projects and don't have time to add features.

If automatically generating the codes is required then I would also be willing to look at a pull request, but only if it didn't significantly complicate the code base, and I would want the comment generation to be behind a command line flag, rather than a default.

Adding an option:

mdankideck --add-gid deck.md

That copies the same file to stdout adding <!-- gid:the_id --> in every question makes it deliberate and optional to use.