diff --git a/ox-hugo.el b/ox-hugo.el index 112d20c..c738861 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -1104,20 +1104,23 @@ and rewrite link paths to make blogging more seamless." (if contents (format "[%s](%s)" contents path) (format "<%s>" path)))) - (`headline - (format - "[%s](#%s)" - ;; Description - (cond ((org-string-nw-p contents)) - ((org-export-numbered-headline-p destination info) - (mapconcat #'number-to-string - (org-export-get-headline-number destination info) - ".")) - (t (org-export-data (org-element-property :title destination) - info))) - ;; Reference - (or (org-element-property :CUSTOM_ID destination) - (org-export-get-reference destination info)))) + (`headline ;Links of type [[* Some heading]] + (let ((title (org-export-data (org-element-property :title destination) info))) + ;; (message "[ox-hugo-link DBG] headline title: %s" title) + (format + "[%s](#%s)" + ;; Description + (cond ((org-string-nw-p contents)) + ((org-export-numbered-headline-p destination info) + (mapconcat #'number-to-string + (org-export-get-headline-number destination info) + ".")) + (t title)) + ;; Reference + (or (org-element-property :CUSTOM_ID destination) + (org-hugo-slug title) + ;; (org-export-get-reference destination info) + )))) (_ (let ((description (or (org-string-nw-p contents) diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index f09800f..57f11e1 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -1434,6 +1434,33 @@ attribute must apply *only* to the link, and not to the image. annotation. So the behavior will depend on the browser (typically an external link will open in a new tab automatically). ** Within the same post (Internal links) :internal_links: +*** Link to headings by name :toc:headings: +:PROPERTIES: +:EXPORT_FILE_NAME: link-to-headings-by-name +:EXPORT_OPTIONS: num:t toc:t +:END: +**** Alpha 101 +:PROPERTIES: +:UNNUMBERED: t +:END: +- Link (with description) to a heading with section number: [[* Beta 102][Link to + /Beta 102/ heading]] +- Link (no description) to a heading without section number: [[* Zeta + 103]] +**** Beta 102 +- Link (with description) to a heading without section number: [[* Alpha 101][Link to + /Alpha 101/ heading]] +***** Gamma 102.1 +****** Delta 102.1.1 +****** Epsilon 102.1.2 +**** Zeta 103 +:PROPERTIES: +:UNNUMBERED: t +:END: +***** Links (no descriptions) to headings with section numbers +- Section [[* Gamma 102.1]] +- Section [[* Delta 102.1.1]] +- Section [[* Epsilon 102.1.2]] *** Link to a heading CUSTOM_ID :PROPERTIES: :EXPORT_FILE_NAME: link-heading-custom-id diff --git a/test/site/content/posts/link-to-headings-by-name.md b/test/site/content/posts/link-to-headings-by-name.md new file mode 100644 index 0000000..5756fd0 --- /dev/null +++ b/test/site/content/posts/link-to-headings-by-name.md @@ -0,0 +1,56 @@ ++++ +title = "Link to headings by name" +tags = ["links", "internal-links", "toc", "headings"] +draft = false ++++ + + +
+
+ +## Table of Contents + +- [Alpha 101](#alpha-101) +- 1 [Beta 102](#beta-102) + - 1.1 [Gamma 102.1](#gamma-102-dot-1) + - 1.1.1 [Delta 102.1.1](#delta-102-dot-1-dot-1) + - 1.1.2 [Epsilon 102.1.2](#epsilon-102-dot-1-dot-2) +- [Zeta 103](#zeta-103) + - [Links (no descriptions) to headings with section numbers](#links--no-descriptions--to-headings-with-section-numbers) +
+ + +## Alpha 101 {#alpha-101} + +- Link (with description) to a heading with section number: [Link to + _Beta 102_ heading](#beta-102) +- Link (no description) to a heading without section number: [Zeta 103](#zeta-103) + + +## 1 Beta 102 {#beta-102} + +- Link (with description) to a heading without section number: [Link to + _Alpha 101_ heading](#alpha-101) + + +### 1.1 Gamma 102.1 {#gamma-102-dot-1} + + +#### 1.1.1 Delta 102.1.1 {#delta-102-dot-1-dot-1} + + +#### 1.1.2 Epsilon 102.1.2 {#epsilon-102-dot-1-dot-2} + + +## Zeta 103 {#zeta-103} + + +### Links (no descriptions) to headings with section numbers {#links--no-descriptions--to-headings-with-section-numbers} + +- Section [1.1](#gamma-102-dot-1) +- Section [1.1.1](#delta-102-dot-1-dot-1) +- Section [1.1.2](#epsilon-102-dot-1-dot-2)