org-capture.el (org-capture): Don't store multiple links over lines in the active...
[org-mode.git] / lisp / ox-org.el
blob7cb90c29be3545b39ceefb1b48297d0412ffbcbf
1 ;;; ox-org.el --- Org Back-End for Org Export Engine
3 ;; Copyright (C) 2013 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou@gmail.com>
6 ;; Keywords: org, wp
8 ;; GNU Emacs is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21 ;;; Commentary:
23 ;; This library implements an Org back-end for Org exporter. Since
24 ;; its usage is mainly internal, it doesn't provide any interactive
25 ;; function.
27 ;;; Code:
28 (require 'ox)
29 (declare-function htmlize-buffer "htmlize" (&optional buffer))
31 (defgroup org-export-org nil
32 "Options for exporting Org mode files to Org."
33 :tag "Org Export Org"
34 :group 'org-export
35 :version "24.4"
36 :package-version '(Org . "8.0"))
38 (define-obsolete-variable-alias
39 'org-export-htmlized-org-css-url 'org-org-htmlized-css-url "24.4")
40 (defcustom org-org-htmlized-css-url nil
41 "URL pointing to the CSS defining colors for htmlized Emacs buffers.
42 Normally when creating an htmlized version of an Org buffer,
43 htmlize will create the CSS to define the font colors. However,
44 this does not work when converting in batch mode, and it also can
45 look bad if different people with different fontification setup
46 work on the same website. When this variable is non-nil,
47 creating an htmlized version of an Org buffer using
48 `org-org-export-as-org' will include a link to this URL if the
49 setting of `org-html-htmlize-output-type' is 'css."
50 :group 'org-export-org
51 :type '(choice
52 (const :tag "Don't include external stylesheet link" nil)
53 (string :tag "URL or local href")))
55 (org-export-define-backend 'org
56 '((babel-call . org-org-identity)
57 (bold . org-org-identity)
58 (center-block . org-org-identity)
59 (clock . org-org-identity)
60 (code . org-org-identity)
61 (comment . (lambda (&rest args) ""))
62 (comment-block . (lambda (&rest args) ""))
63 (diary-sexp . org-org-identity)
64 (drawer . org-org-identity)
65 (dynamic-block . org-org-identity)
66 (entity . org-org-identity)
67 (example-block . org-org-identity)
68 (fixed-width . org-org-identity)
69 (footnote-definition . org-org-identity)
70 (footnote-reference . org-org-identity)
71 (headline . org-org-headline)
72 (horizontal-rule . org-org-identity)
73 (inline-babel-call . org-org-identity)
74 (inline-src-block . org-org-identity)
75 (inlinetask . org-org-identity)
76 (italic . org-org-identity)
77 (item . org-org-identity)
78 (keyword . org-org-keyword)
79 (latex-environment . org-org-identity)
80 (latex-fragment . org-org-identity)
81 (line-break . org-org-identity)
82 (link . org-org-identity)
83 (node-property . org-org-identity)
84 (paragraph . org-org-identity)
85 (plain-list . org-org-identity)
86 (planning . org-org-identity)
87 (property-drawer . org-org-identity)
88 (quote-block . org-org-identity)
89 (quote-section . org-org-identity)
90 (radio-target . org-org-identity)
91 (section . org-org-identity)
92 (special-block . org-org-identity)
93 (src-block . org-org-identity)
94 (statistics-cookie . org-org-identity)
95 (strike-through . org-org-identity)
96 (subscript . org-org-identity)
97 (superscript . org-org-identity)
98 (table . org-org-identity)
99 (table-cell . org-org-identity)
100 (table-row . org-org-identity)
101 (target . org-org-identity)
102 (timestamp . org-org-identity)
103 (underline . org-org-identity)
104 (verbatim . org-org-identity)
105 (verse-block . org-org-identity)))
107 (defun org-org-identity (blob contents info)
108 "Transcode BLOB element or object back into Org syntax."
109 (funcall
110 (intern (format "org-element-%s-interpreter" (org-element-type blob)))
111 blob contents))
113 (defun org-org-headline (headline contents info)
114 "Transcode HEADLINE element back into Org syntax."
115 (unless (plist-get info :with-todo-keywords)
116 (org-element-put-property headline :todo-keyword nil))
117 (unless (plist-get info :with-tags)
118 (org-element-put-property headline :tags nil))
119 (unless (plist-get info :with-priority)
120 (org-element-put-property headline :priority nil))
121 (org-element-headline-interpreter headline contents))
123 (defun org-org-keyword (keyword contents info)
124 "Transcode KEYWORD element back into Org syntax.
125 Ignore keywords targeted at other export back-ends."
126 (unless (member (org-element-property :key keyword)
127 (mapcar
128 (lambda (block-cons)
129 (and (eq (cdr block-cons) 'org-element-export-block-parser)
130 (car block-cons)))
131 org-element-block-name-alist))
132 (org-element-keyword-interpreter keyword nil)))
134 ;;;###autoload
135 (defun org-org-publish-to-org (plist filename pub-dir)
136 "Publish an org file to org.
138 FILENAME is the filename of the Org file to be published. PLIST
139 is the property list for the given project. PUB-DIR is the
140 publishing directory.
142 Return output file name."
143 (org-publish-org-to 'org filename ".org" plist pub-dir)
144 (when (plist-get plist :htmlized-source)
145 (require 'htmlize)
146 (require 'ox-html)
147 (let* ((org-inhibit-startup t)
148 (htmlize-output-type 'css)
149 (visitingp (find-buffer-visiting filename))
150 (work-buffer (or visitingp (find-file filename)))
151 newbuf)
152 (font-lock-fontify-buffer)
153 (setq newbuf (htmlize-buffer))
154 (with-current-buffer newbuf
155 (when org-org-htmlized-css-url
156 (goto-char (point-min))
157 (and (re-search-forward
158 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*" nil t)
159 (replace-match
160 (format
161 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
162 org-org-htmlized-css-url) t t)))
163 (write-file (concat pub-dir (file-name-nondirectory filename) ".html")))
164 (kill-buffer newbuf)
165 (unless visitingp (kill-buffer work-buffer)))
166 (set-buffer-modified-p nil)))
168 (provide 'ox-org)
170 ;; Local variables:
171 ;; generated-autoload-file: "org-loaddefs.el"
172 ;; End:
174 ;;; ox-org.el ends here