ox-org.el 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. (defgroup org-export-org nil
  22. "Options for exporting Org mode files to Org."
  23. :tag "Org Export Org"
  24. :group 'org-export)
  25. (define-obsolete-variable-alias
  26. 'org-export-htmlized-org-css-url org-org-htmlized-css-url "24.4")
  27. (defcustom org-org-htmlized-css-url nil
  28. "URL pointing to the CSS defining colors for htmlized Emacs buffers.
  29. Normally when creating an htmlized version of an Org buffer,
  30. htmlize will create the CSS to define the font colors. However,
  31. this does not work when converting in batch mode, and it also can
  32. look bad if different people with different fontification setup
  33. work on the same website. When this variable is non-nil,
  34. creating an htmlized version of an Org buffer using
  35. `org-org-export-as-org' will include a link to this URL if the
  36. setting of `org-html-htmlize-output-type' is 'css."
  37. :group 'org-export-org
  38. :version "24.4"
  39. :package-version '(Org . "8.0")
  40. :type '(choice
  41. (const :tag "Don't include external stylesheet link" nil)
  42. (string :tag "URL or local href")))
  43. (org-export-define-backend org
  44. ((babel-call . org-org-identity)
  45. (bold . org-org-identity)
  46. (center-block . org-org-identity)
  47. (clock . org-org-identity)
  48. (code . org-org-identity)
  49. (comment . (lambda (&rest args) ""))
  50. (comment-block . (lambda (&rest args) ""))
  51. (diary-sexp . org-org-identity)
  52. (drawer . org-org-identity)
  53. (dynamic-block . org-org-identity)
  54. (entity . org-org-identity)
  55. (example-block . org-org-identity)
  56. (fixed-width . org-org-identity)
  57. (footnote-definition . org-org-identity)
  58. (footnote-reference . org-org-identity)
  59. (headline . org-org-headline)
  60. (horizontal-rule . org-org-identity)
  61. (inline-babel-call . org-org-identity)
  62. (inline-src-block . org-org-identity)
  63. (inlinetask . org-org-identity)
  64. (italic . org-org-identity)
  65. (item . org-org-identity)
  66. (keyword . org-org-keyword)
  67. (latex-environment . org-org-identity)
  68. (latex-fragment . org-org-identity)
  69. (line-break . org-org-identity)
  70. (link . org-org-identity)
  71. (node-property . org-org-identity)
  72. (paragraph . org-org-identity)
  73. (plain-list . org-org-identity)
  74. (planning . org-org-identity)
  75. (property-drawer . org-org-identity)
  76. (quote-block . org-org-identity)
  77. (quote-section . org-org-identity)
  78. (radio-target . org-org-identity)
  79. (section . org-org-identity)
  80. (special-block . org-org-identity)
  81. (src-block . org-org-identity)
  82. (statistics-cookie . org-org-identity)
  83. (strike-through . org-org-identity)
  84. (subscript . org-org-identity)
  85. (superscript . org-org-identity)
  86. (table . org-org-identity)
  87. (table-cell . org-org-identity)
  88. (table-row . org-org-identity)
  89. (target . org-org-identity)
  90. (timestamp . org-org-identity)
  91. (underline . org-org-identity)
  92. (verbatim . org-org-identity)
  93. (verse-block . org-org-identity)))
  94. (defun org-org-identity (blob contents info)
  95. "Transcode BLOB element or object back into Org syntax."
  96. (funcall
  97. (intern (format "org-element-%s-interpreter" (org-element-type blob)))
  98. blob contents))
  99. (defun org-org-headline (headline contents info)
  100. "Transcode HEADLINE element back into Org syntax."
  101. (unless (plist-get info :with-todo-keywords)
  102. (org-element-put-property headline :todo-keyword nil))
  103. (unless (plist-get info :with-tags)
  104. (org-element-put-property headline :tags nil))
  105. (unless (plist-get info :with-priority)
  106. (org-element-put-property headline :priority nil))
  107. (org-element-headline-interpreter headline contents))
  108. (defun org-org-keyword (keyword contents info)
  109. "Transcode KEYWORD element back into Org syntax.
  110. Ignore keywords targeted at other export back-ends."
  111. (unless (member (org-element-property :key keyword)
  112. (mapcar
  113. (lambda (block-cons)
  114. (and (eq (cdr block-cons) 'org-element-export-block-parser)
  115. (car block-cons)))
  116. org-element-block-name-alist))
  117. (org-element-keyword-interpreter keyword nil)))
  118. ;;;###autoload
  119. (defun org-org-publish-to-org (plist filename pub-dir)
  120. "Publish an org file to org.
  121. FILENAME is the filename of the Org file to be published. PLIST
  122. is the property list for the given project. PUB-DIR is the
  123. publishing directory.
  124. Return output file name."
  125. (org-publish-org-to 'org filename ".org" plist pub-dir)
  126. (when (plist-get plist :htmlized-source)
  127. (require 'htmlize)
  128. (require 'ox-html)
  129. (or (find-buffer-visiting filename)
  130. (find-file filename))
  131. (font-lock-fontify-buffer)
  132. (let* ((htmlize-output-type 'css)
  133. (newbuf (htmlize-buffer)))
  134. (with-current-buffer newbuf
  135. (when org-org-htmlized-css-url
  136. (goto-char (point-min))
  137. (and (re-search-forward
  138. "<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*" nil t)
  139. (replace-match
  140. (format
  141. "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
  142. org-org-htmlized-css-url) t t)))
  143. (write-file (concat pub-dir (file-name-nondirectory filename) ".html")))
  144. (kill-buffer newbuf))
  145. (set-buffer-modified-p nil)))
  146. (provide 'ox-org)
  147. ;; Local variables:
  148. ;; generated-autoload-file: "org-loaddefs.el"
  149. ;; End:
  150. ;;; ox-org.el ends here