jasonwilliams / anki

Anki VSCode Plugin
MIT License
275 stars 31 forks source link

How to stop text inclusion in Anki card? #51

Open sophyphile opened 3 years ago

sophyphile commented 3 years ago

Hi guys, apologies if this is a stupid question, I'm new to VS Code.

I want to add an Anki card, and then have some sort of closing operator, so that the text I write after it is not part of the Anki card. How can I do this? Is it possible with this software?

jasonwilliams commented 2 years ago

Hi @sophyphile sorry for the delayed response. I will have to try and add that as currently it’s not possible.

do you have an example to show which may help me fix this?

KennethEnevoldsen commented 2 years ago

Hi @jasonwilliams I have an a similar issue:

I have a case here:

# Topic header
Description of topic, notes etc.

first card:

## card 1
front1

%

back 1

# Topic header 2
Description of topic, notes etc.

## Card 2

front

%

back

Here the topic header 2 is included in the first card, which is naturally not the goal. One option would be to add a stop token (e.g. ## or \n\n)

jasonwilliams commented 2 years ago

Hmm yeah I wonder if stopping on a H1 would help? It already stops if it sees another h2 I believe. I’m open to ideas

KennethEnevoldsen commented 2 years ago

Stopping on H1 would help in my case. But adding an optional stopping token using regex would also be an option.

Another option would be to change the regex for detecting the card to instead of detecting the start of the card (##) use the regex to find the entire card e.g. the regex ^##((.|\n)*)## would match from ## to the next ##. If you don't want to include the ## then (?<=##)((.|\n)*?)(?=##)should also work.

KennethEnevoldsen commented 2 years ago

It seems it might be relevant to also remove ignore comment i.e. <!-- markdown comment -->.

jasonwilliams commented 2 years ago

https://github.com/jasonwilliams/anki/issues/10#issuecomment-678828123 Uses <!— Card —> maybe that’s an options

KennethEnevoldsen commented 2 years ago

Sure. However, do believe that a field with a regex for extracting the card whether it be HTML comments or using another syntax would be ideal. This would allow the user to customize to their needs

jasonwilliams commented 2 years ago

Yes we should offer an option for that. I’m just thinking of the most reasonable default

KennethEnevoldsen commented 2 years ago

I Think HTML comment is a poor default though as it is also a comment thus I would expect it to ignore it in markdown documents potentially one of these from the anki integration with obsidian: https://github.com/Pseudonium/Obsidian_to_Anki