Skip to content

Commit

Permalink
feat: Now cross-post Target links work too!
Browse files Browse the repository at this point in the history
Thanks to the magical Org Element API function
`org-element-target-parser` :)
  • Loading branch information
kaushalmodi committed Feb 18, 2022
1 parent e92b8ab commit a33ff23
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
11 changes: 5 additions & 6 deletions ox-hugo.el
Expand Up @@ -2119,12 +2119,11 @@ INFO is a plist used as a communication channel."
(cond
((equal (org-element-type elem) 'headline)
(setq anchor (org-hugo--get-anchor elem info)))
(t ;This could be the case if `search-str' is a Target link.
;; But I don't know how exactly I would derive a target link's
;; anchor, because for target links, the element type is a
;; `paragraph', and that doesn't have any reference to the
;; `target' Org element.
))
(t
;; If current point has an Org Target, get the target anchor.
(let ((target-elem (org-element-target-parser)))
(when (equal (org-element-type target-elem) 'target)
(setq anchor (org-blackfriday--get-target-anchor target-elem))))))
(when (org-string-nw-p anchor)
(setq anchor (format "#%s" anchor)))
;; (message "[search and get anchor DBG] anchor: %S" anchor)
Expand Down
2 changes: 1 addition & 1 deletion test/site/content-org/all-posts.org
Expand Up @@ -3651,7 +3651,7 @@ links to targets will be resolved to the containing file.

- [[file:issues/issue-556.org::#heading-xyz][Link to CUSTOM_ID]]
- [[file:issues/issue-556.org::* Heading 3][Link to a heading]]
- [[file:issues/issue-556.org::paragraph-2][Link to an Org Target]]
- Links to Org Targets: [[file:issues/issue-556.org::paragraph-2][here]] and [[file:issues/issue-556.org::.paragraph-3][here]]
*** Internal links :internal_links:
Internal links point to targets in the current subtree that will be
exported to the same Hugo post as the link source. To handle links to
Expand Down
3 changes: 3 additions & 0 deletions test/site/content-org/issues/issue-556.org
Expand Up @@ -57,6 +57,9 @@ paragraph one
<<paragraph-2>>
paragraph two

<<.paragraph-3>>
paragraph three

* Local Variables :ARCHIVE:noexport:
#+bind: org-hugo-anchor-functions (org-hugo-get-custom-id org-hugo-get-id org-hugo-get-heading-slug org-hugo-get-md5)
# Local Variables:
Expand Down
3 changes: 3 additions & 0 deletions test/site/content/issues/issue-556.md
Expand Up @@ -55,3 +55,6 @@ paragraph one

<span class="org-target" id="org-target--paragraph-2"></span>
paragraph two

<span class="org-target" id="paragraph-3"></span>
paragraph three
2 changes: 1 addition & 1 deletion test/site/content/posts/links-outside-the-same-post.md
Expand Up @@ -16,7 +16,7 @@ links to targets will be resolved to the containing file.

- [Link to CUSTOM_ID]({{< relref "issue-556#heading-xyz" >}})
- [Link to a heading]({{< relref "issue-556#heading-abc" >}})
- [Link to an Org Target]({{< relref "issue-556" >}})
- Links to Org Targets: [here]({{< relref "issue-556#org-target--paragraph-2" >}}) and [here]({{< relref "issue-556#paragraph-3" >}})


## Internal links <span class="tag"><span class="internal_links">internal-links</span></span> {#internal-links}
Expand Down

0 comments on commit a33ff23

Please sign in to comment.