2013-01-27 22:11:34 +00:00
|
|
|
|
;;; ox-md.el --- Markdown Back-End for Org Export Engine
|
2012-07-25 21:04:36 +00:00
|
|
|
|
|
2013-01-01 15:04:24 +00:00
|
|
|
|
;; Copyright (C) 2012, 2013 Free Software Foundation, Inc.
|
2012-07-25 21:04:36 +00:00
|
|
|
|
|
|
|
|
|
;; Author: Nicolas Goaziou <n.goaziou@gmail.com>
|
|
|
|
|
;; Keywords: org, wp, tex
|
|
|
|
|
|
|
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; This library implements a Markdown back-end (vanilla flavour) for
|
2013-01-27 22:11:34 +00:00
|
|
|
|
;; Org exporter, based on `html' back-end.
|
2012-07-25 21:04:36 +00:00
|
|
|
|
;;
|
|
|
|
|
;; It provides two commands for export, depending on the desired
|
|
|
|
|
;; output: `org-md-export-as-markdown' (temporary buffer) and
|
|
|
|
|
;; `org-md-export-to-markdown' ("md" file).
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2013-02-09 17:25:57 +00:00
|
|
|
|
(eval-when-compile (require 'cl))
|
2013-01-27 22:11:34 +00:00
|
|
|
|
(require 'ox-html)
|
2012-07-25 21:04:36 +00:00
|
|
|
|
|
|
|
|
|
|
2012-07-27 20:52:01 +00:00
|
|
|
|
|
|
|
|
|
;;; User-Configurable Variables
|
|
|
|
|
|
|
|
|
|
(defgroup org-export-md nil
|
|
|
|
|
"Options specific to Markdown export back-end."
|
|
|
|
|
:tag "Org Markdown"
|
|
|
|
|
:group 'org-export
|
|
|
|
|
:version "24.2")
|
|
|
|
|
|
|
|
|
|
(defcustom org-md-headline-style 'atx
|
|
|
|
|
"Style used to format headlines.
|
2012-07-27 22:49:58 +00:00
|
|
|
|
This variable can be set to either `atx' or `setext'."
|
2012-07-27 20:52:01 +00:00
|
|
|
|
:group 'org-export-md
|
|
|
|
|
:type '(choice
|
|
|
|
|
(const :tag "Use \"atx\" style" atx)
|
|
|
|
|
(const :tag "Use \"Setext\" style" setext)))
|
|
|
|
|
|
|
|
|
|
|
2012-07-25 21:04:36 +00:00
|
|
|
|
|
|
|
|
|
;;; Define Back-End
|
|
|
|
|
|
2013-01-27 22:11:34 +00:00
|
|
|
|
(org-export-define-derived-backend md html
|
2012-07-25 21:04:36 +00:00
|
|
|
|
:export-block ("MD" "MARKDOWN")
|
|
|
|
|
:filters-alist ((:filter-parse-tree . org-md-separate-elements))
|
2012-09-09 11:08:52 +00:00
|
|
|
|
:menu-entry
|
|
|
|
|
(?m "Export to Markdown"
|
2012-10-02 20:44:04 +00:00
|
|
|
|
((?M "To temporary buffer"
|
2012-12-02 16:24:19 +00:00
|
|
|
|
(lambda (a s v b) (org-md-export-as-markdown a s v)))
|
|
|
|
|
(?m "To file" (lambda (a s v b) (org-md-export-to-markdown a s v)))
|
2012-09-09 11:08:52 +00:00
|
|
|
|
(?o "To file and open"
|
2012-12-02 16:24:19 +00:00
|
|
|
|
(lambda (a s v b)
|
|
|
|
|
(if a (org-md-export-to-markdown t s v)
|
|
|
|
|
(org-open-file (org-md-export-to-markdown nil s v)))))))
|
2012-07-25 21:04:36 +00:00
|
|
|
|
:translate-alist ((bold . org-md-bold)
|
|
|
|
|
(code . org-md-verbatim)
|
|
|
|
|
(example-block . org-md-example-block)
|
2013-01-28 17:47:43 +00:00
|
|
|
|
(fixed-width . org-md-example-block)
|
2012-07-25 21:04:36 +00:00
|
|
|
|
(footnote-definition . ignore)
|
|
|
|
|
(footnote-reference . ignore)
|
|
|
|
|
(headline . org-md-headline)
|
|
|
|
|
(horizontal-rule . org-md-horizontal-rule)
|
|
|
|
|
(inline-src-block . org-md-verbatim)
|
|
|
|
|
(italic . org-md-italic)
|
|
|
|
|
(item . org-md-item)
|
|
|
|
|
(line-break . org-md-line-break)
|
|
|
|
|
(link . org-md-link)
|
|
|
|
|
(paragraph . org-md-paragraph)
|
|
|
|
|
(plain-list . org-md-plain-list)
|
|
|
|
|
(plain-text . org-md-plain-text)
|
|
|
|
|
(quote-block . org-md-quote-block)
|
|
|
|
|
(quote-section . org-md-example-block)
|
|
|
|
|
(section . org-md-section)
|
|
|
|
|
(src-block . org-md-example-block)
|
|
|
|
|
(template . org-md-template)
|
|
|
|
|
(verbatim . org-md-verbatim)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Filters
|
|
|
|
|
|
|
|
|
|
(defun org-md-separate-elements (tree backend info)
|
|
|
|
|
"Make sure elements are separated by at least one blank line.
|
|
|
|
|
|
|
|
|
|
TREE is the parse tree being exported. BACKEND is the export
|
|
|
|
|
back-end used. INFO is a plist used as a communication channel.
|
|
|
|
|
|
|
|
|
|
Assume BACKEND is `md'."
|
2013-01-27 22:11:34 +00:00
|
|
|
|
(org-element-map tree org-element-all-elements
|
|
|
|
|
(lambda (elem)
|
|
|
|
|
(unless (eq (org-element-type elem) 'org-data)
|
|
|
|
|
(org-element-put-property
|
|
|
|
|
elem :post-blank
|
|
|
|
|
(let ((post-blank (org-element-property :post-blank elem)))
|
|
|
|
|
(if (not post-blank) 1 (max 1 post-blank)))))))
|
2012-07-25 21:04:36 +00:00
|
|
|
|
;; Return updated tree.
|
|
|
|
|
tree)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Transcode Functions
|
|
|
|
|
|
|
|
|
|
;;;; Bold
|
|
|
|
|
|
|
|
|
|
(defun org-md-bold (bold contents info)
|
|
|
|
|
"Transcode BOLD object into Markdown format.
|
|
|
|
|
CONTENTS is the text within bold markup. INFO is a plist used as
|
|
|
|
|
a communication channel."
|
|
|
|
|
(format "**%s**" contents))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Code and Verbatim
|
|
|
|
|
|
|
|
|
|
(defun org-md-verbatim (verbatim contents info)
|
|
|
|
|
"Transcode VERBATIM object into Markdown format.
|
|
|
|
|
CONTENTS is nil. INFO is a plist used as a communication
|
|
|
|
|
channel."
|
|
|
|
|
(let ((value (org-element-property :value verbatim)))
|
|
|
|
|
(format (cond ((not (string-match "`" value)) "`%s`")
|
|
|
|
|
((or (string-match "\\``" value)
|
|
|
|
|
(string-match "`\\'" value))
|
|
|
|
|
"`` %s ``")
|
|
|
|
|
(t "``%s``"))
|
|
|
|
|
value)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Example Block and Src Block
|
|
|
|
|
|
|
|
|
|
(defun org-md-example-block (example-block contents info)
|
|
|
|
|
"Transcode EXAMPLE-BLOCK element into Markdown format.
|
|
|
|
|
CONTENTS is nil. INFO is a plist used as a communication
|
|
|
|
|
channel."
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
"^" " "
|
|
|
|
|
(org-remove-indentation
|
|
|
|
|
(org-element-property :value example-block))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Headline
|
|
|
|
|
|
|
|
|
|
(defun org-md-headline (headline contents info)
|
|
|
|
|
"Transcode HEADLINE element into Markdown format.
|
|
|
|
|
CONTENTS is the headline contents. INFO is a plist used as
|
|
|
|
|
a communication channel."
|
|
|
|
|
(unless (org-element-property :footnote-section-p headline)
|
2012-07-27 20:52:01 +00:00
|
|
|
|
(let* ((level (org-export-get-relative-level headline info))
|
|
|
|
|
(title (org-export-data (org-element-property :title headline) info))
|
|
|
|
|
(todo (and (plist-get info :with-todo-keywords)
|
|
|
|
|
(let ((todo (org-element-property :todo-keyword
|
|
|
|
|
headline)))
|
2012-07-27 21:05:34 +00:00
|
|
|
|
(and todo (concat (org-export-data todo info) " ")))))
|
2012-07-27 20:52:01 +00:00
|
|
|
|
(tags (and (plist-get info :with-tags)
|
|
|
|
|
(let ((tag-list (org-export-get-tags headline info)))
|
|
|
|
|
(and tag-list
|
2012-07-27 21:05:34 +00:00
|
|
|
|
(format " :%s:"
|
2012-07-27 20:52:01 +00:00
|
|
|
|
(mapconcat 'identity tag-list ":"))))))
|
2012-07-27 21:05:34 +00:00
|
|
|
|
(priority
|
|
|
|
|
(and (plist-get info :with-priority)
|
|
|
|
|
(let ((char (org-element-property :priority headline)))
|
|
|
|
|
(and char (format "[#%c] " char)))))
|
|
|
|
|
;; Headline text without tags.
|
|
|
|
|
(heading (concat todo priority title)))
|
2012-07-27 20:52:01 +00:00
|
|
|
|
(cond
|
|
|
|
|
;; Cannot create an headline. Fall-back to a list.
|
|
|
|
|
((or (org-export-low-level-p headline info)
|
|
|
|
|
(not (memq org-md-headline-style '(atx setext)))
|
|
|
|
|
(and (eq org-md-headline-style 'atx) (> level 6))
|
|
|
|
|
(and (eq org-md-headline-style 'setext) (> level 2)))
|
|
|
|
|
(let ((bullet
|
|
|
|
|
(if (not (org-export-numbered-headline-p headline info)) "-"
|
|
|
|
|
(concat (number-to-string
|
|
|
|
|
(car (last (org-export-get-headline-number
|
|
|
|
|
headline info))))
|
|
|
|
|
"."))))
|
2012-07-27 21:05:34 +00:00
|
|
|
|
(concat bullet (make-string (- 4 (length bullet)) ? ) heading tags
|
|
|
|
|
"\n\n"
|
2012-07-27 20:52:01 +00:00
|
|
|
|
(and contents
|
|
|
|
|
(replace-regexp-in-string "^" " " contents)))))
|
|
|
|
|
;; Use "Setext" style.
|
|
|
|
|
((eq org-md-headline-style 'setext)
|
2012-07-27 21:05:34 +00:00
|
|
|
|
(concat heading tags "\n"
|
2012-07-27 20:52:01 +00:00
|
|
|
|
(make-string (length heading) (if (= level 1) ?= ?-))
|
|
|
|
|
"\n\n"
|
|
|
|
|
contents))
|
|
|
|
|
;; Use "atx" style.
|
2012-07-27 21:05:34 +00:00
|
|
|
|
(t (concat (make-string level ?#) " " heading tags "\n\n" contents))))))
|
2012-07-25 21:04:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Horizontal Rule
|
|
|
|
|
|
|
|
|
|
(defun org-md-horizontal-rule (horizontal-rule contents info)
|
|
|
|
|
"Transcode HORIZONTAL-RULE element into Markdown format.
|
|
|
|
|
CONTENTS is the horizontal rule contents. INFO is a plist used
|
|
|
|
|
as a communication channel."
|
|
|
|
|
"---")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Italic
|
|
|
|
|
|
|
|
|
|
(defun org-md-italic (italic contents info)
|
|
|
|
|
"Transcode ITALIC object into Markdown format.
|
|
|
|
|
CONTENTS is the text within italic markup. INFO is a plist used
|
|
|
|
|
as a communication channel."
|
|
|
|
|
(format "*%s*" contents))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Item
|
|
|
|
|
|
|
|
|
|
(defun org-md-item (item contents info)
|
|
|
|
|
"Transcode ITEM element into Markdown format.
|
|
|
|
|
CONTENTS is the item contents. INFO is a plist used as
|
|
|
|
|
a communication channel."
|
|
|
|
|
(let* ((type (org-element-property :type (org-export-get-parent item)))
|
|
|
|
|
(struct (org-element-property :structure item))
|
|
|
|
|
(bullet (if (not (eq type 'ordered)) "-"
|
|
|
|
|
(concat (number-to-string
|
|
|
|
|
(car (last (org-list-get-item-number
|
|
|
|
|
(org-element-property :begin item)
|
|
|
|
|
struct
|
|
|
|
|
(org-list-prevs-alist struct)
|
|
|
|
|
(org-list-parents-alist struct)))))
|
|
|
|
|
"."))))
|
|
|
|
|
(concat bullet
|
|
|
|
|
(make-string (- 4 (length bullet)) ? )
|
|
|
|
|
(case (org-element-property :checkbox item)
|
|
|
|
|
(on "[X] ")
|
|
|
|
|
(trans "[-] ")
|
|
|
|
|
(off "[ ] "))
|
|
|
|
|
(let ((tag (org-element-property :tag item)))
|
|
|
|
|
(and tag (format "**%s:** "(org-export-data tag info))))
|
|
|
|
|
(org-trim (replace-regexp-in-string "^" " " contents)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Line Break
|
|
|
|
|
|
|
|
|
|
(defun org-md-line-break (line-break contents info)
|
|
|
|
|
"Transcode LINE-BREAK object into Markdown format.
|
|
|
|
|
CONTENTS is nil. INFO is a plist used as a communication
|
|
|
|
|
channel."
|
2012-12-12 21:48:06 +00:00
|
|
|
|
" \n")
|
2012-07-25 21:04:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Link
|
|
|
|
|
|
|
|
|
|
(defun org-md-link (link contents info)
|
|
|
|
|
"Transcode LINE-BREAK object into Markdown format.
|
|
|
|
|
CONTENTS is the link's description. INFO is a plist used as
|
|
|
|
|
a communication channel."
|
|
|
|
|
(let ((--link-org-files-as-html-maybe
|
|
|
|
|
(function
|
|
|
|
|
(lambda (raw-path info)
|
|
|
|
|
;; Treat links to `file.org' as links to `file.html', if
|
2013-01-27 22:11:34 +00:00
|
|
|
|
;; needed. See `org-html-link-org-files-as-html'.
|
2012-07-25 21:04:36 +00:00
|
|
|
|
(cond
|
2013-01-27 22:11:34 +00:00
|
|
|
|
((and org-html-link-org-files-as-html
|
2012-07-25 21:04:36 +00:00
|
|
|
|
(string= ".org"
|
|
|
|
|
(downcase (file-name-extension raw-path "."))))
|
|
|
|
|
(concat (file-name-sans-extension raw-path) "."
|
|
|
|
|
(plist-get info :html-extension)))
|
|
|
|
|
(t raw-path)))))
|
|
|
|
|
(type (org-element-property :type link)))
|
|
|
|
|
(cond ((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-html-maybe
|
|
|
|
|
destination info)))
|
|
|
|
|
(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)
|
|
|
|
|
(mapconcat 'number-to-string
|
|
|
|
|
(org-export-get-headline-number
|
|
|
|
|
destination info)
|
|
|
|
|
".")))))))
|
2013-01-27 22:11:34 +00:00
|
|
|
|
((org-export-inline-image-p link org-html-inline-image-rules)
|
2012-12-08 18:30:27 +00:00
|
|
|
|
(let ((path (let ((raw-path (org-element-property :path link)))
|
|
|
|
|
(if (not (file-name-absolute-p raw-path)) raw-path
|
|
|
|
|
(expand-file-name raw-path)))))
|
|
|
|
|
(format "![%s](%s)"
|
|
|
|
|
(let ((caption (org-export-get-caption
|
|
|
|
|
(org-export-get-parent-element link))))
|
|
|
|
|
(when caption (org-export-data caption info)))
|
|
|
|
|
path)))
|
2012-07-25 21:04:36 +00:00
|
|
|
|
((string= type "coderef")
|
|
|
|
|
(let ((ref (org-element-property :path link)))
|
|
|
|
|
(format (org-export-get-coderef-format ref contents)
|
|
|
|
|
(org-export-resolve-coderef ref info))))
|
|
|
|
|
((equal type "radio")
|
|
|
|
|
(let ((destination (org-export-resolve-radio-link link info)))
|
|
|
|
|
(org-export-data (org-element-contents destination) info)))
|
|
|
|
|
((equal type "fuzzy")
|
|
|
|
|
(let ((destination (org-export-resolve-fuzzy-link link info)))
|
|
|
|
|
;; Ignore invisible "#+TARGET: path".
|
|
|
|
|
(unless (eq (org-element-type destination) 'keyword)
|
|
|
|
|
(if (org-string-nw-p contents) contents
|
|
|
|
|
(when destination
|
|
|
|
|
(let ((number (org-export-get-ordinal destination info)))
|
|
|
|
|
(when number
|
|
|
|
|
(if (atom number) (number-to-string number)
|
|
|
|
|
(mapconcat 'number-to-string number ".")))))))))
|
|
|
|
|
(t (let* ((raw-path (org-element-property :path link))
|
|
|
|
|
(path (cond
|
|
|
|
|
((member type '("http" "https" "ftp"))
|
|
|
|
|
(concat type ":" raw-path))
|
|
|
|
|
((equal type "file")
|
|
|
|
|
;; Treat links to ".org" files as ".html",
|
|
|
|
|
;; if needed.
|
|
|
|
|
(setq raw-path
|
|
|
|
|
(funcall --link-org-files-as-html-maybe
|
|
|
|
|
raw-path info))
|
|
|
|
|
;; If file path is absolute, prepend it
|
|
|
|
|
;; with protocol component - "file://".
|
|
|
|
|
(if (not (file-name-absolute-p raw-path)) raw-path
|
|
|
|
|
(concat "file://" (expand-file-name raw-path))))
|
|
|
|
|
(t raw-path))))
|
|
|
|
|
(if (not contents) (format "<%s>" path)
|
|
|
|
|
(format "[%s](%s)" contents path)))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Paragraph
|
|
|
|
|
|
|
|
|
|
(defun org-md-paragraph (paragraph contents info)
|
|
|
|
|
"Transcode PARAGRAPH element into Markdown format.
|
|
|
|
|
CONTENTS is the paragraph contents. INFO is a plist used as
|
|
|
|
|
a communication channel."
|
2012-07-27 12:05:44 +00:00
|
|
|
|
(let ((first-object (car (org-element-contents paragraph))))
|
|
|
|
|
;; If paragraph starts with a #, protect it.
|
|
|
|
|
(if (and (stringp first-object) (string-match "\\`#" first-object))
|
2012-08-19 13:59:24 +00:00
|
|
|
|
(replace-regexp-in-string "\\`#" "\\#" contents nil t)
|
2012-07-27 12:05:44 +00:00
|
|
|
|
contents)))
|
2012-07-25 21:04:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Plain List
|
|
|
|
|
|
|
|
|
|
(defun org-md-plain-list (plain-list contents info)
|
|
|
|
|
"Transcode PLAIN-LIST element into Markdown format.
|
|
|
|
|
CONTENTS is the plain-list contents. INFO is a plist used as
|
|
|
|
|
a communication channel."
|
|
|
|
|
contents)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Plain Text
|
|
|
|
|
|
|
|
|
|
(defun org-md-plain-text (text info)
|
|
|
|
|
"Transcode a TEXT string into Markdown format.
|
|
|
|
|
TEXT is the string to transcode. INFO is a plist holding
|
|
|
|
|
contextual information."
|
2012-10-26 22:36:00 +00:00
|
|
|
|
(when (plist-get info :with-smart-quotes)
|
|
|
|
|
(setq text (org-export-activate-smart-quotes text :html info)))
|
2012-07-27 12:05:44 +00:00
|
|
|
|
;; Protect ambiguous #. This will protect # at the beginning of
|
|
|
|
|
;; a line, but not at the beginning of a paragraph. See
|
|
|
|
|
;; `org-md-paragraph'.
|
|
|
|
|
(setq text (replace-regexp-in-string "\n#" "\n\\\\#" text))
|
2012-07-25 21:04:36 +00:00
|
|
|
|
;; Protect ambiguous !
|
|
|
|
|
(setq text (replace-regexp-in-string "\\(!\\)\\[" "\\\\!" text nil nil 1))
|
|
|
|
|
;; Protect `, *, _ and \
|
2012-10-26 22:36:00 +00:00
|
|
|
|
(setq text (replace-regexp-in-string "[`*_\\]" "\\\\\\&" text))
|
2012-07-25 21:04:36 +00:00
|
|
|
|
;; Handle special strings, if required.
|
|
|
|
|
(when (plist-get info :with-special-strings)
|
2013-01-27 22:11:34 +00:00
|
|
|
|
(setq text (org-html-convert-special-strings text)))
|
2012-07-25 21:04:36 +00:00
|
|
|
|
;; Handle break preservation, if required.
|
|
|
|
|
(when (plist-get info :preserve-breaks)
|
|
|
|
|
(setq text (replace-regexp-in-string "[ \t]*\n" " \n" text)))
|
|
|
|
|
;; Return value.
|
|
|
|
|
text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Quote Block
|
|
|
|
|
|
|
|
|
|
(defun org-md-quote-block (quote-block contents info)
|
|
|
|
|
"Transcode QUOTE-BLOCK element into Markdown format.
|
|
|
|
|
CONTENTS is the quote-block contents. INFO is a plist used as
|
|
|
|
|
a communication channel."
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
"^" "> "
|
|
|
|
|
(replace-regexp-in-string "\n\\'" "" contents)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Section
|
|
|
|
|
|
|
|
|
|
(defun org-md-section (section contents info)
|
|
|
|
|
"Transcode SECTION element into Markdown format.
|
|
|
|
|
CONTENTS is the section contents. INFO is a plist used as
|
|
|
|
|
a communication channel."
|
2012-07-27 12:43:12 +00:00
|
|
|
|
contents)
|
2012-07-25 21:04:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Template
|
|
|
|
|
|
|
|
|
|
(defun org-md-template (contents info)
|
|
|
|
|
"Return complete document string after Markdown conversion.
|
|
|
|
|
CONTENTS is the transcoded contents string. INFO is a plist used
|
|
|
|
|
as a communication channel."
|
|
|
|
|
contents)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Interactive function
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
2012-12-02 16:24:19 +00:00
|
|
|
|
(defun org-md-export-as-markdown (&optional async subtreep visible-only)
|
2012-07-25 21:04:36 +00:00
|
|
|
|
"Export current buffer to a text buffer.
|
|
|
|
|
|
|
|
|
|
If narrowing is active in the current buffer, only export its
|
|
|
|
|
narrowed part.
|
|
|
|
|
|
|
|
|
|
If a region is active, export that region.
|
|
|
|
|
|
2012-12-02 16:24:19 +00:00
|
|
|
|
A non-nil optional argument ASYNC means the process should happen
|
|
|
|
|
asynchronously. The resulting buffer should be accessible
|
|
|
|
|
through the `org-export-stack' interface.
|
|
|
|
|
|
2012-07-25 21:04:36 +00:00
|
|
|
|
When optional argument SUBTREEP is non-nil, export the sub-tree
|
|
|
|
|
at point, extracting information from the headline properties
|
|
|
|
|
first.
|
|
|
|
|
|
|
|
|
|
When optional argument VISIBLE-ONLY is non-nil, don't export
|
|
|
|
|
contents of hidden elements.
|
|
|
|
|
|
2012-07-26 12:51:45 +00:00
|
|
|
|
Export is done in a buffer named \"*Org MD Export*\", which will
|
|
|
|
|
be displayed when `org-export-show-temporary-export-buffer' is
|
|
|
|
|
non-nil."
|
2012-07-25 21:04:36 +00:00
|
|
|
|
(interactive)
|
2012-12-02 16:24:19 +00:00
|
|
|
|
(if async
|
|
|
|
|
(org-export-async-start
|
|
|
|
|
(lambda (output)
|
|
|
|
|
(with-current-buffer (get-buffer-create "*Org MD Export*")
|
|
|
|
|
(erase-buffer)
|
|
|
|
|
(insert output)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(text-mode)
|
|
|
|
|
(org-export-add-to-stack (current-buffer) 'md)))
|
|
|
|
|
`(org-export-as 'md ,subtreep ,visible-only))
|
|
|
|
|
(let ((outbuf (org-export-to-buffer
|
|
|
|
|
'md "*Org MD Export*" subtreep visible-only)))
|
|
|
|
|
(with-current-buffer outbuf (text-mode))
|
|
|
|
|
(when org-export-show-temporary-export-buffer
|
|
|
|
|
(switch-to-buffer-other-window outbuf)))))
|
2012-07-25 21:04:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
2012-12-02 16:24:19 +00:00
|
|
|
|
(defun org-md-export-to-markdown (&optional async subtreep visible-only)
|
2012-07-25 21:04:36 +00:00
|
|
|
|
"Export current buffer to a Markdown file.
|
|
|
|
|
|
|
|
|
|
If narrowing is active in the current buffer, only export its
|
|
|
|
|
narrowed part.
|
|
|
|
|
|
|
|
|
|
If a region is active, export that region.
|
|
|
|
|
|
2012-12-02 16:24:19 +00:00
|
|
|
|
A non-nil optional argument ASYNC means the process should happen
|
|
|
|
|
asynchronously. The resulting file should be accessible through
|
|
|
|
|
the `org-export-stack' interface.
|
|
|
|
|
|
2012-07-25 21:04:36 +00:00
|
|
|
|
When optional argument SUBTREEP is non-nil, export the sub-tree
|
|
|
|
|
at point, extracting information from the headline properties
|
|
|
|
|
first.
|
|
|
|
|
|
|
|
|
|
When optional argument VISIBLE-ONLY is non-nil, don't export
|
|
|
|
|
contents of hidden elements.
|
|
|
|
|
|
|
|
|
|
Return output file's name."
|
|
|
|
|
(interactive)
|
2012-11-29 20:52:43 +00:00
|
|
|
|
(let ((outfile (org-export-output-file-name ".md" subtreep)))
|
2012-12-02 16:24:19 +00:00
|
|
|
|
(if async
|
|
|
|
|
(org-export-async-start
|
|
|
|
|
(lambda (f) (org-export-add-to-stack f 'md))
|
|
|
|
|
`(expand-file-name
|
|
|
|
|
(org-export-to-file 'md ,outfile ,subtreep ,visible-only)))
|
|
|
|
|
(org-export-to-file 'md outfile subtreep visible-only))))
|
2012-07-25 21:04:36 +00:00
|
|
|
|
|
|
|
|
|
|
2013-01-27 22:11:34 +00:00
|
|
|
|
(provide 'ox-md)
|
|
|
|
|
|
|
|
|
|
;; Local variables:
|
|
|
|
|
;; generated-autoload-file: "org-loaddefs.el"
|
|
|
|
|
;; End:
|
|
|
|
|
|
|
|
|
|
;;; ox-md.el ends here
|