Fixed a broken render of a cloze note

This commit is contained in:
Renat Galimov 2023-06-26 08:42:08 +03:00
parent d9ca850a6c
commit db56dfabd1
No known key found for this signature in database
GPG key ID: C70149D1B379469F
3 changed files with 32 additions and 4 deletions

View file

@ -7,9 +7,9 @@
;; Created: Thu May 11 14:05:13 2023 (+0300) ;; Created: Thu May 11 14:05:13 2023 (+0300)
;; Version: ;; Version:
;; Package-Requires: ((ert)) ;; Package-Requires: ((ert))
;; Last-Updated: Mon May 22 18:18:50 2023 (+0300) ;; Last-Updated: Mon Jun 26 08:41:59 2023 (+0300)
;; By: Renat Galimov ;; By: Renat Galimov
;; Update #: 247 ;; Update #: 256
;; URL: https://github.com/orgtre/anki-editor ;; URL: https://github.com/orgtre/anki-editor
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
@ -218,5 +218,24 @@ Simple note body
nil)))))))) nil))))))))
;; The problem with this behavior is that it gets "Back Extra" from
;; the headline. I'd prefer back-extra to be empty.
(ert-deftest test--note-at-point-for-cloze-with-front-should-render-note()
"Test `anki-editor--note-at-point' for cloze with front should render note."
(save-window-excursion
(with-current-buffer (anki-editor-test--test-org-buffer "test.org")
(anki-editor-test--go-to-headline "Cloze with text")
(anki-editor-test--patch-variables
(lambda ()
(should (equal
(anki-editor-note-at-point)
#s(anki-editor-note nil
"Cloze"
"Tests"
(("Back Extra" . "<p>\ntest <b>Cloze with text</b></p>\n")
("Text" . "<p>\nLorem {{c1::lorem}}.\n</p>\n"))
nil))))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; anki-editor-tests.el ends here ;;; anki-editor-tests.el ends here

View file

@ -925,11 +925,12 @@ Return a list of cons of (FIELD-NAME . FIELD-CONTENT)."
(let* ((formatted-heading (or (and format (anki-editor--export-field (format heading-format heading) format)) (let* ((formatted-heading (or (and format (anki-editor--export-field (format heading-format heading) format))
heading)) heading))
(heading-field (unless prepend-heading formatted-heading)) (heading-field (unless prepend-heading formatted-heading))
(formatted-subheading-fields (mapcar (lambda (field) (anki-editor--export-field (cdr field) format)) subheading-fields))
(body-field (seq-reduce (lambda (acc value) (string-trim (concat acc "\n\n" (string-trim (or value ""))))) (body-field (seq-reduce (lambda (acc value) (string-trim (concat acc "\n\n" (string-trim (or value "")))))
(list (list
(when prepend-heading formatted-heading) (when prepend-heading formatted-heading)
(anki-editor--export-field content-before-subheading format) (anki-editor--export-field content-before-subheading format)
(anki-editor--concat-fields fields-extra subheading-fields level)) (anki-editor--concat-fields fields-extra formatted-subheading-fields level))
"")) ""))
;; `field-pool' ia list of all extra fields available to fill the missing fields ;; `field-pool' ia list of all extra fields available to fill the missing fields
(field-pool (remq nil (list heading-field body-field)))) (field-pool (remq nil (list heading-field body-field))))
@ -941,7 +942,6 @@ Return a list of cons of (FIELD-NAME . FIELD-CONTENT)."
(cl-loop for missing-field in fields-missing (cl-loop for missing-field in fields-missing
for field = (pop field-pool) for field = (pop field-pool)
do (push (cons missing-field field) fields))) do (push (cons missing-field field) fields)))
fields))) fields)))
(defun anki-editor--concat-fields (field-names field-alist level) (defun anki-editor--concat-fields (field-names field-alist level)

View file

@ -77,5 +77,14 @@ Note with file link
** Back ** Back
[[file:test-attachments/1x1.gif][Test image]] [[file:test-attachments/1x1.gif][Test image]]
* Cloze with text
:PROPERTIES:
:ANKI_NOTE_TYPE: Cloze
:ANKI_DECK: Tests
:END:
** Text
Lorem {{c1::lorem}}.
* Whatever * Whatever
as as