diff --git a/anki-editor-tests.el b/anki-editor-tests.el index ea65811..91c4b4e 100644 --- a/anki-editor-tests.el +++ b/anki-editor-tests.el @@ -7,9 +7,9 @@ ;; Created: Thu May 11 14:05:13 2023 (+0300) ;; Version: ;; 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 -;; Update #: 247 +;; Update #: 256 ;; URL: https://github.com/orgtre/anki-editor ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; @@ -218,5 +218,24 @@ Simple note body 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" . "

\ntest Cloze with text

\n") + ("Text" . "

\nLorem {{c1::lorem}}.\n

\n")) + nil)))))))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; anki-editor-tests.el ends here diff --git a/anki-editor.el b/anki-editor.el index 8743c9d..8cc6805 100644 --- a/anki-editor.el +++ b/anki-editor.el @@ -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)) 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 ""))))) (list (when prepend-heading formatted-heading) (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 (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 for field = (pop field-pool) do (push (cons missing-field field) fields))) - fields))) (defun anki-editor--concat-fields (field-names field-alist level) diff --git a/test-files/test.org b/test-files/test.org index e094416..39823b2 100644 --- a/test-files/test.org +++ b/test-files/test.org @@ -77,5 +77,14 @@ Note with file link ** Back [[file:test-attachments/1x1.gif][Test image]] + +* Cloze with text +:PROPERTIES: +:ANKI_NOTE_TYPE: Cloze +:ANKI_DECK: Tests +:END: +** Text +Lorem {{c1::lorem}}. + * Whatever as