diff --git a/doc/ChangeLog b/doc/ChangeLog index 390f113cb..2892ecc7e 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,9 @@ +2009-05-13 Carsten Dominik + + * org.texi (Publishing action): Mention the new publishing + function, to publish an Org source file. + (Publishing links): Mention how to link to an Org source file. + 2009-05-11 Carsten Dominik * org.texi (Macro replacement): Document new macros. diff --git a/doc/org.texi b/doc/org.texi index ca5510d6c..b3e1709b7 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -9279,8 +9279,14 @@ possibly transformed in the process. The default transformation is to export Org files as HTML files, and this is done by the function @code{org-publish-org-to-html} which calls the HTML exporter (@pxref{HTML export}). But you also can publish your as PDF files using -@code{org-publish-org-to-pdf}. Other files like images only need to be -copied to the publishing destination, for this you may use +@code{org-publish-org-to-pdf}. If you want to publish the Org file itself, +but with @i{archived}, @i{commented}, and @i{tag-excluded} trees removed, use +@code{org-publish-org-to-org} and set the parameters @code{:plain-source} +and/or @code{:htmlized-source}. This will produce @file{file.org} and +@file{file.org.html} in the publishing +directory@footnote{@file{file-source.org} and @file{file-source.org.html} if +source and publishing directories are equal.}. Other files like images only +need to be copied to the publishing destination, for this you may use @code{org-publish-attachment}. For non-Org files, you always need to provide specify the publishing function: @@ -9288,6 +9294,10 @@ specify the publishing function: @item @code{:publishing-function} @tab Function executing the publication of a file. This may also be a list of functions, which will all be called in turn. +@item @code{:plain-source} +@tab Non-nil means, publish plain source. +@item @code{:htmlized-source} +@tab Non-nil means, publish htmlized source. @end multitable The function must accept two arguments: a property list containing at least a @@ -9420,7 +9430,10 @@ something like @samp{[[file:foo.org][The foo]]} or simply @samp{file:foo.org.} (@pxref{Hyperlinks}). Upon publishing this link becomes a link to @file{foo.html}. In this way, you can interlink the pages of your "org web" project and the links will work as expected when -you publish them to HTML. +you publish them to HTML. If you also publish the Org source file and want +to link to that, use an @code{http:} link instead of an @code{file:} link, +because @code{file:} links are converted to link to the corresponding +@file{html} file. You may also link to related files, such as images. Provided you are careful with relative pathnames, and provided you have also configured Org to upload diff --git a/lisp/ChangeLog b/lisp/ChangeLog index bc0301bfa..f967316a0 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2009-05-13 Carsten Dominik + + * org-exp.el (org-export-as-org): New command. + (org-export-as-org): New command. + + * org-publish.el (org-publish-org-to-org): New function. + 2009-05-12 Carsten Dominik * org.el (org-yank): Just call `org-yank-generic'. diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 4e87a4fd4..65fe509db 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -2396,6 +2396,92 @@ command." (not (get-char-property s 'invisible)))) s)) +;;;###autoload +(defun org-export-as-org (arg &optional hidden ext-plist + to-buffer body-only pub-dir) + "Make a copy wiht not-exporting stuff removed. +The purpose of this function is to provide a way to export the source +Org file of a webpage in Org format, but with sensitive and/or irrelevant +stuff removed. This command will remove the following: + +- archived trees (if the variable `org-export-with-archived-trees' is nil) +- comment blocks and trees starting with the COMMENT keyword +- only trees that are consistent with `org-export-select-tags' + and `org-export-exclude-tags'. + +The only arguments that will be used are EXT-PLIST and PUB-DIR, +all the others will be ignored (but are present so that the general +mechanism to call publishing functions will work). + +EXT-PLIST is a property list with external parameters overriding +org-mode's default settings, but still inferior to file-local +settings. When PUB-DIR is set, use this as the publishing +directory." + (interactive "P") + (let* ((opt-plist (org-combine-plists (org-default-export-plist) + ext-plist + (org-infile-export-plist))) + (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer)))) + (filename (concat (file-name-as-directory + (or pub-dir + (org-export-directory :org opt-plist))) + (file-name-sans-extension + (file-name-nondirectory bfname)) + ".org")) + (filename (and filename + (if (equal (file-truename filename) + (file-truename bfname)) + (concat filename "-source") + filename))) + (backup-inhibited t) + (buffer (find-file-noselect filename)) + (region (buffer-string))) + (save-excursion + (switch-to-buffer buffer) + (erase-buffer) + (insert region) + (let ((org-inhibit-startup t)) (org-mode)) + + ;; Get rid of archived trees + (org-export-remove-archived-trees (plist-get opt-plist :archived-trees)) + + ;; Remove comment environment and comment subtrees + (org-export-remove-comment-blocks-and-subtrees) + + ;; Get rid of excluded trees + (org-export-handle-export-tags (plist-get opt-plist :select-tags) + (plist-get opt-plist :exclude-tags)) + + (when (or (plist-get opt-plist :plain-source) + (not (or (plist-get opt-plist :plain-source) + (plist-get opt-plist :htmlized-source)))) + ;; Either nothing special is requested (default call) + ;; or the plain source is explicitly requested + ;; so: save it + (save-buffer)) + (when (plist-get opt-plist :htmlized-source) + ;; Make the htmlized version + (require 'htmlize) + (require 'org-html) + (font-lock-fontify-buffer) + (let* ((htmlize-output-type 'css) + (newbuf (htmlize-buffer))) + (with-current-buffer newbuf + (when org-export-htmlized-org-css-url + (goto-char (point-min)) + (and (re-search-forward + ".*" + nil t) + (replace-match + (format + "" + org-export-htmlized-org-css-url) + t t))) + (write-file (concat filename ".html"))) + (kill-buffer newbuf))) + (set-buffer-modified-p nil) + (kill-buffer (current-buffer))))) + (defvar org-archive-location) ;; gets loaded with the org-archive require. (defun org-get-current-options () "Return a string with current options as keyword options. diff --git a/lisp/org-html.el b/lisp/org-html.el index 66450fe1a..ae87262a4 100644 --- a/lisp/org-html.el +++ b/lisp/org-html.el @@ -324,6 +324,20 @@ in all modes you want. Then, use the command :group 'org-export-htmlize :type 'string) +(defcustom org-export-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 remove the internal CSS section and replace it +with a link to this URL." + :group + :type '(choice + (const :tag "Keep internal css" nil) + (string :tag "URL or local href"))) + ;;; Variables, constants, and parameter plists (defvar org-export-html-preamble nil diff --git a/lisp/org-publish.el b/lisp/org-publish.el index 2e5e227e0..13114cf07 100644 --- a/lisp/org-publish.el +++ b/lisp/org-publish.el @@ -430,6 +430,11 @@ See `org-publish-org-to' to the list of arguments." See `org-publish-org-to' to the list of arguments." (org-publish-org-to "html" plist filename pub-dir)) +(defun org-publish-org-to-org (plist filename pub-dir) + "Publish an org file to HTML. +See `org-publish-org-to' to the list of arguments." + (org-publish-org-to "org" plist filename pub-dir)) + (defun org-publish-attachment (plist filename pub-dir) "Publish a file with no transformation of any kind. See `org-publish-org-to' to the list of arguments."