From de39ac51ee5fa32da6fbc95c6a7f7d12938ec632 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Fri, 9 May 2008 13:38:01 +0200 Subject: [PATCH] Improve running htmlize.el in batch-mode. --- lisp/ChangeLog | 8 ++++++ lisp/org-exp.el | 76 +++++++++++++++++++++++++++++++++++++++++++++---- lisp/org.el | 2 +- 3 files changed, 80 insertions(+), 6 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 7c353be20..5575a0128 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2008-05-09 Carsten Dominik + + * org-exp.el (org-export-htmlize): New group. + (org-export-htmlize-output-type) + (org-export-htmlize-css-font-prefix): New options. + (org-export-htmlize-region-for-paste): New function. + (org-export-htmlize-generate-css): New command. + 2008-05-08 Carsten Dominik * org.el (org-set-visibility-according-to-property): New function. diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 6247bf104..1f9f38883 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -33,6 +33,8 @@ (declare-function org-export-latex-preprocess "org-export-latex" ()) (declare-function org-agenda-skip "org-agenda" ()) (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ()) +(declare-function htmlize-region "ext:htmlize" (beg end)) +(defvar htmlize-buffer-places) ; from htmlize.el (defgroup org-export nil "Options for exporting org-listings." @@ -569,6 +571,24 @@ to a file." :group 'org-export-html :type 'string) +(defgroup org-export-htmlize nil + "Options for processing examples with htmlize.el." + :tag "Org Export Htmlize" + :group 'org-export-html) + +(defcustom org-export-htmlize-output-type 'inline-css + "Output type to be used by htmlize when formatting code snippets. +Normally this is `inline-css', but if you have defined to appropriate +classes in your css style file, setting this to `css' means that the +fontification will use appropriate class names." + :group 'org-export-htmlize + :type '(choice (const css) (const inline-css))) + +(defcustom org-export-htmlize-css-font-prefix "org-" + "The prefix for CSS class names for htmlize font specifications." + :group 'org-export-htmlize + :type 'string) + (defgroup org-export-icalendar nil "Options specific for iCalendar export of Org-mode files." :tag "Org Export iCalendar" @@ -1665,10 +1685,8 @@ backends, it converts the segment into an EXAMPLE segment." (funcall mode) (fundamental-mode)) (font-lock-fontify-buffer) - ;; silence the byte-compiler - (when (fboundp 'htmlize-region-for-paste) - ;; transform the region to HTML - (htmlize-region-for-paste (point-min) (point-max)))))) + (org-export-htmlize-region-for-paste + (point-min) (point-max))))) (if (string-match "]*\\)>\n?" htmltext) (setq htmltext (replace-match "
"
 					    t t htmltext)))
@@ -1678,7 +1696,7 @@ backends, it converts the segment into an EXAMPLE segment."
       (concat "#+BEGIN_EXAMPLE\n" code
 	      (if (string-match "\n\\'" code) "" "\n")
 	      "#+END_EXAMPLE\n")))))
-  
+
 ;;; ASCII export
 
 (defvar org-last-level nil) ; dynamically scoped variable
@@ -3264,6 +3282,52 @@ But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
 	  (setq r (concat r "@
"))) r)))) +(defun org-export-htmlize-region-for-paste (beg end) + "Convert the region to HTML, using htmlize.el. +This is much like `htmlize-region-for-paste', only that it uses +the settings define in the org-... variables." + (let* ((htmlize-output-type 'css) + (htmlize-css-name-prefix org-export-htmlize-css-font-prefix) + (htmlbuf (htmlize-region beg end))) + (unwind-protect + (with-current-buffer htmlbuf + (buffer-substring (plist-get htmlize-buffer-places 'content-start) + (plist-get htmlize-buffer-places 'content-end))) + (kill-buffer htmlbuf)))) + +(defun org-export-htmlize-generate-css () + "Create the CSS for all font definitions in the current Emacs session. +Use this to create face definitions in your CSS style file that can then +be used by code snippets transformed by htmlize. +This command just produces a buffer that contains class definitions for all +faces used in the current Emacs session. You can copy and paste the ones you +need into your CSS file. + +If you then set `org-export-htmlize-output-type' to `css', calls to +the function `org-export-htmlize-region-for-paste' will produce code +that uses these same face definitions." + (interactive) + (and (get-buffer "*html*") (kill-buffer "*html*")) + (with-temp-buffer + (let ((fl (face-list)) + (htmlize-css-name-prefix "org-") + (htmlize-output-type 'css) + f i) + (while (setq f (pop fl) + i (and f (face-attribute f :inherit))) + (when (and (symbolp f) (or (not i) (not (listp i)))) + (insert (org-add-props (copy-sequence "1") nil 'face f)))) + (htmlize-region (point-min) (point-max)))) + (switch-to-buffer "*html*") + (goto-char (point-min)) + (if (re-search-forward "" nil t) + (delete-region (1+ (match-end 0)) (point-max))) + (beginning-of-line 1) + (if (looking-at " +") (replace-match "")) + (goto-char (point-min))) + (defun org-html-protect (s) ;; convert & to &, < to < and > to > (let ((start 0)) @@ -3919,3 +3983,5 @@ The XOXO buffer is named *xoxo-*" ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95 ;;; org-exp.el ends here + + diff --git a/lisp/org.el b/lisp/org.el index 327f1fa91..2dd52a019 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -12161,7 +12161,7 @@ See the individual commands for more information." (cond ((org-at-table-p) (call-interactively 'org-table-previous-field)) ((integerp arg) - (message "Content view to level: " arg) + (message "Content view to level: %d" arg) (org-content (prefix-numeric-value arg)) (setq org-cycle-global-status 'overview)) (t (call-interactively 'org-global-cycle))))