ox-org.el 6.2 KB

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