Format backlink heading as a link

This commit is contained in:
Correl Roush 2022-07-13 19:13:41 -04:00
parent 7778b2d24e
commit c104206c91
2 changed files with 7 additions and 4 deletions

View file

@ -49,11 +49,11 @@
(goto-char (org-roam-backlink-point backlink))
(org-roam-export--excerpt)))
(defun org-roam-export--format-backlink (title excerpt)
(defun org-roam-export--format-backlink (link title excerpt)
"Format a backlink with TITLE and EXCERPT for inclusion in an Org document."
(with-temp-buffer
(org-mode)
(insert "** " title "\n\n")
(insert "** " (org-make-link-string link title) "\n\n")
(if (string-match-p "^\*+ " excerpt) (org-paste-subtree 3 excerpt)
(insert excerpt))
(buffer-string)))
@ -61,6 +61,7 @@
(defun org-roam-export-format-backlink (backlink)
"Format a BACKLINK for inclusion in an Org document."
(org-roam-export--format-backlink
(org-roam-export-backlink-link backlink)
(org-roam-export-backlink-title backlink)
(org-roam-export-backlink-excerpt backlink)))

View file

@ -116,16 +116,17 @@ lobortis quam non eleifend. Pellentesque vitae imperdiet nisl.\n")
(mapcar #'org-roam-export-backlink-excerpt (org-roam-backlinks-get (org-roam-node-from-id "e6c17c1a-6b05-40d2-a01f-b147633c51b1") :unique t)))))
(ert-deftest format-backlink-test ()
(should (equal "** Heading > Subheading
(should (equal "** [[id:34cf17c6-f804-4adb-b386-3c6dfb83cfad][Heading > Subheading]]
Paragraph text.
"
(org-roam-export--format-backlink
"id:34cf17c6-f804-4adb-b386-3c6dfb83cfad"
"Heading > Subheading"
"Paragraph text.\n"))))
(ert-deftest format-backlink-with-subheadings ()
(should (equal "** Heading
(should (equal "** [[id:9428184d-5030-4e5b-91f6-b865d5cc311b][Heading]]
*** Subheading One
@ -138,6 +139,7 @@ Paragraph text.
Paragraph text.
"
(org-roam-export--format-backlink
"id:9428184d-5030-4e5b-91f6-b865d5cc311b"
"Heading"
"** Subheading One