Backlink Formatting

This commit is contained in:
Correl Roush 2022-07-13 12:51:10 -04:00
parent 841202288a
commit 5cef9aa24d
2 changed files with 44 additions and 0 deletions

View file

@ -48,5 +48,14 @@
(goto-char (org-roam-backlink-point backlink))
(org-roam-export--excerpt)))
(defun org-roam-export-format-backlink (title excerpt)
"Format a backlink with TITLE and EXCERPT for inclusion in an Org document."
(with-temp-buffer
(org-mode)
(insert "** " title "\n\n")
(if (string-match-p "^\*+ " excerpt) (org-paste-subtree 3 excerpt)
(insert excerpt))
(buffer-string)))
(provide 'org-roam-export)
;;; org-roam-export.el ends here

View file

@ -115,5 +115,40 @@ venenatis eget. Proin laoreet nulla a enim bibendum finibus. Proin mattis
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
Paragraph text.
"
(org-roam-export-format-backlink
"Heading > Subheading"
"Paragraph text.\n"))))
(ert-deftest format-backlink-with-subheadings ()
(should (equal "** Heading
*** Subheading One
Paragraph text.
**** Subheading Two
***** Subheading Two A
Paragraph text.
"
(org-roam-export-format-backlink
"Heading"
"** Subheading One
Paragraph text.
*** Subheading Two
**** Subheading Two A
Paragraph text.
"))))
(provide 'tests)
;;; tests.el ends here