Derive Org heading based internal link refs using org-hugo-slug

master
Kaushal Modi 8 years ago
parent 1213df6c6d
commit a89fb81d03
  1. 31
      ox-hugo.el
  2. 27
      test/site/content-org/all-posts.org
  3. 56
      test/site/content/posts/link-to-headings-by-name.md

@ -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)

@ -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

@ -0,0 +1,56 @@
+++
title = "Link to headings by name"
tags = ["links", "internal-links", "toc", "headings"]
draft = false
+++
<style>
.ox-hugo-toc ul {
list-style: none;
}
</style>
<div class="ox-hugo-toc toc">
<div></div>
## Table of Contents
- [Alpha 101](#alpha-101)
- <span class="section-num">1</span> [Beta 102](#beta-102)
- <span class="section-num">1.1</span> [Gamma 102.1](#gamma-102-dot-1)
- <span class="section-num">1.1.1</span> [Delta 102.1.1](#delta-102-dot-1-dot-1)
- <span class="section-num">1.1.2</span> [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)
</div>
## 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)
## <span class="section-num">1</span> Beta 102 {#beta-102}
- Link (with description) to a heading without section number: [Link to
_Alpha 101_ heading](#alpha-101)
### <span class="section-num">1.1</span> Gamma 102.1 {#gamma-102-dot-1}
#### <span class="section-num">1.1.1</span> Delta 102.1.1 {#delta-102-dot-1-dot-1}
#### <span class="section-num">1.1.2</span> 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)
Loading…
Cancel
Save