Auto-detect `seq` cards in addcards.lua
dkl9

dkl9 commited on 2023-199 10:11:58
Showing 2 changed files, with 17 additions and 4 deletions.


Improves upon 44e11a9. Also updated documentation.md accordingly.
... ...
@@ -56,8 +56,10 @@ The notes must be separated by blank lines.
56 56
 Each note can have multiple lines.
57 57
 There must be an extra blank line at the end of the input.
58 58
 
59
-This feature can only generate basic multi-cloze cards.
60
-For now, to make a sequential card, you must input the note to the add-cards feature and manually edit the Recfile to set the card's `CardType` field to `seq`.
59
+This feature auto-detects the type of card (multi-cloze or sequential) from the content of the note.
60
+If there are braces, it's saved as multi-cloze.
61
+If there are double-semicolons, it's saved as sequential.
62
+If both are present, the procedure favours multi-cloze.
61 63
 
62 64
 ## Correcting cards
63 65
 `src/main.lua c N` (where `N` is an integer) opens the note for card N from the deck in a text editor.
... ...
@@ -17,7 +17,6 @@ local function fn(config, deck)
17 17
         local newcard = Card:new({ note = notetext, ct = "bmc", created = os.time() })
18 18
         for _re in notetext:gmatch("{[^}]+}") do
19 19
             table.insert(newcard.pr, Prompt:new({ card = newcard, ease = config:get("StartingEase") }))
20
-            prctr = prctr + 1
21 20
         end
22 21
         if mismatched(notetext) then
23 22
             io.write(string.format("Card %d (\"%s\") contains mismatched braces\n", #deck + 1, notetext))
... ...
@@ -25,8 +24,20 @@ local function fn(config, deck)
25 24
         if #newcard.pr >= 1 then
26 25
             table.insert(deck, newcard)
27 26
             cardctr = cardctr + 1
27
+            prctr = prctr + #newcard.pr
28 28
         else
29
-            io.write(string.format("Card \"%s\" contains no answers (check braces)\n", notetext))
29
+            newcard = Card:new({ note = notetext, ct = "seq", created = os.time() })
30
+            prctr = 0
31
+            for _re in notetext:gmatch(";;") do
32
+                table.insert(newcard.pr, Prompt:new({ card = newcard, ease = config:get("StartingEase") }))
33
+            end
34
+            if #newcard.pr >= 1 then
35
+                table.insert(deck, newcard)
36
+                cardctr = cardctr + 1
37
+                prctr = prctr + #newcard.pr
38
+            else
39
+                io.write(string.format("Card \"%s\" contains no answers (check braces/double-semicolons)\n", notetext))
40
+            end
30 41
         end
31 42
     end
32 43
     io.write(string.format(
33 44