emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/denote 25fe9870dc 225/355: Finalise 'denote:' custom Or


From: ELPA Syncer
Subject: [elpa] externals/denote 25fe9870dc 225/355: Finalise 'denote:' custom Org hyperlink type
Date: Sun, 26 Jun 2022 23:58:27 -0400 (EDT)

branch: externals/denote
commit 25fe9870dc4db51e022872453d771d6978bf69b5
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Finalise 'denote:' custom Org hyperlink type
    
    The export part was missing.  It is important to return the right
    values.
    
    Relevant discussion with Frank Ehmsen on the mailing list:
    
<https://lists.sr.ht/~protesilaos/denote/%3Ccfb70295-4e54-0f54-559c-c9423df5a1d8@eh-is.de%3E>.
---
 denote-link.el | 50 +++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 39 insertions(+), 11 deletions(-)

diff --git a/denote-link.el b/denote-link.el
index b412b69017..117d1cddaf 100644
--- a/denote-link.el
+++ b/denote-link.el
@@ -294,10 +294,28 @@ manual for more on the matter)."
   (org-link-set-parameters
    "denote"
    :follow #'denote-link-ol-follow
-   :complete #'denote-link-ol-complete))
+   :complete #'denote-link-ol-complete
+   :export #'denote-link-ol-export))
 
 (declare-function org-link-open-as-file "ol" (path arg))
 
+(defun denote-link--ol-resolve-link-to-target (link &optional path-id)
+  "Resolve LINK into the appropriate target.
+With optional PATH-ID return a cons cell consisting of the path
+and the identifier."
+  (let* ((search (and (string-match "::\\(.*\\)\\'" link)
+                             (match-string 1 link)))
+            (id (if (and (stringp search) (not (string-empty-p search)))
+                 (substring link 0 (match-beginning 0))
+               link))
+         (path (expand-file-name (file-name-completion id 
(denote-directory)))))
+    (cond
+     (path-id
+      (cons (format "%s" path) (format "%s" id)))
+     ((and (stringp search) (not (string-empty-p search)))
+      (concat path "::" search))
+     (path))))
+
 (defun denote-link-ol-follow (link)
   "Find file of type `denote:' matching LINK.
 LINK is the identifier of the note, optionally followed by a
@@ -306,16 +324,9 @@ Read Info node `(org) Search Options'.
 
 Uses the function `denote-directory' to establish the path to the
 file."
-  (let* ((search (and (string-match "::\\(.*\\)\\'" link)
-                             (match-string 1 link)))
-            (id (if (and (stringp search) (not (string-empty-p search)))
-                 (substring link 0 (match-beginning 0))
-               link))
-         (path (expand-file-name (file-name-completion id (denote-directory))))
-         (target (if (and (stringp search) (not (string-empty-p search)))
-                     (concat path "::" search)
-                   path)))
-    (org-link-open-as-file target nil)))
+  (org-link-open-as-file
+   (denote-link--ol-resolve-link-to-target link)
+   nil))
 
 (defun denote-link-ol-complete ()
   "Like `denote-link' but for Org integration.
@@ -326,5 +337,22 @@ interface by first selecting the `denote:' hyperlink type."
     (denote-retrieve--read-file-prompt)
     (denote-link--file-type-format (buffer-file-name)))))
 
+(defun denote-link-ol-export (link description format)
+  "Export a `denote:' link from Org files.
+The LINK, DESCRIPTION, and FORMAT are handled by the export
+backend."
+  (let* ((path-id (denote-link--ol-resolve-link-to-target link :path-id))
+         (path (file-name-nondirectory (car path-id)))
+         (p (file-name-sans-extension path))
+         (id (cdr path-id))
+            (desc (or description (concat "denote:" id))))
+    (cond
+     ((eq format 'html) (format "<a target=\"_blank\" href=\"%s.html\">%s</a>" 
p desc))
+     ((eq format 'latex) (format "\\href{%s}{%s}" (replace-regexp-in-string 
"[\\{}$%&_#~^]" "\\\\\\&" path) desc))
+     ((eq format 'texinfo) (format "@uref{%s,%s}" path desc))
+     ((eq format 'ascii) (format "[%s] <denote:%s>" desc path)) ; NOTE 
2022-06-16: May be tweaked further
+     ((eq format 'md) (format "[%s](%s.md)" desc p))
+     (t path))))
+
 (provide 'denote-link)
 ;;; denote-link.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]