Skip to content

Commit

Permalink
fix: cloze-parse handling of empty cues
Browse files Browse the repository at this point in the history
  • Loading branch information
ksqsf committed Feb 19, 2023
1 parent e1e5f76 commit f086a07
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/main/frontend/extensions/srs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,14 @@
(defn cloze-parse
"Parse the cloze content, and return [answer cue]."
[content]
(let [parts (string/split content cloze-cue-separator)]
(if (> (count parts) 1)
;; If there are more than one separator, only the last component is considered the cue.
[(string/trimr (string/join cloze-cue-separator (drop-last parts)))
(string/trim (last parts))]
;; No separator found.
[(string/join cloze-cue-separator parts) nil])))
(let [parts (string/split content cloze-cue-separator -1)]
(if (<= (count parts) 1)
[content nil]
(let [cue (string/trim (last parts))]
;; If there are more than one separator, only the last component is considered the cue.
(if (string/blank? cue)
[(string/trimr (string/join cloze-cue-separator (drop-last parts))) nil]
[(string/trimr (string/join cloze-cue-separator (drop-last parts))) cue])))))

(rum/defcs cloze-macro-show < rum/reactive
{:init (fn [state]
Expand Down

0 comments on commit f086a07

Please sign in to comment.