2015-10-31 19:05:22 -04:00
|
|
|
|
;;; ox-md.el --- Markdown Back-End for Org Export Engine -*- lexical-binding: t; -*-
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
2021-01-01 14:55:31 -05:00
|
|
|
|
;; Copyright (C) 2012-2021 Free Software Foundation, Inc.
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
|
|
|
|
;; Author: Nicolas Goaziou <n.goaziou@gmail.com>
|
2021-05-03 00:41:56 -04:00
|
|
|
|
;; Maintainer: Nicolas Goaziou <n.goaziou at gmail dot com>
|
2013-03-07 08:44:58 -05:00
|
|
|
|
;; Keywords: org, wp, markdown
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
Backport changes from Emacs revs 115081 and 115082
2013-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
Address some byte-compiler warnings.
* ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* ob-calc.el (org--var-syms): Rename from `var-syms'.
* ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* ob-table.el (sbe): Move debug declaration.
* org-clock.el (org--msg-extra): Rename from `msg-extra'.
* org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* org-colview.el (org-agenda-overriding-columns-format):
* org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* ob-python.el (py-which-bufname, python-shell-buffer-name):
* ob-haskell.el (org-export-copy-to-kill-ring):
* ob-exp.el (org-link-search-inhibit-query):
* ob-R.el (ess-eval-visibly-p):
* ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* ox-odt.el (org-odt-hfy-face-to-css):
* org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* ob-sqlite.el (org-babel-sqlite-expand-vars):
* ob-sql.el (org-babel-sql-expand-vars):
* ob-shen.el (org-babel-execute:shen):
* ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* ob-scala.el (org-babel-scala-evaluate):
* ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* ob-picolisp.el (org-babel-execute:picolisp):
* ob-perl.el (org-babel-perl-evaluate):
* ob-maxima.el (org-babel-execute:maxima):
* ob-lisp.el (org-babel-execute:lisp):
* ob-java.el (org-babel-execute:java):
* ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 Glenn Morris <rgm@gnu.org>
* ox-html.el (org-html-scripts): Add 2013 to copyright years.
(org-html-infojs-template): Copyright holder to FSF.
2013-11-12 14:57:31 -05:00
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
2013-02-23 03:56:24 -05:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2012-07-25 17:04:36 -04:00
|
|
|
|
;; 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.
|
|
|
|
|
|
2013-02-23 03:56:24 -05:00
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
2012-07-25 17:04:36 -04:00
|
|
|
|
;; 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
|
2017-09-13 18:52:52 -04:00
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
2013-11-17 03:12:41 -05:00
|
|
|
|
;; This library implements a Markdown back-end (vanilla flavor) for
|
2013-10-20 04:58:30 -04:00
|
|
|
|
;; Org exporter, based on `html' back-end. See Org manual for more
|
|
|
|
|
;; information.
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2016-07-25 09:55:16 -04:00
|
|
|
|
(require 'cl-lib)
|
2013-01-27 17:11:34 -05:00
|
|
|
|
(require 'ox-html)
|
2013-09-25 02:53:59 -04:00
|
|
|
|
(require 'ox-publish)
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
2012-07-27 16:52:01 -04:00
|
|
|
|
|
|
|
|
|
;;; User-Configurable Variables
|
|
|
|
|
|
|
|
|
|
(defgroup org-export-md nil
|
|
|
|
|
"Options specific to Markdown export back-end."
|
|
|
|
|
:tag "Org Markdown"
|
|
|
|
|
:group 'org-export
|
2013-03-06 11:31:28 -05:00
|
|
|
|
:version "24.4"
|
|
|
|
|
:package-version '(Org . "8.0"))
|
2012-07-27 16:52:01 -04:00
|
|
|
|
|
|
|
|
|
(defcustom org-md-headline-style 'atx
|
|
|
|
|
"Style used to format headlines.
|
2012-07-27 18:49:58 -04:00
|
|
|
|
This variable can be set to either `atx' or `setext'."
|
2012-07-27 16:52:01 -04:00
|
|
|
|
:group 'org-export-md
|
|
|
|
|
:type '(choice
|
|
|
|
|
(const :tag "Use \"atx\" style" atx)
|
|
|
|
|
(const :tag "Use \"Setext\" style" setext)))
|
|
|
|
|
|
|
|
|
|
|
2016-08-22 04:48:57 -04:00
|
|
|
|
;;;; Footnotes
|
|
|
|
|
|
|
|
|
|
(defcustom org-md-footnotes-section "%s%s"
|
|
|
|
|
"Format string for the footnotes section.
|
|
|
|
|
The first %s placeholder will be replaced with the localized Footnotes section
|
|
|
|
|
heading, the second with the contents of the Footnotes section."
|
|
|
|
|
:group 'org-export-md
|
|
|
|
|
:type 'string
|
2017-01-25 23:39:18 -05:00
|
|
|
|
:version "26.1"
|
2016-08-22 04:48:57 -04:00
|
|
|
|
:package-version '(Org . "9.0"))
|
|
|
|
|
|
|
|
|
|
(defcustom org-md-footnote-format "<sup>%s</sup>"
|
|
|
|
|
"Format string for the footnote reference.
|
|
|
|
|
The %s will be replaced by the footnote reference itself."
|
|
|
|
|
:group 'org-export-md
|
|
|
|
|
:type 'string
|
2017-01-25 23:39:18 -05:00
|
|
|
|
:version "26.1"
|
2016-08-22 04:48:57 -04:00
|
|
|
|
:package-version '(Org . "9.0"))
|
|
|
|
|
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
|
|
|
|
;;; Define Back-End
|
|
|
|
|
|
2013-03-19 11:24:40 -04:00
|
|
|
|
(org-export-define-derived-backend 'md 'html
|
|
|
|
|
:filters-alist '((:filter-parse-tree . org-md-separate-elements))
|
2012-09-09 07:08:52 -04:00
|
|
|
|
:menu-entry
|
2013-03-19 11:24:40 -04:00
|
|
|
|
'(?m "Export to Markdown"
|
|
|
|
|
((?M "To temporary buffer"
|
|
|
|
|
(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)))
|
|
|
|
|
(?o "To file and open"
|
|
|
|
|
(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)))))))
|
|
|
|
|
:translate-alist '((bold . org-md-bold)
|
2020-06-23 09:47:08 -04:00
|
|
|
|
(center-block . org-md--convert-to-html)
|
2013-03-19 11:24:40 -04:00
|
|
|
|
(code . org-md-verbatim)
|
2020-06-23 09:47:08 -04:00
|
|
|
|
(drawer . org-md--identity)
|
|
|
|
|
(dynamic-block . org-md--identity)
|
2013-03-19 11:24:40 -04:00
|
|
|
|
(example-block . org-md-example-block)
|
2014-09-08 05:57:27 -04:00
|
|
|
|
(export-block . org-md-export-block)
|
2013-03-19 11:24:40 -04:00
|
|
|
|
(fixed-width . org-md-example-block)
|
|
|
|
|
(headline . org-md-headline)
|
|
|
|
|
(horizontal-rule . org-md-horizontal-rule)
|
|
|
|
|
(inline-src-block . org-md-verbatim)
|
2020-06-23 09:47:08 -04:00
|
|
|
|
(inlinetask . org-md--convert-to-html)
|
2014-01-21 17:35:34 -05:00
|
|
|
|
(inner-template . org-md-inner-template)
|
2013-03-19 11:24:40 -04:00
|
|
|
|
(italic . org-md-italic)
|
|
|
|
|
(item . org-md-item)
|
2014-01-04 14:19:24 -05:00
|
|
|
|
(keyword . org-md-keyword)
|
2013-03-19 11:24:40 -04:00
|
|
|
|
(line-break . org-md-line-break)
|
|
|
|
|
(link . org-md-link)
|
2013-09-25 15:27:29 -04:00
|
|
|
|
(node-property . org-md-node-property)
|
2013-03-19 11:24:40 -04:00
|
|
|
|
(paragraph . org-md-paragraph)
|
|
|
|
|
(plain-list . org-md-plain-list)
|
|
|
|
|
(plain-text . org-md-plain-text)
|
2013-09-25 15:27:29 -04:00
|
|
|
|
(property-drawer . org-md-property-drawer)
|
2013-03-19 11:24:40 -04:00
|
|
|
|
(quote-block . org-md-quote-block)
|
|
|
|
|
(section . org-md-section)
|
2020-06-23 09:47:08 -04:00
|
|
|
|
(special-block . org-md--convert-to-html)
|
2013-03-19 11:24:40 -04:00
|
|
|
|
(src-block . org-md-example-block)
|
2020-06-23 09:47:08 -04:00
|
|
|
|
(table . org-md--convert-to-html)
|
2013-03-19 11:24:40 -04:00
|
|
|
|
(template . org-md-template)
|
2014-05-21 03:06:59 -04:00
|
|
|
|
(verbatim . org-md-verbatim))
|
2016-08-22 04:48:57 -04:00
|
|
|
|
:options-alist
|
|
|
|
|
'((:md-footnote-format nil nil org-md-footnote-format)
|
|
|
|
|
(:md-footnotes-section nil nil org-md-footnotes-section)
|
|
|
|
|
(:md-headline-style nil nil org-md-headline-style)))
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Filters
|
|
|
|
|
|
2015-10-31 19:05:22 -04:00
|
|
|
|
(defun org-md-separate-elements (tree _backend info)
|
2014-01-21 17:35:34 -05:00
|
|
|
|
"Fix blank lines between elements.
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
|
|
|
|
TREE is the parse tree being exported. BACKEND is the export
|
|
|
|
|
back-end used. INFO is a plist used as a communication channel.
|
|
|
|
|
|
2014-11-02 17:09:48 -05:00
|
|
|
|
Enforce a blank line between elements. There are two exceptions
|
|
|
|
|
to this rule:
|
2014-08-16 10:19:01 -04:00
|
|
|
|
|
|
|
|
|
1. Preserve blank lines between sibling items in a plain list,
|
|
|
|
|
|
2014-11-02 17:09:48 -05:00
|
|
|
|
2. In an item, remove any blank line before the very first
|
2015-09-24 04:27:24 -04:00
|
|
|
|
paragraph and the next sub-list when the latter ends the
|
|
|
|
|
current item.
|
2014-01-21 17:35:34 -05:00
|
|
|
|
|
2012-07-25 17:04:36 -04:00
|
|
|
|
Assume BACKEND is `md'."
|
2014-01-21 17:35:34 -05:00
|
|
|
|
(org-element-map tree (remq 'item org-element-all-elements)
|
2014-08-16 10:19:01 -04:00
|
|
|
|
(lambda (e)
|
2014-11-02 17:09:48 -05:00
|
|
|
|
(org-element-put-property
|
|
|
|
|
e :post-blank
|
|
|
|
|
(if (and (eq (org-element-type e) 'paragraph)
|
|
|
|
|
(eq (org-element-type (org-element-property :parent e)) 'item)
|
2015-09-24 04:27:24 -04:00
|
|
|
|
(org-export-first-sibling-p e info)
|
2015-09-22 15:32:07 -04:00
|
|
|
|
(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)))))
|
2014-11-02 17:09:48 -05:00
|
|
|
|
0
|
|
|
|
|
1))))
|
2012-07-25 17:04:36 -04:00
|
|
|
|
;; Return updated tree.
|
|
|
|
|
tree)
|
|
|
|
|
|
2020-06-23 09:34:48 -04:00
|
|
|
|
|
|
|
|
|
;;; Internal functions
|
|
|
|
|
|
|
|
|
|
(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."
|
|
|
|
|
(unless (org-element-property :footnote-section-p headline)
|
|
|
|
|
(or
|
|
|
|
|
;; Global table of contents includes HEADLINE.
|
|
|
|
|
(and (plist-get info :with-toc)
|
|
|
|
|
(memq headline
|
|
|
|
|
(org-export-collect-headlines info (plist-get info :with-toc))))
|
|
|
|
|
;; A local table of contents includes HEADLINE.
|
|
|
|
|
(cl-some
|
|
|
|
|
(lambda (h)
|
|
|
|
|
(let ((section (car (org-element-contents h))))
|
|
|
|
|
(and
|
|
|
|
|
(eq 'section (org-element-type section))
|
|
|
|
|
(org-element-map section 'keyword
|
|
|
|
|
(lambda (keyword)
|
|
|
|
|
(when (equal "TOC" (org-element-property :key keyword))
|
|
|
|
|
(let ((case-fold-search t)
|
|
|
|
|
(value (org-element-property :value keyword)))
|
|
|
|
|
(and (string-match-p "\\<headlines\\>" value)
|
|
|
|
|
(let ((n (and
|
|
|
|
|
(string-match "\\<[0-9]+\\>" value)
|
|
|
|
|
(string-to-number (match-string 0 value))))
|
|
|
|
|
(local? (string-match-p "\\<local\\>" value)))
|
|
|
|
|
(memq headline
|
|
|
|
|
(org-export-collect-headlines
|
|
|
|
|
info n (and local? keyword))))))))
|
|
|
|
|
info t))))
|
|
|
|
|
(org-element-lineage headline))
|
|
|
|
|
;; A link refers internally to HEADLINE.
|
|
|
|
|
(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.
|
|
|
|
|
STYLE is the preferred style (`atx' or `setext'). LEVEL is the
|
|
|
|
|
header level. TITLE is the headline title. ANCHOR is the HTML
|
|
|
|
|
anchor tag for the section as a string. TAGS are the tags set on
|
|
|
|
|
the section."
|
|
|
|
|
(let ((anchor-lines (and anchor (concat anchor "\n\n"))))
|
|
|
|
|
;; Use "Setext" style
|
|
|
|
|
(if (and (eq style 'setext) (< level 3))
|
|
|
|
|
(let* ((underline-char (if (= level 1) ?= ?-))
|
|
|
|
|
(underline (concat (make-string (length title) underline-char)
|
|
|
|
|
"\n")))
|
|
|
|
|
(concat "\n" anchor-lines title tags "\n" underline "\n"))
|
|
|
|
|
;; Use "Atx" style
|
|
|
|
|
(let ((level-mark (make-string level ?#)))
|
|
|
|
|
(concat "\n" anchor-lines level-mark " " title tags "\n\n")))))
|
|
|
|
|
|
|
|
|
|
(defun org-md--build-toc (info &optional n _keyword scope)
|
|
|
|
|
"Return a table of contents.
|
|
|
|
|
|
|
|
|
|
INFO is a plist used as a communication channel.
|
|
|
|
|
|
|
|
|
|
Optional argument N, when non-nil, is an integer specifying the
|
|
|
|
|
depth of the table.
|
|
|
|
|
|
|
|
|
|
When optional argument SCOPE is non-nil, build a table of
|
|
|
|
|
contents according to the specified element."
|
|
|
|
|
(concat
|
|
|
|
|
(unless scope
|
|
|
|
|
(let ((style (plist-get info :md-headline-style))
|
|
|
|
|
(title (org-html--translate "Table of Contents" info)))
|
|
|
|
|
(org-md--headline-title style 1 title nil)))
|
|
|
|
|
(mapconcat
|
|
|
|
|
(lambda (headline)
|
|
|
|
|
(let* ((indentation
|
|
|
|
|
(make-string
|
|
|
|
|
(* 4 (1- (org-export-get-relative-level headline info)))
|
|
|
|
|
?\s))
|
|
|
|
|
(bullet
|
|
|
|
|
(if (not (org-export-numbered-headline-p headline info)) "- "
|
|
|
|
|
(let ((prefix
|
|
|
|
|
(format "%d." (org-last (org-export-get-headline-number
|
|
|
|
|
headline info)))))
|
|
|
|
|
(concat prefix (make-string (max 1 (- 4 (length prefix)))
|
|
|
|
|
?\s)))))
|
|
|
|
|
(title
|
|
|
|
|
(format "[%s](#%s)"
|
|
|
|
|
(org-export-data-with-backend
|
|
|
|
|
(org-export-get-alt-title headline info)
|
|
|
|
|
(org-export-toc-entry-backend 'md)
|
|
|
|
|
info)
|
|
|
|
|
(or (org-element-property :CUSTOM_ID headline)
|
|
|
|
|
(org-export-get-reference headline info))))
|
|
|
|
|
(tags (and (plist-get info :with-tags)
|
|
|
|
|
(not (eq 'not-in-toc (plist-get info :with-tags)))
|
|
|
|
|
(org-make-tag-string
|
|
|
|
|
(org-export-get-tags headline info)))))
|
|
|
|
|
(concat indentation bullet title tags)))
|
|
|
|
|
(org-export-collect-headlines info n scope) "\n")
|
|
|
|
|
"\n"))
|
|
|
|
|
|
|
|
|
|
(defun org-md--footnote-formatted (footnote info)
|
|
|
|
|
"Formats a single footnote entry FOOTNOTE.
|
|
|
|
|
FOOTNOTE is a cons cell of the form (number . definition).
|
|
|
|
|
INFO is a plist with contextual information."
|
|
|
|
|
(let* ((fn-num (car footnote))
|
|
|
|
|
(fn-text (cdr footnote))
|
|
|
|
|
(fn-format (plist-get info :md-footnote-format))
|
|
|
|
|
(fn-anchor (format "fn.%d" fn-num))
|
|
|
|
|
(fn-href (format " href=\"#fnr.%d\"" fn-num))
|
|
|
|
|
(fn-link-to-ref (org-html--anchor fn-anchor fn-num fn-href info)))
|
|
|
|
|
(concat (format fn-format fn-link-to-ref) " " fn-text "\n")))
|
|
|
|
|
|
|
|
|
|
(defun org-md--footnote-section (info)
|
|
|
|
|
"Format the footnote section.
|
|
|
|
|
INFO is a plist used as a communication channel."
|
|
|
|
|
(let* ((fn-alist (org-export-collect-footnote-definitions info))
|
|
|
|
|
(fn-alist (cl-loop for (n _type raw) in fn-alist collect
|
|
|
|
|
(cons n (org-trim (org-export-data raw info)))))
|
|
|
|
|
(headline-style (plist-get info :md-headline-style))
|
|
|
|
|
(section-title (org-html--translate "Footnotes" info)))
|
|
|
|
|
(when fn-alist
|
|
|
|
|
(format (plist-get info :md-footnotes-section)
|
|
|
|
|
(org-md--headline-title headline-style 1 section-title)
|
|
|
|
|
(mapconcat (lambda (fn) (org-md--footnote-formatted fn info))
|
|
|
|
|
fn-alist
|
|
|
|
|
"\n")))))
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
2020-06-23 09:47:08 -04:00
|
|
|
|
(defun org-md--convert-to-html (datum _contents info)
|
|
|
|
|
"Convert DATUM into raw HTML, including contents."
|
|
|
|
|
(org-export-data-with-backend datum 'html info))
|
|
|
|
|
|
|
|
|
|
(defun org-md--identity (_datum contents _info)
|
2020-06-25 14:36:26 -04:00
|
|
|
|
"Return CONTENTS only."
|
2020-06-23 09:47:08 -04:00
|
|
|
|
contents)
|
|
|
|
|
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
|
|
|
|
;;; Transcode Functions
|
|
|
|
|
|
|
|
|
|
;;;; Bold
|
|
|
|
|
|
2015-10-31 19:05:22 -04:00
|
|
|
|
(defun org-md-bold (_bold contents _info)
|
2012-07-25 17:04:36 -04:00
|
|
|
|
"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
|
|
|
|
|
|
2015-10-31 19:05:22 -04:00
|
|
|
|
(defun org-md-verbatim (verbatim _contents _info)
|
2012-07-25 17:04:36 -04:00
|
|
|
|
"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`")
|
2016-09-02 21:05:10 -04:00
|
|
|
|
((or (string-prefix-p "`" value)
|
|
|
|
|
(string-suffix-p "`" value))
|
2012-07-25 17:04:36 -04:00
|
|
|
|
"`` %s ``")
|
|
|
|
|
(t "``%s``"))
|
|
|
|
|
value)))
|
|
|
|
|
|
|
|
|
|
|
2018-09-20 05:23:49 -04:00
|
|
|
|
;;;; Example Block, Src Block and Export Block
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
2015-10-31 19:05:22 -04:00
|
|
|
|
(defun org-md-example-block (example-block _contents info)
|
2012-07-25 17:04:36 -04:00
|
|
|
|
"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
|
2014-04-06 08:06:08 -04:00
|
|
|
|
(org-export-format-code-default example-block info))))
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
2014-09-08 05:57:27 -04:00
|
|
|
|
(defun org-md-export-block (export-block contents info)
|
|
|
|
|
"Transcode a EXPORT-BLOCK element from Org to Markdown.
|
|
|
|
|
CONTENTS is nil. INFO is a plist holding contextual information."
|
|
|
|
|
(if (member (org-element-property :type export-block) '("MARKDOWN" "MD"))
|
|
|
|
|
(org-remove-indentation (org-element-property :value export-block))
|
|
|
|
|
;; Also include HTML export blocks.
|
|
|
|
|
(org-export-with-backend 'html export-block contents info)))
|
|
|
|
|
|
2014-01-04 14:19:24 -05:00
|
|
|
|
|
2012-07-25 17:04:36 -04:00
|
|
|
|
;;;; 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 16:52:01 -04: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 17:05:34 -04:00
|
|
|
|
(and todo (concat (org-export-data todo info) " ")))))
|
2012-07-27 16:52:01 -04:00
|
|
|
|
(tags (and (plist-get info :with-tags)
|
|
|
|
|
(let ((tag-list (org-export-get-tags headline info)))
|
|
|
|
|
(and tag-list
|
2018-04-18 17:57:51 -04:00
|
|
|
|
(concat " " (org-make-tag-string tag-list))))))
|
2012-07-27 17:05:34 -04:00
|
|
|
|
(priority
|
|
|
|
|
(and (plist-get info :with-priority)
|
|
|
|
|
(let ((char (org-element-property :priority headline)))
|
|
|
|
|
(and char (format "[#%c] " char)))))
|
|
|
|
|
;; Headline text without tags.
|
Use options instead of hard-coded variables
* lisp/ox-beamer.el (org-beamer--format-frame,
org-beamer--format-block, org-beamer-template): Use options instead
of hard-coded variables.
* lisp/ox-man.el (org-man-inline-src-block, org-man-src-block,
org-man-table, org-man-table-cell): Use options instead of
hard-coded variables.
* lisp/ox-md.el (org-md-headline): Use options instead of hard-coded
variables.
* lisp/ox-texinfo.el (org-texinfo-format-headline-function,
org-texinfo-format-inlinetask-function): Change default value.
(org-texinfo--text-markup, org-texinfo--format-menu): Change signature
(org-texinfo--build-menu, org-texinfo-bold, org-texinfo-code,
org-texinfo-comment, org-texinfo-italic, org-texinfo-verbatim): Apply
signature change.
(org-texinfo-template, org-texinfo-clock, org-texinfo-drawer,
org-texinfo-link, org-texinfo-plain-list, org-texinfo-planning,
org-texinfo-table, org-texinfo-table-cell, org-texinfo-timestamp): Use
options instead of variable names.
(org-texinfo-format-headline-default-function,
org-texinfo-format-inlinetask-default-function): New functions.
(org-texinfo-headline, org-texinfo-inlinetask): Use new functions.
2014-07-28 09:44:56 -04:00
|
|
|
|
(heading (concat todo priority title))
|
|
|
|
|
(style (plist-get info :md-headline-style)))
|
2012-07-27 16:52:01 -04:00
|
|
|
|
(cond
|
2013-02-23 07:47:44 -05:00
|
|
|
|
;; Cannot create a headline. Fall-back to a list.
|
2012-07-27 16:52:01 -04:00
|
|
|
|
((or (org-export-low-level-p headline info)
|
Use options instead of hard-coded variables
* lisp/ox-beamer.el (org-beamer--format-frame,
org-beamer--format-block, org-beamer-template): Use options instead
of hard-coded variables.
* lisp/ox-man.el (org-man-inline-src-block, org-man-src-block,
org-man-table, org-man-table-cell): Use options instead of
hard-coded variables.
* lisp/ox-md.el (org-md-headline): Use options instead of hard-coded
variables.
* lisp/ox-texinfo.el (org-texinfo-format-headline-function,
org-texinfo-format-inlinetask-function): Change default value.
(org-texinfo--text-markup, org-texinfo--format-menu): Change signature
(org-texinfo--build-menu, org-texinfo-bold, org-texinfo-code,
org-texinfo-comment, org-texinfo-italic, org-texinfo-verbatim): Apply
signature change.
(org-texinfo-template, org-texinfo-clock, org-texinfo-drawer,
org-texinfo-link, org-texinfo-plain-list, org-texinfo-planning,
org-texinfo-table, org-texinfo-table-cell, org-texinfo-timestamp): Use
options instead of variable names.
(org-texinfo-format-headline-default-function,
org-texinfo-format-inlinetask-default-function): New functions.
(org-texinfo-headline, org-texinfo-inlinetask): Use new functions.
2014-07-28 09:44:56 -04:00
|
|
|
|
(not (memq style '(atx setext)))
|
|
|
|
|
(and (eq style 'atx) (> level 6))
|
|
|
|
|
(and (eq style 'setext) (> level 2)))
|
2012-07-27 16:52:01 -04:00
|
|
|
|
(let ((bullet
|
|
|
|
|
(if (not (org-export-numbered-headline-p headline info)) "-"
|
|
|
|
|
(concat (number-to-string
|
|
|
|
|
(car (last (org-export-get-headline-number
|
|
|
|
|
headline info))))
|
|
|
|
|
"."))))
|
2016-08-22 04:48:57 -04:00
|
|
|
|
(concat bullet (make-string (- 4 (length bullet)) ?\s) heading tags "\n\n"
|
|
|
|
|
(and contents (replace-regexp-in-string "^" " " contents)))))
|
2017-03-10 12:52:06 -05:00
|
|
|
|
(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))))))
|
2017-10-11 19:00:14 -04:00
|
|
|
|
(concat (org-md--headline-title style level heading anchor tags)
|
2017-03-10 12:52:06 -05:00
|
|
|
|
contents)))))))
|
|
|
|
|
|
2012-07-25 17:04:36 -04:00
|
|
|
|
;;;; Horizontal Rule
|
|
|
|
|
|
2015-10-31 19:05:22 -04:00
|
|
|
|
(defun org-md-horizontal-rule (_horizontal-rule _contents _info)
|
2012-07-25 17:04:36 -04:00
|
|
|
|
"Transcode HORIZONTAL-RULE element into Markdown format.
|
|
|
|
|
CONTENTS is the horizontal rule contents. INFO is a plist used
|
|
|
|
|
as a communication channel."
|
|
|
|
|
"---")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Italic
|
|
|
|
|
|
2015-10-31 19:05:22 -04:00
|
|
|
|
(defun org-md-italic (_italic contents _info)
|
2012-07-25 17:04:36 -04:00
|
|
|
|
"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)) ? )
|
2016-07-25 09:55:16 -04:00
|
|
|
|
(pcase (org-element-property :checkbox item)
|
|
|
|
|
(`on "[X] ")
|
|
|
|
|
(`trans "[-] ")
|
|
|
|
|
(`off "[ ] "))
|
2012-07-25 17:04:36 -04:00
|
|
|
|
(let ((tag (org-element-property :tag item)))
|
|
|
|
|
(and tag (format "**%s:** "(org-export-data tag info))))
|
2014-01-08 16:47:10 -05:00
|
|
|
|
(and contents
|
|
|
|
|
(org-trim (replace-regexp-in-string "^" " " contents))))))
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
|
|
|
|
|
2014-01-04 14:19:24 -05:00
|
|
|
|
|
|
|
|
|
;;;; Keyword
|
|
|
|
|
|
|
|
|
|
(defun org-md-keyword (keyword contents info)
|
|
|
|
|
"Transcode a KEYWORD element into Markdown format.
|
|
|
|
|
CONTENTS is nil. INFO is a plist used as a communication
|
|
|
|
|
channel."
|
2017-03-11 09:21:27 -05:00
|
|
|
|
(pcase (org-element-property :key keyword)
|
|
|
|
|
((or "MARKDOWN" "MD") (org-element-property :value keyword))
|
|
|
|
|
("TOC"
|
|
|
|
|
(let ((case-fold-search t)
|
|
|
|
|
(value (org-element-property :value keyword)))
|
|
|
|
|
(cond
|
|
|
|
|
((string-match-p "\\<headlines\\>" value)
|
|
|
|
|
(let ((depth (and (string-match "\\<[0-9]+\\>" value)
|
|
|
|
|
(string-to-number (match-string 0 value))))
|
2019-05-15 14:22:05 -04:00
|
|
|
|
(scope
|
|
|
|
|
(cond
|
|
|
|
|
((string-match ":target +\\(\".+?\"\\|\\S-+\\)" value) ;link
|
|
|
|
|
(org-export-resolve-link
|
|
|
|
|
(org-strip-quotes (match-string 1 value)) info))
|
|
|
|
|
((string-match-p "\\<local\\>" value) keyword)))) ;local
|
2017-03-11 09:21:27 -05:00
|
|
|
|
(org-remove-indentation
|
2019-05-15 14:22:05 -04:00
|
|
|
|
(org-md--build-toc info depth keyword scope)))))))
|
2017-03-11 09:21:27 -05:00
|
|
|
|
(_ (org-export-with-backend 'html keyword contents info))))
|
2014-01-04 14:19:24 -05:00
|
|
|
|
|
|
|
|
|
|
2012-07-25 17:04:36 -04:00
|
|
|
|
;;;; Line Break
|
|
|
|
|
|
2015-10-31 19:05:22 -04:00
|
|
|
|
(defun org-md-line-break (_line-break _contents _info)
|
2012-07-25 17:04:36 -04:00
|
|
|
|
"Transcode LINE-BREAK object into Markdown format.
|
|
|
|
|
CONTENTS is nil. INFO is a plist used as a communication
|
|
|
|
|
channel."
|
2012-12-12 16:48:06 -05:00
|
|
|
|
" \n")
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Link
|
|
|
|
|
|
2020-01-13 20:52:12 -05:00
|
|
|
|
(defun org-md-link (link desc info)
|
2020-05-10 01:41:54 -04:00
|
|
|
|
"Transcode LINK object into Markdown format.
|
2020-01-13 20:52:12 -05:00
|
|
|
|
DESC is the description part of the link, or the empty string.
|
|
|
|
|
INFO is a plist holding contextual information. See
|
|
|
|
|
`org-export-data'."
|
|
|
|
|
(let* ((link-org-files-as-md
|
|
|
|
|
(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)))
|
2020-01-17 18:44:41 -05:00
|
|
|
|
(type (org-element-property :type link))
|
2020-01-13 21:07:53 -05:00
|
|
|
|
(raw-path (org-element-property :path link))
|
2020-01-13 20:52:12 -05:00
|
|
|
|
(path (cond
|
|
|
|
|
((member type '("http" "https" "ftp" "mailto"))
|
2020-01-13 21:07:53 -05:00
|
|
|
|
(concat type ":" raw-path))
|
2020-02-20 03:29:21 -05:00
|
|
|
|
((string-equal type "file")
|
2020-01-13 20:52:12 -05:00
|
|
|
|
(org-export-file-uri (funcall link-org-files-as-md raw-path)))
|
|
|
|
|
(t raw-path))))
|
2014-08-21 05:05:45 -04:00
|
|
|
|
(cond
|
2015-01-04 15:54:41 -05:00
|
|
|
|
;; Link type is handled by a special function.
|
2020-02-14 04:00:15 -05:00
|
|
|
|
((org-export-custom-protocol-maybe link desc 'md info))
|
2015-09-20 16:27:09 -04:00
|
|
|
|
((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))))
|
2016-07-25 09:55:16 -04:00
|
|
|
|
(pcase (org-element-type destination)
|
|
|
|
|
(`plain-text ; External file.
|
2015-09-20 16:27:09 -04:00
|
|
|
|
(let ((path (funcall link-org-files-as-md destination)))
|
2020-01-13 20:52:12 -05:00
|
|
|
|
(if (not desc) (format "<%s>" path)
|
|
|
|
|
(format "[%s](%s)" desc path))))
|
2016-07-25 09:55:16 -04:00
|
|
|
|
(`headline
|
2015-09-20 16:27:09 -04:00
|
|
|
|
(format
|
|
|
|
|
"[%s](#%s)"
|
|
|
|
|
;; Description.
|
2020-01-13 20:52:12 -05:00
|
|
|
|
(cond ((org-string-nw-p desc))
|
2015-09-20 16:27:09 -04:00
|
|
|
|
((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))))
|
2016-07-25 09:55:16 -04:00
|
|
|
|
(_
|
2015-09-20 16:27:09 -04:00
|
|
|
|
(let ((description
|
2020-01-13 21:07:53 -05:00
|
|
|
|
(or (org-string-nw-p desc)
|
2015-09-20 16:27:09 -04:00
|
|
|
|
(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))))))))
|
2014-08-21 05:05:45 -04:00
|
|
|
|
((org-export-inline-image-p link org-html-inline-image-rules)
|
2020-02-20 03:29:21 -05:00
|
|
|
|
(let ((path (cond ((not (string-equal type "file"))
|
2020-01-17 18:44:41 -05:00
|
|
|
|
(concat type ":" raw-path))
|
2020-01-13 20:52:12 -05:00
|
|
|
|
((not (file-name-absolute-p raw-path)) raw-path)
|
|
|
|
|
(t (expand-file-name raw-path))))
|
2014-08-21 05:05:45 -04:00
|
|
|
|
(caption (org-export-data
|
|
|
|
|
(org-export-get-caption
|
2020-02-18 16:57:37 -05:00
|
|
|
|
(org-export-get-parent-element link))
|
|
|
|
|
info)))
|
2014-08-21 05:05:45 -04:00
|
|
|
|
(format "![img](%s)"
|
|
|
|
|
(if (not (org-string-nw-p caption)) path
|
|
|
|
|
(format "%s \"%s\"" path caption)))))
|
|
|
|
|
((string= type "coderef")
|
2020-01-13 20:52:12 -05:00
|
|
|
|
(format (org-export-get-coderef-format path desc)
|
|
|
|
|
(org-export-resolve-coderef path info)))
|
2020-11-03 15:24:03 -05:00
|
|
|
|
((string= type "radio")
|
|
|
|
|
(let ((destination (org-export-resolve-radio-link link info)))
|
|
|
|
|
(if (not destination) desc
|
|
|
|
|
(format "<a href=\"#%s\">%s</a>"
|
|
|
|
|
(org-export-get-reference destination info)
|
|
|
|
|
desc))))
|
2020-01-13 20:52:12 -05:00
|
|
|
|
(t (if (not desc) (format "<%s>" path)
|
|
|
|
|
(format "[%s](%s)" desc path))))))
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
|
|
|
|
|
2013-09-25 15:27:29 -04:00
|
|
|
|
;;;; Node Property
|
|
|
|
|
|
2015-10-31 19:05:22 -04:00
|
|
|
|
(defun org-md-node-property (node-property _contents _info)
|
2013-09-25 15:27:29 -04:00
|
|
|
|
"Transcode a NODE-PROPERTY element into Markdown syntax.
|
|
|
|
|
CONTENTS is nil. INFO is a plist holding contextual
|
|
|
|
|
information."
|
|
|
|
|
(format "%s:%s"
|
|
|
|
|
(org-element-property :key node-property)
|
|
|
|
|
(let ((value (org-element-property :value node-property)))
|
|
|
|
|
(if value (concat " " value) ""))))
|
|
|
|
|
|
|
|
|
|
|
2012-07-25 17:04:36 -04:00
|
|
|
|
;;;; Paragraph
|
|
|
|
|
|
2015-10-31 19:05:22 -04:00
|
|
|
|
(defun org-md-paragraph (paragraph contents _info)
|
2012-07-25 17:04:36 -04:00
|
|
|
|
"Transcode PARAGRAPH element into Markdown format.
|
|
|
|
|
CONTENTS is the paragraph contents. INFO is a plist used as
|
|
|
|
|
a communication channel."
|
2012-07-27 08:05:44 -04:00
|
|
|
|
(let ((first-object (car (org-element-contents paragraph))))
|
|
|
|
|
;; If paragraph starts with a #, protect it.
|
2016-09-02 21:05:10 -04:00
|
|
|
|
(if (and (stringp first-object) (string-prefix-p "#" first-object))
|
|
|
|
|
(concat "\\" contents)
|
2012-07-27 08:05:44 -04:00
|
|
|
|
contents)))
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Plain List
|
|
|
|
|
|
2015-10-31 19:05:22 -04:00
|
|
|
|
(defun org-md-plain-list (_plain-list contents _info)
|
2012-07-25 17:04:36 -04:00
|
|
|
|
"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 18:36:00 -04:00
|
|
|
|
(when (plist-get info :with-smart-quotes)
|
|
|
|
|
(setq text (org-export-activate-smart-quotes text :html info)))
|
2017-12-20 13:01:06 -05:00
|
|
|
|
;; The below series of replacements in `text' is order sensitive.
|
|
|
|
|
;; Protect `, *, _, and \
|
|
|
|
|
(setq text (replace-regexp-in-string "[`*_\\]" "\\\\\\&" text))
|
2012-07-27 08:05:44 -04: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 17:04:36 -04:00
|
|
|
|
;; Protect ambiguous !
|
|
|
|
|
(setq text (replace-regexp-in-string "\\(!\\)\\[" "\\\\!" text nil nil 1))
|
|
|
|
|
;; Handle special strings, if required.
|
|
|
|
|
(when (plist-get info :with-special-strings)
|
2013-01-27 17:11:34 -05:00
|
|
|
|
(setq text (org-html-convert-special-strings text)))
|
2012-07-25 17:04:36 -04: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)
|
|
|
|
|
|
|
|
|
|
|
2013-09-25 15:27:29 -04:00
|
|
|
|
;;;; Property Drawer
|
|
|
|
|
|
2015-10-31 19:05:22 -04:00
|
|
|
|
(defun org-md-property-drawer (_property-drawer contents _info)
|
2013-09-25 15:27:29 -04:00
|
|
|
|
"Transcode a PROPERTY-DRAWER element into Markdown format.
|
|
|
|
|
CONTENTS holds the contents of the drawer. INFO is a plist
|
|
|
|
|
holding contextual information."
|
|
|
|
|
(and (org-string-nw-p contents)
|
|
|
|
|
(replace-regexp-in-string "^" " " contents)))
|
|
|
|
|
|
|
|
|
|
|
2012-07-25 17:04:36 -04:00
|
|
|
|
;;;; Quote Block
|
|
|
|
|
|
2015-10-31 19:05:22 -04:00
|
|
|
|
(defun org-md-quote-block (_quote-block contents _info)
|
2012-07-25 17:04:36 -04:00
|
|
|
|
"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
|
|
|
|
|
|
2015-10-31 19:05:22 -04:00
|
|
|
|
(defun org-md-section (_section contents _info)
|
2012-07-25 17:04:36 -04:00
|
|
|
|
"Transcode SECTION element into Markdown format.
|
|
|
|
|
CONTENTS is the section contents. INFO is a plist used as
|
|
|
|
|
a communication channel."
|
2012-07-27 08:43:12 -04:00
|
|
|
|
contents)
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Template
|
|
|
|
|
|
2014-01-21 17:35:34 -05:00
|
|
|
|
(defun org-md-inner-template (contents info)
|
|
|
|
|
"Return body of document after converting it to Markdown syntax.
|
|
|
|
|
CONTENTS is the transcoded contents string. INFO is a plist
|
|
|
|
|
holding export options."
|
|
|
|
|
;; Make sure CONTENTS is separated from table of contents and
|
|
|
|
|
;; footnotes with at least a blank line.
|
2016-08-22 04:48:57 -04:00
|
|
|
|
(concat
|
|
|
|
|
;; Table of contents.
|
|
|
|
|
(let ((depth (plist-get info :with-toc)))
|
2017-03-11 09:21:27 -05:00
|
|
|
|
(when depth
|
|
|
|
|
(concat (org-md--build-toc info (and (wholenump depth) depth)) "\n")))
|
2016-08-22 04:48:57 -04:00
|
|
|
|
;; Document contents.
|
|
|
|
|
contents
|
|
|
|
|
"\n"
|
|
|
|
|
;; Footnotes section.
|
2016-09-02 20:26:45 -04:00
|
|
|
|
(org-md--footnote-section info)))
|
2014-01-21 17:35:34 -05:00
|
|
|
|
|
2015-10-31 19:05:22 -04:00
|
|
|
|
(defun org-md-template (contents _info)
|
2012-07-25 17:04:36 -04:00
|
|
|
|
"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 11:24:19 -05:00
|
|
|
|
(defun org-md-export-as-markdown (&optional async subtreep visible-only)
|
2013-03-07 10:31:24 -05:00
|
|
|
|
"Export current buffer to a Markdown buffer.
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
|
|
|
|
If narrowing is active in the current buffer, only export its
|
|
|
|
|
narrowed part.
|
|
|
|
|
|
|
|
|
|
If a region is active, export that region.
|
|
|
|
|
|
2012-12-02 11:24:19 -05: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 17:04:36 -04: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 08:51:45 -04: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 17:04:36 -04:00
|
|
|
|
(interactive)
|
Export back-ends: Apply changes to export functions
* contrib/lisp/ox-confluence.el (org-confluence-export-as-confluence):
* contrib/lisp/ox-deck.el (org-deck-export-as-html,
org-deck-export-to-html):
* contrib/lisp/ox-freemind.el (org-freemind-export-to-freemind):
* contrib/lisp/ox-groff.el (org-groff-export-to-groff,
org-groff-export-to-pdf):
* contrib/lisp/ox-koma-letter.el (org-koma-letter-export-as-latex,
org-koma-letter-export-to-latex, org-koma-letter-export-to-pdf):
* contrib/lisp/ox-rss.el (org-rss-export-as-rss,
org-rss-export-to-rss):
* contrib/lisp/ox-s5.el (org-s5-export-as-html,
org-s5-export-to-html):
* contrib/lisp/ox-taskjuggler.el (org-taskjuggler-export):
* lisp/ob-haskell.el:
* lisp/ox-ascii.el (org-ascii-export-as-ascii,
org-ascii-export-to-ascii):
* lisp/ox-beamer.el (org-beamer-export-as-latex,
org-beamer-export-to-latex, org-beamer-export-to-pdf):
* lisp/ox-html.el (org-html-export-as-html, org-html-export-to-html):
* lisp/ox-icalendar.el (org-icalendar-export-to-ics):
* lisp/ox-latex.el (org-latex-export-as-latex,
org-latex-export-to-pdf):
* lisp/ox-man.el (org-man-export-to-man, org-man-export-to-pdf):
* lisp/ox-md.el (org-md-export-as-markdown,
org-md-export-to-markdown):
* lisp/ox-odt.el (org-odt-export-to-odt):
* lisp/ox-org.el (org-org-export-as-org, org-org-export-to-org):
* lisp/ox-publish.el (org-publish-org-to):
* lisp/ox-texinfo.el (org-texinfo-export-to-texinfo,
org-texinfo-export-to-info):
* testing/lisp/test-ob-exp.el (test-ob-exp/org-babel-exp-src-blocks/w-no-file):
2013-08-07 04:35:42 -04:00
|
|
|
|
(org-export-to-buffer 'md "*Org MD Export*"
|
|
|
|
|
async subtreep visible-only nil nil (lambda () (text-mode))))
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
2013-04-06 13:09:38 -04:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun org-md-convert-region-to-md ()
|
2016-08-23 16:13:56 -04:00
|
|
|
|
"Assume the current region has Org syntax, and convert it to Markdown.
|
2013-04-06 13:09:38 -04:00
|
|
|
|
This can be used in any buffer. For example, you can write an
|
2016-08-23 16:13:56 -04:00
|
|
|
|
itemized list in Org syntax in a Markdown buffer and use
|
2013-04-06 13:09:38 -04:00
|
|
|
|
this command to convert it."
|
|
|
|
|
(interactive)
|
|
|
|
|
(org-export-replace-region-by 'md))
|
|
|
|
|
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
2012-12-02 11:24:19 -05:00
|
|
|
|
(defun org-md-export-to-markdown (&optional async subtreep visible-only)
|
2012-07-25 17:04:36 -04: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 11:24:19 -05: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 17:04:36 -04: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 15:52:43 -05:00
|
|
|
|
(let ((outfile (org-export-output-file-name ".md" subtreep)))
|
Export back-ends: Apply changes to export functions
* contrib/lisp/ox-confluence.el (org-confluence-export-as-confluence):
* contrib/lisp/ox-deck.el (org-deck-export-as-html,
org-deck-export-to-html):
* contrib/lisp/ox-freemind.el (org-freemind-export-to-freemind):
* contrib/lisp/ox-groff.el (org-groff-export-to-groff,
org-groff-export-to-pdf):
* contrib/lisp/ox-koma-letter.el (org-koma-letter-export-as-latex,
org-koma-letter-export-to-latex, org-koma-letter-export-to-pdf):
* contrib/lisp/ox-rss.el (org-rss-export-as-rss,
org-rss-export-to-rss):
* contrib/lisp/ox-s5.el (org-s5-export-as-html,
org-s5-export-to-html):
* contrib/lisp/ox-taskjuggler.el (org-taskjuggler-export):
* lisp/ob-haskell.el:
* lisp/ox-ascii.el (org-ascii-export-as-ascii,
org-ascii-export-to-ascii):
* lisp/ox-beamer.el (org-beamer-export-as-latex,
org-beamer-export-to-latex, org-beamer-export-to-pdf):
* lisp/ox-html.el (org-html-export-as-html, org-html-export-to-html):
* lisp/ox-icalendar.el (org-icalendar-export-to-ics):
* lisp/ox-latex.el (org-latex-export-as-latex,
org-latex-export-to-pdf):
* lisp/ox-man.el (org-man-export-to-man, org-man-export-to-pdf):
* lisp/ox-md.el (org-md-export-as-markdown,
org-md-export-to-markdown):
* lisp/ox-odt.el (org-odt-export-to-odt):
* lisp/ox-org.el (org-org-export-as-org, org-org-export-to-org):
* lisp/ox-publish.el (org-publish-org-to):
* lisp/ox-texinfo.el (org-texinfo-export-to-texinfo,
org-texinfo-export-to-info):
* testing/lisp/test-ob-exp.el (test-ob-exp/org-babel-exp-src-blocks/w-no-file):
2013-08-07 04:35:42 -04:00
|
|
|
|
(org-export-to-file 'md outfile async subtreep visible-only)))
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
2013-09-25 02:53:59 -04:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun org-md-publish-to-md (plist filename pub-dir)
|
|
|
|
|
"Publish an org file to Markdown.
|
|
|
|
|
|
|
|
|
|
FILENAME is the filename of the Org file to be published. PLIST
|
|
|
|
|
is the property list for the given project. PUB-DIR is the
|
|
|
|
|
publishing directory.
|
|
|
|
|
|
|
|
|
|
Return output file name."
|
|
|
|
|
(org-publish-org-to 'md filename ".md" plist pub-dir))
|
2012-07-25 17:04:36 -04:00
|
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
|
(provide 'ox-md)
|
|
|
|
|
|
|
|
|
|
;; Local variables:
|
|
|
|
|
;; generated-autoload-file: "org-loaddefs.el"
|
|
|
|
|
;; End:
|
|
|
|
|
|
|
|
|
|
;;; ox-md.el ends here
|