diff --git a/ox-hugo.el b/ox-hugo.el
index 00bde34..2cb0d05 100644
--- a/ox-hugo.el
+++ b/ox-hugo.el
@@ -1997,8 +1997,10 @@ and rewrite link paths to make blogging more seamless."
(format "<%s>" path))))
(`headline ;Links of type [[* Some heading]]
(let ((title (org-hugo--sanitize-title
- info (org-element-property :title destination))))
- ;; (message "[ox-hugo-link DBG] headline title: %s" title)
+ info (org-element-property :title destination) 'md)))
+ ;; (message "[ox-hugo-link DBG] headline title pre sanitize: %s"
+ ;; (org-export-data (org-element-property :title destination) info))
+ ;; (message "[ox-hugo-link DBG] headline title post sanitize: %s" title)
(format
"[%s](#%s)"
;; Description
@@ -2951,7 +2953,7 @@ to ((name . \"foo\") (weight . 80))."
(push cell valid-menu-alist))))
valid-menu-alist))
-(defun org-hugo--sanitize-title (info &optional title)
+(defun org-hugo--sanitize-title (info &optional title backend)
"Return sanitized version of an Org headline TITLE.
INFO is a plist used as a communication channel.
@@ -2966,22 +2968,26 @@ If TITLE is non-nil, ignore the value of
`org-export-with-title'. When non-nil, TITLE is the object
returned by `org-element-property'.
-The title string is returned in a markup-free \"raw\" form."
+If BACKEND is nil, return the TITLE without any markup
+characters, else export it using the BACKEND."
(unless title
(when (plist-get info :with-title)
(setq title (plist-get info :title))))
- ;; "Raw" backend that returns emphasis elements without any markup
- ;; characters -- http://lists.gnu.org/r/emacs-orgmode/2017-12/msg00490.html
- (let* ((raw-backend (let ((get-raw (lambda (object contents _)
+ (let* ((backend (or backend
+ ;; "Raw" backend that returns emphasis elements
+ ;; without any markup characters --
+ ;; http://lists.gnu.org/r/emacs-orgmode/2017-12/msg00490.html
+ (let ((get-raw (lambda (object contents _)
(or contents
(org-element-property :value object)))))
(org-export-create-backend
:parent 'ascii
:transcoders (mapcar (lambda (type)
(cons type get-raw))
- '(bold code italic strike-through underline verbatim)))))
- (title (org-export-data-with-backend title raw-backend info))
+ '(bold code italic strike-through
+ underline verbatim))))))
+ (title (org-export-data-with-backend title backend info))
;; Hugo does not render Markdown in the titles and so the
;; Blackfriday smartDashes conversion does not work there. So
;; do that here instead. Convert "---" to EM DASH, "--" to EN
@@ -3950,7 +3956,7 @@ links."
(equal 'headline destination-type))
(let ((headline-title
(org-hugo--sanitize-title
- info (org-element-property :title destination))))
+ info (org-element-property :title destination) 'ascii)))
;; (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))))))))
diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org
index 3bb831c..cb79680 100644
--- a/test/site/content-org/all-posts.org
+++ b/test/site/content-org/all-posts.org
@@ -2906,18 +2906,18 @@ Once that is evaluated, links like these will export fine i.e. no
: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]].
+- Link (no description) to a heading without section number: [[* Zeta 103
+ which has *some markup*]].
The space after that =*= in the link is optional.. so this also
- works: [[*Zeta 103]].
+ works: [[*Zeta 103 which has *some markup*]].
**** 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
+**** Zeta 103 which has *some markup*
:PROPERTIES:
:UNNUMBERED: t
:END:
diff --git a/test/site/content/posts/link-to-headings-by-name.md b/test/site/content/posts/link-to-headings-by-name.md
index c68b10f..913dd27 100644
--- a/test/site/content/posts/link-to-headings-by-name.md
+++ b/test/site/content/posts/link-to-headings-by-name.md
@@ -19,7 +19,7 @@ draft = false
- 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)
+- [Zeta 103 which has **some markup**](#zeta-103-which-has-some-markup)
- [Links (no descriptions) to headings with section numbers](#links--no-descriptions--to-headings-with-section-numbers)
@@ -30,10 +30,10 @@ draft = false
- 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).
+- Link (no description) to a heading without section number: [Zeta 103 which has **some markup**](#zeta-103-which-has-some-markup).
The space after that `*` in the link is optional.. so this also
- works: [Zeta 103](#zeta-103).
+ works: [Zeta 103 which has **some markup**](#zeta-103-which-has-some-markup).
## 1 Beta 102 {#beta-102}
@@ -51,7 +51,7 @@ draft = false
#### 1.1.2 Epsilon 102.1.2 {#epsilon-102-dot-1-dot-2}
-## Zeta 103 {#zeta-103}
+## Zeta 103 which has **some markup** {#zeta-103-which-has-some-markup}
### Links (no descriptions) to headings with section numbers {#links--no-descriptions--to-headings-with-section-numbers}
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 338dd97..aa2412d 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](#org5518ced)
+- [Link to target within the same post](#org7d2d8b5)
## Cross-post links {#cross-post-links}
@@ -49,7 +49,7 @@ resolved to the containing post.
- 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" >}})
+- 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" >}})
@@ -68,7 +68,7 @@ resolved to the containing post.
## Internal target {#internal-target}
-
+
## Link destination {#link-destination}
@@ -76,7 +76,7 @@ resolved to the containing post.
### External target {#external-target}
-
+
### External target with **bold** and _italic_ {#external-target-with-bold-and-italic}