diff options
Diffstat (limited to 'lisp/ox-md.el')
-rw-r--r-- | lisp/ox-md.el | 96 |
1 files changed, 52 insertions, 44 deletions
diff --git a/lisp/ox-md.el b/lisp/ox-md.el index e4291e5..602c149 100644 --- a/lisp/ox-md.el +++ b/lisp/ox-md.el @@ -107,7 +107,8 @@ to this rule: 1. Preserve blank lines between sibling items in a plain list, 2. In an item, remove any blank line before the very first - paragraph and the next sub-list. + paragraph and the next sub-list when the latter ends the + current item. Assume BACKEND is `md'." (org-element-map tree (remq 'item org-element-all-elements) @@ -116,9 +117,10 @@ Assume BACKEND is `md'." e :post-blank (if (and (eq (org-element-type e) 'paragraph) (eq (org-element-type (org-element-property :parent e)) 'item) - (eq (org-element-type (org-export-get-next-element e info)) - 'plain-list) - (not (org-export-get-previous-element e info))) + (org-export-first-sibling-p e info) + (let ((next (org-export-get-next-element e info))) + (and (eq (org-element-type next) 'plain-list) + (not (org-export-get-next-element next info))))) 0 1)))) ;; Return updated tree. @@ -196,8 +198,9 @@ a communication channel." (and char (format "[#%c] " char))))) (anchor (and (plist-get info :with-toc) - (org-html--anchor - (org-export-get-reference headline info) nil nil info))) + (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))) @@ -213,7 +216,7 @@ a communication channel." (car (last (org-export-get-headline-number headline info)))) ".")))) - (concat bullet (make-string (- 4 (length bullet)) ? ) heading tags + (concat bullet (make-string (- 4 (length bullet)) ?\s) heading tags "\n\n" (and contents (replace-regexp-in-string "^" " " contents))))) @@ -224,7 +227,8 @@ a communication channel." "\n\n" contents)) ;; Use "atx" style. - (t (concat (make-string level ?#) " " heading tags anchor "\n\n" contents)))))) + (t (concat (make-string level ?#) " " heading tags anchor "\n\n" + contents)))))) ;;;; Horizontal Rule @@ -301,33 +305,50 @@ channel." CONTENTS is the link's description. INFO is a plist used as a communication channel." (let ((link-org-files-as-md - (function - (lambda (raw-path) - ;; Treat links to `file.org' as links to `file.md'. - (if (string= ".org" (downcase (file-name-extension raw-path "."))) - (concat (file-name-sans-extension raw-path) ".md") - raw-path)))) + (lambda (raw-path) + ;; Treat links to `file.org' as links to `file.md'. + (if (string= ".org" (downcase (file-name-extension raw-path "."))) + (concat (file-name-sans-extension raw-path) ".md") + raw-path))) (type (org-element-property :type link))) (cond ;; Link type is handled by a special function. ((org-export-custom-protocol-maybe link contents 'md)) - ((member type '("custom-id" "id")) - (let ((destination (org-export-resolve-id-link link info))) - (if (stringp destination) ; External file. - (let ((path (funcall link-org-files-as-md destination))) - (if (not contents) (format "<%s>" path) - (format "[%s](%s)" contents path))) - (concat - (and contents (concat contents " ")) - (format "(%s)" - (format (org-export-translate "See section %s" :html info) - (if (org-export-numbered-headline-p destination info) - (mapconcat #'number-to-string - (org-export-get-headline-number - destination info) - ".") - (org-export-data - (org-element-property :title destination) info)))))))) + ((member type '("custom-id" "id" "fuzzy")) + (let ((destination (if (string= type "fuzzy") + (org-export-resolve-fuzzy-link link info) + (org-export-resolve-id-link link info)))) + (case (org-element-type destination) + (plain-text ; External file. + (let ((path (funcall link-org-files-as-md destination))) + (if (not contents) (format "<%s>" path) + (format "[%s](%s)" contents 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)))) + (t + (let ((description + (or (org-string-nw-p contents) + (let ((number (org-export-get-ordinal destination info))) + (cond + ((not number) nil) + ((atom number) (number-to-string number)) + (t (mapconcat #'number-to-string number "."))))))) + (when description + (format "[%s](#%s)" + description + (org-export-get-reference destination info)))))))) ((org-export-inline-image-p link org-html-inline-image-rules) (let ((path (let ((raw-path (org-element-property :path link))) (if (not (file-name-absolute-p raw-path)) raw-path @@ -343,19 +364,6 @@ a communication channel." (format (org-export-get-coderef-format ref contents) (org-export-resolve-coderef ref info)))) ((equal type "radio") contents) - ((equal type "fuzzy") - (let ((destination (org-export-resolve-fuzzy-link link info))) - (if (org-string-nw-p contents) contents - (when destination - (let ((number (org-export-get-ordinal destination info))) - (if number - (if (atom number) (number-to-string number) - (mapconcat #'number-to-string number ".")) - ;; Unnumbered headline. - (and (eq 'headline (org-element-type destination)) - ;; BUG: shouldn't headlines have a form like [ref](name) in md? - (org-export-data - (org-element-property :title destination) info)))))))) (t (let* ((raw-path (org-element-property :path link)) (path (cond |