diff --git a/ox-hugo.el b/ox-hugo.el index f14cc05..afb274b 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -3904,12 +3904,17 @@ links." (org-export-resolve-fuzzy-link link info) (org-export-resolve-id-link link info))) (source-path (org-hugo--get-element-path link info)) - (destination-path (org-hugo--get-element-path destination info))) + (destination-path (org-hugo--get-element-path destination info)) + (destination-type (org-element-type destination))) + ;; (message "[ox-hugo pre process DBG] destination type: %s" destination-type) + ;; Change the link if it points to a valid ;; destination outside the subtree. (unless (equal source-path destination-path) - (let ((link-copy (org-element-copy link))) - (apply #'org-element-adopt-elements link-copy (org-element-contents link)) + (let ((link-desc (org-element-contents link)) + (link-copy (org-element-copy link))) + ;; (message "[ox-hugo pre process DBG] link desc: %s" link-desc) + (apply #'org-element-adopt-elements link-copy link-desc) (org-element-put-property link-copy :type "file") (org-element-put-property link-copy :path @@ -3937,6 +3942,16 @@ links." (t (let ((anchor (org-hugo--get-anchor destination info))) (concat destination-path ".org::#" anchor))))) + ;; If the link destination is a heading and if + ;; user hasn't set the link description, set the + ;; description to the destination heading title. + (when (and (null link-desc) + (equal 'headline destination-type)) + (let ((headline-title + (org-hugo--sanitize-title + info (org-element-property :title destination)))) + ;; (message "[ox-hugo pre process DBG] destination heading: %s" headline-title) + (org-element-set-contents link-copy headline-title))) (org-element-set-element link link-copy)))))))) ;; Workaround to prevent exporting of empty special blocks. diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index 7d48bd8..6884403 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -3057,6 +3057,7 @@ resolved to the containing post. - Link to CUSTOM_ID outside the same post: [[#external-target]] - Link to ID outside the same post: [[id:de0df718-f9b4-4449-bb0a-eb4402fa5fcb]] - Link to target outside the same post: [[*External target]] +- Another link to target outside the same post: [[* External target with *bold* and /italic/]] - Link to subtree by CUSTOM_ID: [[#link-destination]] - Link to subtree by ID: [[id:1e5e0bcd-caea-40ad-a75b-e488634c2678]] - Link to subtree by headline: [[*Link destination]] @@ -3064,6 +3065,7 @@ resolved to the containing post. - [[#external-target][Link to CUSTOM_ID outside the same post]] - [[id:de0df718-f9b4-4449-bb0a-eb4402fa5fcb][Link to ID outside the same post]] - [[*External target][Link to target outside the same post]] +- [[* External target with *bold* and /italic/][Another link to target outside the same post]] - [[#link-destination][Link to subtree by CUSTOM_ID]] - [[id:1e5e0bcd-caea-40ad-a75b-e488634c2678][Link to subtree by ID]] - [[*Link destination][Link to subtree by headline]] @@ -3085,6 +3087,7 @@ resolved to the containing post. :ID: de0df718-f9b4-4449-bb0a-eb4402fa5fcb :END: <> +**** External target with *bold* and /italic/ * Equations :equations:mathjax: ** Inline equations :PROPERTIES: diff --git a/test/site/content/posts/link-destination.md b/test/site/content/posts/link-destination.md index f5d1d56..c2a5aec 100644 --- a/test/site/content/posts/link-destination.md +++ b/test/site/content/posts/link-destination.md @@ -6,4 +6,7 @@ draft = false ## External target {#external-target} - + + + +## External target with **bold** and _italic_ {#external-target-with-bold-and-italic} diff --git a/test/site/content/posts/links-outside-the-same-post.md b/test/site/content/posts/links-outside-the-same-post.md index 9068ef8..338dd97 100644 --- a/test/site/content/posts/links-outside-the-same-post.md +++ b/test/site/content/posts/links-outside-the-same-post.md @@ -30,7 +30,7 @@ init file. - [Link to CUSTOM\_ID within the same post](#internal-target) - [Link to ID within the same post](#internal-target) - [Link to headline within the same post](#internal-target) -- [Link to target within the same post](#orgc42fc68) +- [Link to target within the same post](#org5518ced) ## Cross-post links {#cross-post-links} @@ -46,12 +46,13 @@ resolved to the containing post. ### Links without descriptions {#links-without-descriptions} -- Link to CUSTOM\_ID outside the same post: [{{< relref "link-destination#external-target" >}}]({{< relref "link-destination#external-target" >}}) -- Link to ID outside the same post: [{{< relref "link-destination#external-target" >}}]({{< relref "link-destination#external-target" >}}) -- Link to target outside the same post: [{{< relref "link-destination#external-target" >}}]({{< relref "link-destination#external-target" >}}) -- Link to subtree by CUSTOM\_ID: [{{< relref "link-destination" >}}]({{< relref "link-destination" >}}) -- Link to subtree by ID: [{{< relref "link-destination" >}}]({{< relref "link-destination" >}}) -- Link to subtree by headline: [{{< relref "link-destination" >}}]({{< relref "link-destination" >}}) +- Link to CUSTOM\_ID outside the same post: [External target]({{< relref "link-destination#external-target" >}}) +- Link to ID outside the same post: [External target]({{< relref "link-destination#external-target" >}}) +- Link to target outside the same post: [External target]({{< relref "link-destination#external-target" >}}) +- Another link to target outside the same post: [External target with bold and italic]({{< relref "link-destination#external-target-with-bold-and-italic" >}}) +- Link to subtree by CUSTOM\_ID: [Link destination]({{< relref "link-destination" >}}) +- Link to subtree by ID: [Link destination]({{< relref "link-destination" >}}) +- Link to subtree by headline: [Link destination]({{< relref "link-destination" >}}) ### Links with descriptions {#links-with-descriptions} @@ -59,6 +60,7 @@ resolved to the containing post. - [Link to CUSTOM\_ID outside the same post]({{< relref "link-destination#external-target" >}}) - [Link to ID outside the same post]({{< relref "link-destination#external-target" >}}) - [Link to target outside the same post]({{< relref "link-destination#external-target" >}}) +- [Another link to target outside the same post]({{< relref "link-destination#external-target-with-bold-and-italic" >}}) - [Link to subtree by CUSTOM\_ID]({{< relref "link-destination" >}}) - [Link to subtree by ID]({{< relref "link-destination" >}}) - [Link to subtree by headline]({{< relref "link-destination" >}}) @@ -66,7 +68,7 @@ resolved to the containing post. ## Internal target {#internal-target} - + ## Link destination {#link-destination} @@ -74,4 +76,7 @@ resolved to the containing post. ### External target {#external-target} - + + + +### External target with **bold** and _italic_ {#external-target-with-bold-and-italic}