Add option to prepend heading to content before first (sub)heading

Like this, when exactly one field is missing and there is content
before the first (sub)heading, the heading is seen as part of that
content and one can avoid having to duplicate it there. The
content with the prepended heading will be mapped to the missing
field. Notes in Anki and Org can be made to look more similar
without always needing a separate field for the heading.
This commit is contained in:
orgtre 2022-11-02 12:34:47 +01:00
parent b0ecbbe4ad
commit 3c1bab3c03

View file

@ -123,6 +123,12 @@ For example, you can put custom styles or scripts in this variable."
A leading logical operator like `+' or `&' is required."
:type 'string)
(defcustom anki-editor-prepend-note-heading nil
"Prepend note heading to contents before first (sub)heading.
This is only in effect when exactly one note-type field is not found
among the note subheadings and there is content before the first subheading."
:type 'boolean)
;;; AnkiConnect
@ -776,18 +782,33 @@ Return a list of cons of (FIELD-NAME . FIELD-CONTENT)."
(if (equal "" (string-trim content-before-subheading))
(push (cons (car fields-missing) heading)
fields)
(push (cons (car fields-missing) content-before-subheading)
fields))
(if anki-editor-prepend-note-heading
(push (cons (car fields-missing)
(concat heading "\n\n"
content-before-subheading))
fields)
(push (cons (car fields-missing)
content-before-subheading)
fields)))
(if (equal "" (string-trim content-before-subheading))
(push (cons (car fields-missing)
(anki-editor--concat-fields
fields-extra subheading-fields level))
fields)
(if anki-editor-prepend-note-heading
(push (cons (car fields-missing)
(concat heading "\n\n"
content-before-subheading
(anki-editor--concat-fields
fields-extra subheading-fields
level)))
fields)
(push (cons (car fields-missing)
(concat content-before-subheading
(anki-editor--concat-fields
fields-extra subheading-fields level)))
fields))))
fields-extra subheading-fields
level)))
fields)))))
((equal 2 (length fields-missing))
(if (equal 0 (length fields-extra))
(progn