From 3c1bab3c035e5fba31019c315458d62dfbb848af Mon Sep 17 00:00:00 2001 From: orgtre Date: Wed, 2 Nov 2022 12:34:47 +0100 Subject: [PATCH] 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. --- anki-editor.el | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/anki-editor.el b/anki-editor.el index 22945a3..9ae12ef 100644 --- a/anki-editor.el +++ b/anki-editor.el @@ -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) - (push (cons (car fields-missing) - (concat content-before-subheading - (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))))) ((equal 2 (length fields-missing)) (if (equal 0 (length fields-extra)) (progn