Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow updating question by smarter matching #19

Open
louwers opened this issue May 21, 2022 · 2 comments
Open

Allow updating question by smarter matching #19

louwers opened this issue May 21, 2022 · 2 comments

Comments

@louwers
Copy link

louwers commented May 21, 2022

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. -->

@lukesmurray
Copy link
Owner

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.

@gromenauer
Copy link

gromenauer commented Feb 12, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants