Retain markup in titles when deriving them for internal/x-post links

master
Kaushal Modi 7 years ago
parent ed5df37e18
commit 6ab67efc56
  1. 26
      ox-hugo.el
  2. 8
      test/site/content-org/all-posts.org
  3. 8
      test/site/content/posts/link-to-headings-by-name.md
  4. 8
      test/site/content/posts/links-outside-the-same-post.md

@ -1997,8 +1997,10 @@ and rewrite link paths to make blogging more seamless."
(format "<%s>" path)))) (format "<%s>" path))))
(`headline ;Links of type [[* Some heading]] (`headline ;Links of type [[* Some heading]]
(let ((title (org-hugo--sanitize-title (let ((title (org-hugo--sanitize-title
info (org-element-property :title destination)))) info (org-element-property :title destination) 'md)))
;; (message "[ox-hugo-link DBG] headline title: %s" title) ;; (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 (format
"[%s](#%s)" "[%s](#%s)"
;; Description ;; Description
@ -2951,7 +2953,7 @@ to ((name . \"foo\") (weight . 80))."
(push cell valid-menu-alist)))) (push cell valid-menu-alist))))
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. "Return sanitized version of an Org headline TITLE.
INFO is a plist used as a communication channel. 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 `org-export-with-title'. When non-nil, TITLE is the object
returned by `org-element-property'. 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 (unless title
(when (plist-get info :with-title) (when (plist-get info :with-title)
(setq title (plist-get info :title)))) (setq title (plist-get info :title))))
;; "Raw" backend that returns emphasis elements without any markup (let* ((backend (or backend
;; characters -- http://lists.gnu.org/r/emacs-orgmode/2017-12/msg00490.html ;; "Raw" backend that returns emphasis elements
(let* ((raw-backend (let ((get-raw (lambda (object contents _) ;; without any markup characters --
;; http://lists.gnu.org/r/emacs-orgmode/2017-12/msg00490.html
(let ((get-raw (lambda (object contents _)
(or contents (or contents
(org-element-property :value object))))) (org-element-property :value object)))))
(org-export-create-backend (org-export-create-backend
:parent 'ascii :parent 'ascii
:transcoders (mapcar (lambda (type) :transcoders (mapcar (lambda (type)
(cons type get-raw)) (cons type get-raw))
'(bold code italic strike-through underline verbatim))))) '(bold code italic strike-through
(title (org-export-data-with-backend title raw-backend info)) underline verbatim))))))
(title (org-export-data-with-backend title backend info))
;; Hugo does not render Markdown in the titles and so the ;; Hugo does not render Markdown in the titles and so the
;; Blackfriday smartDashes conversion does not work there. So ;; Blackfriday smartDashes conversion does not work there. So
;; do that here instead. Convert "---" to EM DASH, "--" to EN ;; do that here instead. Convert "---" to EM DASH, "--" to EN
@ -3950,7 +3956,7 @@ links."
(equal 'headline destination-type)) (equal 'headline destination-type))
(let ((headline-title (let ((headline-title
(org-hugo--sanitize-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) ;; (message "[ox-hugo pre process DBG] destination heading: %s" headline-title)
(org-element-set-contents link-copy headline-title))) (org-element-set-contents link-copy headline-title)))
(org-element-set-element link link-copy)))))))) (org-element-set-element link link-copy))))))))

@ -2906,18 +2906,18 @@ Once that is evaluated, links like these will export fine i.e. no
:END: :END:
- Link (with description) to a heading with section number: [[* Beta 102][Link to - Link (with description) to a heading with section number: [[* Beta 102][Link to
/Beta 102/ heading]] /Beta 102/ heading]]
- Link (no description) to a heading without section number: [[* Zeta - Link (no description) to a heading without section number: [[* Zeta 103
103]]. which has *some markup*]].
The space after that =*= in the link is optional.. so this also The space after that =*= in the link is optional.. so this also
works: [[*Zeta 103]]. works: [[*Zeta 103 which has *some markup*]].
**** Beta 102 **** Beta 102
- Link (with description) to a heading without section number: [[* Alpha 101][Link to - Link (with description) to a heading without section number: [[* Alpha 101][Link to
/Alpha 101/ heading]] /Alpha 101/ heading]]
***** Gamma 102.1 ***** Gamma 102.1
****** Delta 102.1.1 ****** Delta 102.1.1
****** Epsilon 102.1.2 ****** Epsilon 102.1.2
**** Zeta 103 **** Zeta 103 which has *some markup*
:PROPERTIES: :PROPERTIES:
:UNNUMBERED: t :UNNUMBERED: t
:END: :END:

@ -19,7 +19,7 @@ draft = false
- <span class="section-num">1.1</span> [Gamma 102.1](#gamma-102-dot-1) - <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.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) - <span class="section-num">1.1.2</span> [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) - [Links (no descriptions) to headings with section numbers](#links--no-descriptions--to-headings-with-section-numbers)
</div> </div>
@ -30,10 +30,10 @@ draft = false
- Link (with description) to a heading with section number: [Link to - Link (with description) to a heading with section number: [Link to
_Beta 102_ heading](#beta-102) _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 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).
## <span class="section-num">1</span> Beta 102 {#beta-102} ## <span class="section-num">1</span> Beta 102 {#beta-102}
@ -51,7 +51,7 @@ draft = false
#### <span class="section-num">1.1.2</span> Epsilon 102.1.2 {#epsilon-102-dot-1-dot-2} #### <span class="section-num">1.1.2</span> 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} ### Links (no descriptions) to headings with section numbers {#links--no-descriptions--to-headings-with-section-numbers}

@ -30,7 +30,7 @@ init file.
- [Link to CUSTOM\_ID within the same post](#internal-target) - [Link to CUSTOM\_ID within the same post](#internal-target)
- [Link to 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 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} ## 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 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 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" >}}) - 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 CUSTOM\_ID: [Link destination]({{< relref "link-destination" >}})
- Link to subtree by 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" >}}) - Link to subtree by headline: [Link destination]({{< relref "link-destination" >}})
@ -68,7 +68,7 @@ resolved to the containing post.
## Internal target {#internal-target} ## Internal target {#internal-target}
<a id="org5518ced"></a> <a id="org7d2d8b5"></a>
## Link destination {#link-destination} ## Link destination {#link-destination}
@ -76,7 +76,7 @@ resolved to the containing post.
### External target {#external-target} ### External target {#external-target}
<a id="org1b9b4fd"></a> <a id="orga9009ef"></a>
### External target with **bold** and _italic_ {#external-target-with-bold-and-italic} ### External target with **bold** and _italic_ {#external-target-with-bold-and-italic}

Loading…
Cancel
Save