ox-html.el (org-html-display-buffer-mode): Delete
[org-mode.git] / lisp / ox-org.el
blob7f43c1d2860f38d020a22497cdcf9d265cf0d1da
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 (defcustom org-org-htmlized-css-url nil
39 "URL pointing to the CSS defining colors for htmlized Emacs buffers.
40 Normally when creating an htmlized version of an Org buffer,
41 htmlize will create the CSS to define the font colors. However,
42 this does not work when converting in batch mode, and it also can
43 look bad if different people with different fontification setup
44 work on the same website. When this variable is non-nil,
45 creating an htmlized version of an Org buffer using
46 `org-org-export-as-org' will include a link to this URL if the
47 setting of `org-html-htmlize-output-type' is 'css."
48 :group 'org-export-org
49 :type '(choice
50 (const :tag "Don't include external stylesheet link" nil)
51 (string :tag "URL or local href")))
52 (define-obsolete-variable-alias
53 'org-export-htmlized-org-css-url org-org-htmlized-css-url "24.4")
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 (or (find-buffer-visiting filename)
148 (find-file filename))
149 (font-lock-fontify-buffer)
150 (let* ((htmlize-output-type 'css)
151 (newbuf (htmlize-buffer)))
152 (with-current-buffer newbuf
153 (when org-org-htmlized-css-url
154 (goto-char (point-min))
155 (and (re-search-forward
156 "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*" nil t)
157 (replace-match
158 (format
159 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
160 org-org-htmlized-css-url) t t)))
161 (write-file (concat pub-dir (file-name-nondirectory filename) ".html")))
162 (kill-buffer newbuf))
163 (set-buffer-modified-p nil)))
165 (provide 'ox-org)
167 ;; Local variables:
168 ;; generated-autoload-file: "org-loaddefs.el"
169 ;; End:
171 ;;; ox-org.el ends here