2022-06-12 00:07:24 +00:00
;;; org-roam-export.el --- Description -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2022 Correl Roush
;;
2022-06-12 06:23:58 +00:00
;; Author: Correl Roush <correl@gmail.com>
;; Maintainer: Correl Roush <correl@gmail.com>
2022-06-12 00:07:24 +00:00
;; Created: June 10, 2022
;; Modified: June 10, 2022
;; Version: 0.0.1
;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex tools unix vc wp
;; Homepage: https://github.com/correlr/org-roam-export
2022-07-13 21:39:39 +00:00
;; Package-Requires: ((emacs "25.1") (org-roam "2.2.1"))
2022-06-12 00:07:24 +00:00
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;; Description
;;
;;; Code:
2022-06-12 00:24:24 +00:00
( require 'org-roam )
2022-06-12 01:17:07 +00:00
( defun org-roam-export-backlink-title ( backlink )
" Get exportable title of BACKLINK. "
2022-06-12 06:18:04 +00:00
( mapconcat #' identity
( append
( list ( org-roam-node-title ( org-roam-backlink-source-node backlink ) ) )
( plist-get ( org-roam-backlink-properties backlink ) :outline ) )
" > " ) )
2022-06-12 01:17:07 +00:00
( defun org-roam-export-backlink-link ( backlink )
" Get Org link to BACKLINK. "
( concat " id: " ( org-roam-node-id ( org-roam-backlink-source-node backlink ) ) ) )
2022-06-12 00:07:24 +00:00
2022-06-12 21:47:59 +00:00
( defun org-roam-export--excerpt ( &optional buffer element )
" Extract an excerpt from ELEMENT in BUFFER. "
( with-current-buffer ( or buffer ( current-buffer ) )
( let ( ( element ( or element ( org-element-at-point ) ) ) )
2022-07-13 22:19:31 +00:00
( if-let ( ( begin ( org-element-property :contents-begin element ) )
( end ( org-element-property :contents-end element ) ) )
( buffer-substring begin end )
" " ) ) ) )
2022-06-12 21:47:59 +00:00
2022-06-12 06:07:29 +00:00
( defun org-roam-export-backlink-excerpt ( backlink )
" Get the Org element containing the link from BACKLINK as an excerpt. "
( with-temp-buffer
2022-07-13 22:19:31 +00:00
( insert-file-contents ( org-roam-node-file ( org-roam-backlink-source-node backlink ) ) )
2022-06-12 06:07:29 +00:00
( goto-char ( org-roam-backlink-point backlink ) )
2022-06-12 21:47:59 +00:00
( org-roam-export--excerpt ) ) )
2022-06-12 06:07:29 +00:00
2022-07-13 21:39:39 +00:00
( defun org-roam-export--format-backlink ( title excerpt )
2022-07-13 16:51:10 +00:00
" 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 ) ) )
2022-07-13 21:39:39 +00:00
( 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-title backlink )
( org-roam-export-backlink-excerpt backlink ) ) )
( defun org-roam-export-preprocessor ( backend )
" Append org-roam backlinks with content when applicable before
passing to the org export BACKEND. "
( when-let ( ( node ( org-roam-node-at-point ) ) )
( let ( ( backlinks ( org-roam-backlinks-get node ) ) )
( when backlinks
( save-excursion
( goto-char ( point-max ) )
( insert ( concat " \n * Backlinks \n "
( string-join ( mapcar #' org-roam-export-format-backlink backlinks ) ) ) ) ) ) ) ) )
2022-06-12 00:07:24 +00:00
( provide 'org-roam-export )
;;; org-roam-export.el ends here