Coder Social home page Coder Social logo

Comments (3)

protesilaos avatar protesilaos commented on September 2, 2024

Thank you @fingerknight!

Can you try a diff?

 denote.el | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/denote.el b/denote.el
index c3e5cb5..c0f8a4c 100644
--- a/denote.el
+++ b/denote.el
@@ -4080,10 +4080,9 @@ ;;;;; Register `denote:' custom Org hyperlink
 
 (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."
+(defun denote-link--ol-resolve-link-to-target (link &optional full-data)
+  "Resolve LINK to target file, with or without additioanl search terms.
+With optional FULL-DATA return a list in the form of (path id search)."
   (let* ((search (and (string-match "::\\(.*\\)\\'" link)
                       (match-string 1 link)))
          (id (if (and search (not (string-empty-p search)))
@@ -4091,8 +4090,8 @@ (defun denote-link--ol-resolve-link-to-target (link &optional path-id)
                link))
          (path (denote-get-path-by-id id)))
     (cond
-     (path-id
-      (cons (format "%s" path) (format "%s" id)))
+     (full-data
+      (list path id search))
      ((and search (not (string-empty-p search)))
       (concat path "::" search))
      (path))))
@@ -4174,17 +4173,24 @@ (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-relative-name (car path-id)))
-         (p (file-name-sans-extension path))
-         (id (cdr path-id))
-         (desc (or description (concat "denote:" id))))
+  (let* ((path-id (denote-link--ol-resolve-link-to-target link :full-data))
+         (path (file-relative-name (nth 0 path-id)))
+         (id (nth 1 path-id))
+         (search (nth 2 path-id))
+         (anchor (file-name-sans-extension path))
+         (anchor-html (if search
+                          (concat (file-name-sans-extension path) search)
+                        anchor))
+         (desc (cond
+                (description)
+                (search (format "denote:%s::%s" id search))
+                (t (concat "denote:" id)))))
     (cond
-     ((eq format 'html) (format "<a href=\"%s.html\">%s</a>" p desc))
+     ((eq format 'html) (format "<a href=\"%s.html\">%s</a>" anchor-html 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))
+     ((eq format 'md) (format "[%s](%s.md)" desc anchor))
      (t path))))
 
 ;; The `eval-after-load' part with the quoted lambda is adapted from

from denote.

fingerknight avatar fingerknight commented on September 2, 2024

Perhaps I have not clarified the case.

Assume there are two files a.org:

* Headline
content

and b.org:

[[denote:a::Headline][NAME]]

Exported b.org, we should obatin <a href="a.html#Headline">NAME</a>, Headline being a HTML anchor.

The diff is just to adjust the exported file name.

For html, it should be like

(format "<a href=\"%s.html%s\">%s</a>"
        (file-name-sans-extension path)
        (if search
            (concat "#" search)
          "")
        desc)

As for md, I have no idea if it has the syntax to link to the Headline at the other file.

from denote.

protesilaos avatar protesilaos commented on September 2, 2024

Thank you for clarifying! I pushed the changes.

from denote.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.