ox-md.el 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. ;;; ox-md.el --- Markdown Back-End for Org Export Engine -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2012-2016 Free Software Foundation, Inc.
  3. ;; Author: Nicolas Goaziou <n.goaziou@gmail.com>
  4. ;; Keywords: org, wp, markdown
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;; This library implements a Markdown back-end (vanilla flavor) for
  18. ;; Org exporter, based on `html' back-end. See Org manual for more
  19. ;; information.
  20. ;;; Code:
  21. (require 'cl-lib)
  22. (require 'ox-html)
  23. (require 'ox-publish)
  24. ;;; User-Configurable Variables
  25. (defgroup org-export-md nil
  26. "Options specific to Markdown export back-end."
  27. :tag "Org Markdown"
  28. :group 'org-export
  29. :version "24.4"
  30. :package-version '(Org . "8.0"))
  31. (defcustom org-md-headline-style 'atx
  32. "Style used to format headlines.
  33. This variable can be set to either `atx' or `setext'."
  34. :group 'org-export-md
  35. :type '(choice
  36. (const :tag "Use \"atx\" style" atx)
  37. (const :tag "Use \"Setext\" style" setext)))
  38. ;;;; Footnotes
  39. (defcustom org-md-footnotes-section "%s%s"
  40. "Format string for the footnotes section.
  41. The first %s placeholder will be replaced with the localized Footnotes section
  42. heading, the second with the contents of the Footnotes section."
  43. :group 'org-export-md
  44. :type 'string
  45. :version "25.2"
  46. :package-version '(Org . "9.0"))
  47. (defcustom org-md-footnote-format "<sup>%s</sup>"
  48. "Format string for the footnote reference.
  49. The %s will be replaced by the footnote reference itself."
  50. :group 'org-export-md
  51. :type 'string
  52. :version "25.2"
  53. :package-version '(Org . "9.0"))
  54. ;;; Define Back-End
  55. (org-export-define-derived-backend 'md 'html
  56. :filters-alist '((:filter-parse-tree . org-md-separate-elements))
  57. :menu-entry
  58. '(?m "Export to Markdown"
  59. ((?M "To temporary buffer"
  60. (lambda (a s v b) (org-md-export-as-markdown a s v)))
  61. (?m "To file" (lambda (a s v b) (org-md-export-to-markdown a s v)))
  62. (?o "To file and open"
  63. (lambda (a s v b)
  64. (if a (org-md-export-to-markdown t s v)
  65. (org-open-file (org-md-export-to-markdown nil s v)))))))
  66. :translate-alist '((bold . org-md-bold)
  67. (code . org-md-verbatim)
  68. (example-block . org-md-example-block)
  69. (export-block . org-md-export-block)
  70. (fixed-width . org-md-example-block)
  71. (headline . org-md-headline)
  72. (horizontal-rule . org-md-horizontal-rule)
  73. (inline-src-block . org-md-verbatim)
  74. (inner-template . org-md-inner-template)
  75. (italic . org-md-italic)
  76. (item . org-md-item)
  77. (keyword . org-md-keyword)
  78. (line-break . org-md-line-break)
  79. (link . org-md-link)
  80. (node-property . org-md-node-property)
  81. (paragraph . org-md-paragraph)
  82. (plain-list . org-md-plain-list)
  83. (plain-text . org-md-plain-text)
  84. (property-drawer . org-md-property-drawer)
  85. (quote-block . org-md-quote-block)
  86. (section . org-md-section)
  87. (src-block . org-md-example-block)
  88. (template . org-md-template)
  89. (verbatim . org-md-verbatim))
  90. :options-alist
  91. '((:md-footnote-format nil nil org-md-footnote-format)
  92. (:md-footnotes-section nil nil org-md-footnotes-section)
  93. (:md-headline-style nil nil org-md-headline-style)))
  94. ;;; Filters
  95. (defun org-md-separate-elements (tree _backend info)
  96. "Fix blank lines between elements.
  97. TREE is the parse tree being exported. BACKEND is the export
  98. back-end used. INFO is a plist used as a communication channel.
  99. Enforce a blank line between elements. There are two exceptions
  100. to this rule:
  101. 1. Preserve blank lines between sibling items in a plain list,
  102. 2. In an item, remove any blank line before the very first
  103. paragraph and the next sub-list when the latter ends the
  104. current item.
  105. Assume BACKEND is `md'."
  106. (org-element-map tree (remq 'item org-element-all-elements)
  107. (lambda (e)
  108. (org-element-put-property
  109. e :post-blank
  110. (if (and (eq (org-element-type e) 'paragraph)
  111. (eq (org-element-type (org-element-property :parent e)) 'item)
  112. (org-export-first-sibling-p e info)
  113. (let ((next (org-export-get-next-element e info)))
  114. (and (eq (org-element-type next) 'plain-list)
  115. (not (org-export-get-next-element next info)))))
  116. 0
  117. 1))))
  118. ;; Return updated tree.
  119. tree)
  120. ;;; Transcode Functions
  121. ;;;; Bold
  122. (defun org-md-bold (_bold contents _info)
  123. "Transcode BOLD object into Markdown format.
  124. CONTENTS is the text within bold markup. INFO is a plist used as
  125. a communication channel."
  126. (format "**%s**" contents))
  127. ;;;; Code and Verbatim
  128. (defun org-md-verbatim (verbatim _contents _info)
  129. "Transcode VERBATIM object into Markdown format.
  130. CONTENTS is nil. INFO is a plist used as a communication
  131. channel."
  132. (let ((value (org-element-property :value verbatim)))
  133. (format (cond ((not (string-match "`" value)) "`%s`")
  134. ((or (string-prefix-p "`" value)
  135. (string-suffix-p "`" value))
  136. "`` %s ``")
  137. (t "``%s``"))
  138. value)))
  139. ;;;; Example Block, Src Block and export Block
  140. (defun org-md-example-block (example-block _contents info)
  141. "Transcode EXAMPLE-BLOCK element into Markdown format.
  142. CONTENTS is nil. INFO is a plist used as a communication
  143. channel."
  144. (replace-regexp-in-string
  145. "^" " "
  146. (org-remove-indentation
  147. (org-export-format-code-default example-block info))))
  148. (defun org-md-export-block (export-block contents info)
  149. "Transcode a EXPORT-BLOCK element from Org to Markdown.
  150. CONTENTS is nil. INFO is a plist holding contextual information."
  151. (if (member (org-element-property :type export-block) '("MARKDOWN" "MD"))
  152. (org-remove-indentation (org-element-property :value export-block))
  153. ;; Also include HTML export blocks.
  154. (org-export-with-backend 'html export-block contents info)))
  155. ;;;; Headline
  156. (defun org-md-headline (headline contents info)
  157. "Transcode HEADLINE element into Markdown format.
  158. CONTENTS is the headline contents. INFO is a plist used as
  159. a communication channel."
  160. (unless (org-element-property :footnote-section-p headline)
  161. (let* ((level (org-export-get-relative-level headline info))
  162. (title (org-export-data (org-element-property :title headline) info))
  163. (todo (and (plist-get info :with-todo-keywords)
  164. (let ((todo (org-element-property :todo-keyword
  165. headline)))
  166. (and todo (concat (org-export-data todo info) " ")))))
  167. (tags (and (plist-get info :with-tags)
  168. (let ((tag-list (org-export-get-tags headline info)))
  169. (and tag-list
  170. (format " :%s:"
  171. (mapconcat 'identity tag-list ":"))))))
  172. (priority
  173. (and (plist-get info :with-priority)
  174. (let ((char (org-element-property :priority headline)))
  175. (and char (format "[#%c] " char)))))
  176. (anchor
  177. (and (plist-get info :with-toc)
  178. (format "<a id=\"%s\"></a>"
  179. (or (org-element-property :CUSTOM_ID headline)
  180. (org-export-get-reference headline info)))))
  181. ;; Headline text without tags.
  182. (heading (concat todo priority title))
  183. (style (plist-get info :md-headline-style)))
  184. (cond
  185. ;; Cannot create a headline. Fall-back to a list.
  186. ((or (org-export-low-level-p headline info)
  187. (not (memq style '(atx setext)))
  188. (and (eq style 'atx) (> level 6))
  189. (and (eq style 'setext) (> level 2)))
  190. (let ((bullet
  191. (if (not (org-export-numbered-headline-p headline info)) "-"
  192. (concat (number-to-string
  193. (car (last (org-export-get-headline-number
  194. headline info))))
  195. "."))))
  196. (concat bullet (make-string (- 4 (length bullet)) ?\s) heading tags "\n\n"
  197. (and contents (replace-regexp-in-string "^" " " contents)))))
  198. (t (concat (org-md--headline-title style level title anchor tags) contents))))))
  199. ;; Headline Title
  200. (defun org-md--headline-title (style level title &optional anchor tags)
  201. "Generate a headline title in the preferred Markdown headline style.
  202. STYLE is the preferred style (`atx' or `setext'). LEVEL is the
  203. header level. TITLE is the headline title. ANCHOR is the HTML
  204. anchor tag for the section as a string. TAGS are the tags set on
  205. the section."
  206. (let ((anchor-lines (and anchor (concat anchor "\n\n"))))
  207. ;; Use "Setext" style
  208. (if (and (eq style 'setext) (< level 3))
  209. (let* ((underline-char (if (= level 1) ?= ?-))
  210. (underline (concat (make-string (length title) underline-char)
  211. "\n")))
  212. (concat "\n" anchor-lines title tags "\n" underline "\n"))
  213. ;; Use "Atx" style
  214. (let ((level-mark (make-string level ?#)))
  215. (concat "\n" anchor-lines level-mark " " title tags "\n\n")))))
  216. ;;;; Horizontal Rule
  217. (defun org-md-horizontal-rule (_horizontal-rule _contents _info)
  218. "Transcode HORIZONTAL-RULE element into Markdown format.
  219. CONTENTS is the horizontal rule contents. INFO is a plist used
  220. as a communication channel."
  221. "---")
  222. ;;;; Italic
  223. (defun org-md-italic (_italic contents _info)
  224. "Transcode ITALIC object into Markdown format.
  225. CONTENTS is the text within italic markup. INFO is a plist used
  226. as a communication channel."
  227. (format "*%s*" contents))
  228. ;;;; Item
  229. (defun org-md-item (item contents info)
  230. "Transcode ITEM element into Markdown format.
  231. CONTENTS is the item contents. INFO is a plist used as
  232. a communication channel."
  233. (let* ((type (org-element-property :type (org-export-get-parent item)))
  234. (struct (org-element-property :structure item))
  235. (bullet (if (not (eq type 'ordered)) "-"
  236. (concat (number-to-string
  237. (car (last (org-list-get-item-number
  238. (org-element-property :begin item)
  239. struct
  240. (org-list-prevs-alist struct)
  241. (org-list-parents-alist struct)))))
  242. "."))))
  243. (concat bullet
  244. (make-string (- 4 (length bullet)) ? )
  245. (pcase (org-element-property :checkbox item)
  246. (`on "[X] ")
  247. (`trans "[-] ")
  248. (`off "[ ] "))
  249. (let ((tag (org-element-property :tag item)))
  250. (and tag (format "**%s:** "(org-export-data tag info))))
  251. (and contents
  252. (org-trim (replace-regexp-in-string "^" " " contents))))))
  253. ;;;; Keyword
  254. (defun org-md-keyword (keyword contents info)
  255. "Transcode a KEYWORD element into Markdown format.
  256. CONTENTS is nil. INFO is a plist used as a communication
  257. channel."
  258. (if (member (org-element-property :key keyword) '("MARKDOWN" "MD"))
  259. (org-element-property :value keyword)
  260. (org-export-with-backend 'html keyword contents info)))
  261. ;;;; Line Break
  262. (defun org-md-line-break (_line-break _contents _info)
  263. "Transcode LINE-BREAK object into Markdown format.
  264. CONTENTS is nil. INFO is a plist used as a communication
  265. channel."
  266. " \n")
  267. ;;;; Link
  268. (defun org-md-link (link contents info)
  269. "Transcode LINE-BREAK object into Markdown format.
  270. CONTENTS is the link's description. INFO is a plist used as
  271. a communication channel."
  272. (let ((link-org-files-as-md
  273. (lambda (raw-path)
  274. ;; Treat links to `file.org' as links to `file.md'.
  275. (if (string= ".org" (downcase (file-name-extension raw-path ".")))
  276. (concat (file-name-sans-extension raw-path) ".md")
  277. raw-path)))
  278. (type (org-element-property :type link)))
  279. (cond
  280. ;; Link type is handled by a special function.
  281. ((org-export-custom-protocol-maybe link contents 'md))
  282. ((member type '("custom-id" "id" "fuzzy"))
  283. (let ((destination (if (string= type "fuzzy")
  284. (org-export-resolve-fuzzy-link link info)
  285. (org-export-resolve-id-link link info))))
  286. (pcase (org-element-type destination)
  287. (`plain-text ; External file.
  288. (let ((path (funcall link-org-files-as-md destination)))
  289. (if (not contents) (format "<%s>" path)
  290. (format "[%s](%s)" contents path))))
  291. (`headline
  292. (format
  293. "[%s](#%s)"
  294. ;; Description.
  295. (cond ((org-string-nw-p contents))
  296. ((org-export-numbered-headline-p destination info)
  297. (mapconcat #'number-to-string
  298. (org-export-get-headline-number destination info)
  299. "."))
  300. (t (org-export-data (org-element-property :title destination)
  301. info)))
  302. ;; Reference.
  303. (or (org-element-property :CUSTOM_ID destination)
  304. (org-export-get-reference destination info))))
  305. (_
  306. (let ((description
  307. (or (org-string-nw-p contents)
  308. (let ((number (org-export-get-ordinal destination info)))
  309. (cond
  310. ((not number) nil)
  311. ((atom number) (number-to-string number))
  312. (t (mapconcat #'number-to-string number ".")))))))
  313. (when description
  314. (format "[%s](#%s)"
  315. description
  316. (org-export-get-reference destination info))))))))
  317. ((org-export-inline-image-p link org-html-inline-image-rules)
  318. (let ((path (let ((raw-path (org-element-property :path link)))
  319. (if (not (file-name-absolute-p raw-path)) raw-path
  320. (expand-file-name raw-path))))
  321. (caption (org-export-data
  322. (org-export-get-caption
  323. (org-export-get-parent-element link)) info)))
  324. (format "![img](%s)"
  325. (if (not (org-string-nw-p caption)) path
  326. (format "%s \"%s\"" path caption)))))
  327. ((string= type "coderef")
  328. (let ((ref (org-element-property :path link)))
  329. (format (org-export-get-coderef-format ref contents)
  330. (org-export-resolve-coderef ref info))))
  331. ((equal type "radio") contents)
  332. (t (let* ((raw-path (org-element-property :path link))
  333. (path
  334. (cond
  335. ((member type '("http" "https" "ftp"))
  336. (concat type ":" raw-path))
  337. ((string= type "file")
  338. (org-export-file-uri (funcall link-org-files-as-md raw-path)))
  339. (t raw-path))))
  340. (if (not contents) (format "<%s>" path)
  341. (format "[%s](%s)" contents path)))))))
  342. ;;;; Node Property
  343. (defun org-md-node-property (node-property _contents _info)
  344. "Transcode a NODE-PROPERTY element into Markdown syntax.
  345. CONTENTS is nil. INFO is a plist holding contextual
  346. information."
  347. (format "%s:%s"
  348. (org-element-property :key node-property)
  349. (let ((value (org-element-property :value node-property)))
  350. (if value (concat " " value) ""))))
  351. ;;;; Paragraph
  352. (defun org-md-paragraph (paragraph contents _info)
  353. "Transcode PARAGRAPH element into Markdown format.
  354. CONTENTS is the paragraph contents. INFO is a plist used as
  355. a communication channel."
  356. (let ((first-object (car (org-element-contents paragraph))))
  357. ;; If paragraph starts with a #, protect it.
  358. (if (and (stringp first-object) (string-prefix-p "#" first-object))
  359. (concat "\\" contents)
  360. contents)))
  361. ;;;; Plain List
  362. (defun org-md-plain-list (_plain-list contents _info)
  363. "Transcode PLAIN-LIST element into Markdown format.
  364. CONTENTS is the plain-list contents. INFO is a plist used as
  365. a communication channel."
  366. contents)
  367. ;;;; Plain Text
  368. (defun org-md-plain-text (text info)
  369. "Transcode a TEXT string into Markdown format.
  370. TEXT is the string to transcode. INFO is a plist holding
  371. contextual information."
  372. (when (plist-get info :with-smart-quotes)
  373. (setq text (org-export-activate-smart-quotes text :html info)))
  374. ;; Protect ambiguous #. This will protect # at the beginning of
  375. ;; a line, but not at the beginning of a paragraph. See
  376. ;; `org-md-paragraph'.
  377. (setq text (replace-regexp-in-string "\n#" "\n\\\\#" text))
  378. ;; Protect ambiguous !
  379. (setq text (replace-regexp-in-string "\\(!\\)\\[" "\\\\!" text nil nil 1))
  380. ;; Protect `, *, _ and \
  381. (setq text (replace-regexp-in-string "[`*_\\]" "\\\\\\&" text))
  382. ;; Handle special strings, if required.
  383. (when (plist-get info :with-special-strings)
  384. (setq text (org-html-convert-special-strings text)))
  385. ;; Handle break preservation, if required.
  386. (when (plist-get info :preserve-breaks)
  387. (setq text (replace-regexp-in-string "[ \t]*\n" " \n" text)))
  388. ;; Return value.
  389. text)
  390. ;;;; Property Drawer
  391. (defun org-md-property-drawer (_property-drawer contents _info)
  392. "Transcode a PROPERTY-DRAWER element into Markdown format.
  393. CONTENTS holds the contents of the drawer. INFO is a plist
  394. holding contextual information."
  395. (and (org-string-nw-p contents)
  396. (replace-regexp-in-string "^" " " contents)))
  397. ;;;; Quote Block
  398. (defun org-md-quote-block (_quote-block contents _info)
  399. "Transcode QUOTE-BLOCK element into Markdown format.
  400. CONTENTS is the quote-block contents. INFO is a plist used as
  401. a communication channel."
  402. (replace-regexp-in-string
  403. "^" "> "
  404. (replace-regexp-in-string "\n\\'" "" contents)))
  405. ;;;; Section
  406. (defun org-md-section (_section contents _info)
  407. "Transcode SECTION element into Markdown format.
  408. CONTENTS is the section contents. INFO is a plist used as
  409. a communication channel."
  410. contents)
  411. ;;;; Template
  412. (defun org-md--footnote-formatted (footnote info)
  413. "Formats a single footnote entry FOOTNOTE.
  414. FOOTNOTE is a cons cell of the form (number . definition).
  415. INFO is a plist with contextual information."
  416. (let* ((fn-num (car footnote))
  417. (fn-text (cdr footnote))
  418. (fn-format (plist-get info :md-footnote-format))
  419. (fn-anchor (format "fn.%d" fn-num))
  420. (fn-href (format " href=\"#fnr.%d\"" fn-num))
  421. (fn-link-to-ref (org-html--anchor fn-anchor fn-num fn-href info)))
  422. (concat (format fn-format fn-link-to-ref) " " fn-text "\n")))
  423. (defun org-md--footnote-section (info)
  424. "Format the footnote section.
  425. INFO is a plist used as a communication channel."
  426. (let* ((fn-alist (org-export-collect-footnote-definitions info))
  427. (fn-alist (cl-loop for (n _type raw) in fn-alist collect
  428. (cons n (org-trim (org-export-data raw info)))))
  429. (headline-style (plist-get info :md-headline-style))
  430. (section-title (org-html--translate "Footnotes" info)))
  431. (when fn-alist
  432. (format (plist-get info :md-footnotes-section)
  433. (org-md--headline-title headline-style 1 section-title)
  434. (mapconcat (lambda (fn) (org-md--footnote-formatted fn info))
  435. fn-alist
  436. "\n")))))
  437. (defun org-md-inner-template (contents info)
  438. "Return body of document after converting it to Markdown syntax.
  439. CONTENTS is the transcoded contents string. INFO is a plist
  440. holding export options."
  441. ;; Make sure CONTENTS is separated from table of contents and
  442. ;; footnotes with at least a blank line.
  443. (concat
  444. ;; Table of contents.
  445. (let ((depth (plist-get info :with-toc)))
  446. (when depth (org-html-toc depth info)))
  447. ;; Document contents.
  448. contents
  449. "\n"
  450. ;; Footnotes section.
  451. (org-md--footnote-section info)))
  452. (defun org-md-template (contents _info)
  453. "Return complete document string after Markdown conversion.
  454. CONTENTS is the transcoded contents string. INFO is a plist used
  455. as a communication channel."
  456. contents)
  457. ;;; Interactive function
  458. ;;;###autoload
  459. (defun org-md-export-as-markdown (&optional async subtreep visible-only)
  460. "Export current buffer to a Markdown buffer.
  461. If narrowing is active in the current buffer, only export its
  462. narrowed part.
  463. If a region is active, export that region.
  464. A non-nil optional argument ASYNC means the process should happen
  465. asynchronously. The resulting buffer should be accessible
  466. through the `org-export-stack' interface.
  467. When optional argument SUBTREEP is non-nil, export the sub-tree
  468. at point, extracting information from the headline properties
  469. first.
  470. When optional argument VISIBLE-ONLY is non-nil, don't export
  471. contents of hidden elements.
  472. Export is done in a buffer named \"*Org MD Export*\", which will
  473. be displayed when `org-export-show-temporary-export-buffer' is
  474. non-nil."
  475. (interactive)
  476. (org-export-to-buffer 'md "*Org MD Export*"
  477. async subtreep visible-only nil nil (lambda () (text-mode))))
  478. ;;;###autoload
  479. (defun org-md-convert-region-to-md ()
  480. "Assume the current region has Org syntax, and convert it to Markdown.
  481. This can be used in any buffer. For example, you can write an
  482. itemized list in Org syntax in a Markdown buffer and use
  483. this command to convert it."
  484. (interactive)
  485. (org-export-replace-region-by 'md))
  486. ;;;###autoload
  487. (defun org-md-export-to-markdown (&optional async subtreep visible-only)
  488. "Export current buffer to a Markdown file.
  489. If narrowing is active in the current buffer, only export its
  490. narrowed part.
  491. If a region is active, export that region.
  492. A non-nil optional argument ASYNC means the process should happen
  493. asynchronously. The resulting file should be accessible through
  494. the `org-export-stack' interface.
  495. When optional argument SUBTREEP is non-nil, export the sub-tree
  496. at point, extracting information from the headline properties
  497. first.
  498. When optional argument VISIBLE-ONLY is non-nil, don't export
  499. contents of hidden elements.
  500. Return output file's name."
  501. (interactive)
  502. (let ((outfile (org-export-output-file-name ".md" subtreep)))
  503. (org-export-to-file 'md outfile async subtreep visible-only)))
  504. ;;;###autoload
  505. (defun org-md-publish-to-md (plist filename pub-dir)
  506. "Publish an org file to Markdown.
  507. FILENAME is the filename of the Org file to be published. PLIST
  508. is the property list for the given project. PUB-DIR is the
  509. publishing directory.
  510. Return output file name."
  511. (org-publish-org-to 'md filename ".md" plist pub-dir))
  512. (provide 'ox-md)
  513. ;; Local variables:
  514. ;; generated-autoload-file: "org-loaddefs.el"
  515. ;; End:
  516. ;;; ox-md.el ends here