Browse Source

ox-org.el: Handle :htmlized-source in publishing projects

* ox-org.el (org-org-htmlized-css-url): Rename from
`org-html-htmlized-org-css-url' and moved here from
ox-html.el.
(org-org-publish-to-org): Handle :htmlized-source in
publishing projects.
Bastien Guerry 12 years ago
parent
commit
4351dda5ab
2 changed files with 45 additions and 16 deletions
  1. 0 15
      lisp/ox-html.el
  2. 45 1
      lisp/ox-org.el

+ 0 - 15
lisp/ox-html.el

@@ -712,21 +712,6 @@ in all modes you want.  Then, use the command
   :group 'org-export-html
   :type 'string)
 
-(defcustom org-html-htmlized-org-css-url nil
-  "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
-Normally when creating an htmlized version of an Org buffer, htmlize will
-create CSS to define the font colors.  However, this does not work when
-converting in batch mode, and it also can look bad if different people
-with different fontification setup work on the same website.
-When this variable is non-nil, creating an htmlized version of an Org buffer
-using `org-export-as-org' will include a link to this URL if the
-setting of `org-html-htmlize-output-type' is 'css."
-  :group 'org-export-html
-  :type '(choice
-	  (const :tag "Don't include external stylesheet link" nil)
-	  (string :tag "URL or local href")))
-
-
 ;;;; Table
 
 (defcustom org-html-table-tag

+ 45 - 1
lisp/ox-org.el

@@ -27,6 +27,30 @@
 ;;; Code:
 (require 'ox)
 
+(defgroup org-export-org nil
+  "Options for exporting Org mode files to Org."
+  :tag "Org Export Org"
+  :group 'org-export)
+
+(define-obsolete-variable-alias
+  'org-export-htmlized-org-css-url org-org-htmlized-css-url "24.4")
+(defcustom org-org-htmlized-css-url nil
+  "URL pointing to the CSS defining colors for htmlized Emacs buffers.
+Normally when creating an htmlized version of an Org buffer,
+htmlize will create the CSS to define the font colors.  However,
+this does not work when converting in batch mode, and it also can
+look bad if different people with different fontification setup
+work on the same website.  When this variable is non-nil,
+creating an htmlized version of an Org buffer using
+`org-org-export-as-org' will include a link to this URL if the
+setting of `org-html-htmlize-output-type' is 'css."
+  :group 'org-export-org
+  :version "24.4"
+  :package-version '(Org . "8.0")
+  :type '(choice
+	  (const :tag "Don't include external stylesheet link" nil)
+	  (string :tag "URL or local href")))
+
 (org-export-define-backend org
   ((babel-call . org-org-identity)
    (bold . org-org-identity)
@@ -115,7 +139,27 @@ is the property list for the given project.  PUB-DIR is the
 publishing directory.
 
 Return output file name."
-  (org-publish-org-to 'org filename ".org" plist pub-dir))
+  (org-publish-org-to 'org filename ".org" plist pub-dir)
+  (when (plist-get plist :htmlized-source)
+    (require 'htmlize)
+    (require 'ox-html)
+    (or (find-buffer-visiting filename)
+	(find-file filename))
+    (font-lock-fontify-buffer)
+    (let* ((htmlize-output-type 'css)
+	   (newbuf (htmlize-buffer)))
+      (with-current-buffer newbuf
+	(when org-org-htmlized-css-url
+	  (goto-char (point-min))
+	  (and (re-search-forward
+		"<style type=\"text/css\">[^\000]*?\n[ \t]*</style>.*" nil t)
+	       (replace-match
+		(format
+		 "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
+		 org-org-htmlized-css-url) t t)))
+	(write-file (concat pub-dir (file-name-nondirectory filename) ".html")))
+      (kill-buffer newbuf))
+    (set-buffer-modified-p nil)))
 
 (provide 'ox-org)