diff options
author | Thanos Apollo <[email protected]> | 2024-07-16 14:04:22 +0300 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2024-07-16 14:04:40 +0300 |
commit | e6f7b6f02e7f80c39b57da0fc4d8228a6e40f973 (patch) | |
tree | 2e39902583091502a6473437dc7432331d5d98e2 | |
parent | 605b3166b7a16814ab59a5fc010f6e138858abf0 (diff) |
cloze: Add gnosis-cloze-add-hints: Add hints to cloze string.
-rw-r--r-- | gnosis.el | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -464,6 +464,19 @@ Refer to =gnosis-db-schema-extras' for informations on images stored." (replace-match (propertize cloze-string 'face 'gnosis-face-cloze) nil t))) (buffer-string)))) +(defun gnosis-cloze-add-hints (str hints &optional cloze-string) + "Replace CLOZE-STRING in STR with HINTS." + (cl-assert (listp hints) nil "Hints must be a list.") + (let ((cloze-string (or cloze-string gnosis-cloze-string)) + (count 0)) + (with-temp-buffer + (insert str) + (goto-char (point-min)) + (while (search-forward cloze-string nil t) + (when (and (nth count hints) (search-backward cloze-string nil t)) + (replace-match (propertize (format "[%s]" (nth count hints)) 'face 'gnosis-face-cloze))) + (setq count (1+ count))) + (buffer-string)))) (defun gnosis-display-basic-answer (answer success user-input) "Display ANSWER. |