diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-03-10 18:52:06 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-03-10 18:52:06 +0100 |
commit | 4cb6abe3b7d724a310199ec47762d46086c2dec2 (patch) | |
tree | 8442596882b4a5df5c64e40c79909cee194657d1 | |
parent | 5b4215eb166554a2a358be457318c4dab5a5b55d (diff) | |
download | org-mode-4cb6abe3b7d724a310199ec47762d46086c2dec2.tar.gz |
ox-md: Fix internal links
* lisp/ox-md.el (org-md-headline): Add an anchor when a link is
referring to the headline.
(org-md--headline-referred-p): New function.
-rw-r--r-- | lisp/ox-md.el | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/lisp/ox-md.el b/lisp/ox-md.el index ad6ee35..c8ea1fa 100644 --- a/lisp/ox-md.el +++ b/lisp/ox-md.el @@ -217,11 +217,6 @@ a communication channel." (and (plist-get info :with-priority) (let ((char (org-element-property :priority headline))) (and char (format "[#%c] " char))))) - (anchor - (and (plist-get info :with-toc) - (format "<a id=\"%s\"></a>" - (or (org-element-property :CUSTOM_ID headline) - (org-export-get-reference headline info))))) ;; Headline text without tags. (heading (concat todo priority title)) (style (plist-get info :md-headline-style))) @@ -239,10 +234,29 @@ a communication channel." ".")))) (concat bullet (make-string (- 4 (length bullet)) ?\s) heading tags "\n\n" (and contents (replace-regexp-in-string "^" " " contents))))) - (t (concat (org-md--headline-title style level title anchor tags) contents)))))) - - -;; Headline Title + (t + (let ((anchor + (and (org-md--headline-referred-p headline info) + (format "<a id=\"%s\"></a>" + (or (org-element-property :CUSTOM_ID headline) + (org-export-get-reference headline info)))))) + (concat (org-md--headline-title style level title anchor tags) + contents))))))) + + +(defun org-md--headline-referred-p (headline info) + "Non-nil when HEADLINE is being referred to. +INFO is a plist used as a communication channel. Links and table +of contents can refer to headlines." + (or (plist-get info :with-toc) + (org-element-map (plist-get info :parse-tree) 'link + (lambda (link) + (eq headline + (pcase (org-element-property :type link) + ((or "custom-id" "id") (org-export-resolve-id-link link info)) + ("fuzzy" (org-export-resolve-fuzzy-link link info)) + (_ nil)))) + info t))) (defun org-md--headline-title (style level title &optional anchor tags) "Generate a headline title in the preferred Markdown headline style. |