ObsidianToAnki / Obsidian_to_Anki

Script to add flashcards from text/markdown files to Anki
GNU General Public License v3.0
1.51k stars 132 forks source link

Regex for extra fields in highlighted curly cloze cards #220

Open usmaanb opened 3 years ago

usmaanb commented 3 years ago

Is there a way to configure the regex to allow extra fields in highlighted curlycloze cards? Currently my regex is as follows (from the wiki for highlighted cloze cards): ((?:.+\n)*(?:.*==.*)(?:\n(?:^.{1,3}$|^.{4}(?<!<!--).*))*)

Is there a way to customise the regex so that it can detect both the cloze and the input for the "extra" field on the cloze card, like if the example below were to scanned?: This is a ==Cloze== card Extra: This is extra information Such that everything after Extra: is added to the "extra" field of the card?

gsneath commented 2 years ago

Any update on this? I need to do this as well.

timblaktu commented 2 years ago

@usmaanb @gsneath I believe you'd need to modify the regex to have another capture group that corresponds to the extra field. The docs for writing custom regexes in this plugin, say:

You need to have as many capture groups in your regexp as there are fields in the note type

.. and the Anki docs for cloze-deletion imply that for the cloze note type there is only a single field, and that Extra is an optional second field:

The default cloze note type has a second field called Extra, that is shown on the answer side of each card. It can be used for adding some usage notes or extra information.

Incidentally, the documented highlight-cloze style does not work for me, and I wonder if you lend some extra pairs of eyes to check my work. This is what I have done/tested:

  1. Cloze Custom Regex in Note type table: ((?:.+\n)*(?:.*==.*)(?:\n(?:^.{1,3}$|^.{4}(?<!<!--).*))*)
  2. CurlyCloze - Highlights to Clozes in ENABLED.
  3. Added the following markdown to a file in my Vault, and Sync Vault:
IPSEC provides ==Authentication==

..I get all the expected successful notifications about the sync, but nothing appears in my target Anki deck (Default).

I have vetted my setup using Basic regex cards using the documented Sub-header style which creates cards just fine, as do basic and the non-highlight "Paragraph" cloze type documented on the same page as the highlight one.

So, seems there's an issue with the documented regex. Putting the faulty regex and my test line from above into regex101.com, I see there is a single match group, matching the entire string:

image

Do you see anything wrong here? Thanks a million.

timblaktu commented 2 years ago

The problem was that I didn't have BOTH CurlyCloze Obsidian_to_anki plugin settings enabled:

image

The docs for the highlight cloze style don't make it clear that both are required.

I'd love to update the GitHub repo Wiki to make this more clear, but it does not appear to be editable by me, nor does the wiki appear to be in the repo, so I cannot edit it via a PR from a repo fork. Any suggestions on how to contribute here?

timblaktu commented 2 years ago

Also @usmaanb @gsneath, see this solution to your original question.