From e0b67c43964737bcfd0be610a85c38a84376671f Mon Sep 17 00:00:00 2001 From: Correl Date: Wed, 13 Jul 2022 19:44:03 -0400 Subject: [PATCH] Fix subtree excerpts Subtrees should include their initial heading and full body. --- org-roam-export.el | 11 +++++++---- tests.el | 7 +++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/org-roam-export.el b/org-roam-export.el index ffe3e26..d7ce9cd 100644 --- a/org-roam-export.el +++ b/org-roam-export.el @@ -37,10 +37,13 @@ "Extract an excerpt from ELEMENT in BUFFER." (with-current-buffer (or buffer (current-buffer)) (let ((element (or element (org-element-at-point)))) - (if-let ((begin (org-element-property :contents-begin element)) - (end (org-element-property :contents-end element))) - (buffer-substring begin end) - "")))) + (if (eq 'headline (org-element-type element)) + (progn (org-mark-subtree) + (buffer-substring (point) (mark))) + (if-let ((begin (org-element-property :contents-begin element)) + (end (org-element-property :contents-end element))) + (buffer-substring begin end) + ""))))) (defun org-roam-export-backlink-excerpt (backlink) "Get the Org element containing the link from BACKLINK as an excerpt." diff --git a/tests.el b/tests.el index eaca12f..7ae6eed 100644 --- a/tests.el +++ b/tests.el @@ -79,18 +79,21 @@ Opening paragraph. (ert-deftest excerpt-heading-with-subheadings-test () (with-test-document (goto-line 8) - (should (equal " Heading one paragraph. + (should (equal "* Heading One + + Heading one paragraph. ** Subheading One A - List item 1 - List item 2 + " (org-roam-export--excerpt))))) (ert-deftest excerpt-simple-heading-test () (with-test-document (goto-line 17) - (should (equal " Heading two paragraph.\n" (org-roam-export--excerpt))))) + (should (equal "* Heading Two\n\n Heading two paragraph.\n" (org-roam-export--excerpt))))) (ert-deftest lorem-backlink-excerpt () (should (equal '("Aliquam [[id:d12a1ce4-3199-42f4-b39b-b68c03458669][lorem]] ante, suscipit a lorem molestie, aliquet elementum eros. Proin