diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 4be6b01..b3a848e 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -252,6 +252,11 @@ e.g. \"timestamp:nil\"." :group 'org-export-general :type 'boolean) +(defcustom org-export-comment-blocks nil + "If non-nil, export comment blocks" + :group 'org-export-general + :type 'boolean) + (defcustom org-export-with-tags 'not-in-toc "If nil, do not export tags, just remove them from headlines. If this is the symbol `not-in-toc', tags will be removed from table of @@ -519,6 +524,7 @@ Org-mode file." white-space:nowrap; } .org-info-js_search-highlight {background-color:#ffff00; color:#000000; font-weight:bold; } + .org-comment { background: #efefef; border: solid 1px; } ]]> " "The default style specification for exported HTML files. @@ -817,6 +823,7 @@ or if they are only using it locally." (:footnotes . org-export-with-footnotes) (:drawers . org-export-with-drawers) (:tags . org-export-with-tags) + (:comment-blocks . org-export-comment-blocks) (:TeX-macros . org-export-with-TeX-macros) (:LaTeX-fragments . org-export-with-LaTeX-fragments) (:skip-before-1st-heading . org-export-skip-text-before-1st-heading) @@ -962,7 +969,8 @@ modified) list.") ("skip" . :skip-before-1st-heading) ("author" . :author-info) ("creator" . :creator-info) - ("timestamp" . :time-stamp-file))) + ("timestamp" . :time-stamp-file) + ("comment-blocks" . :comment-blocks))) o) (while (setq o (pop op)) (if (string-match (concat (regexp-quote (car o)) @@ -1436,6 +1444,9 @@ on this string to produce the exported version." ;; Handle source code snippets (org-export-replace-src-segments) + + ;; Handle comment environment and comment subtrees + (org-export-handle-comment-blocks-and-subtrees (plist-get parameters :comment-blocks)) ;; Get rid of drawers (org-export-remove-or-extract-drawers drawers @@ -1478,10 +1489,6 @@ on this string to produce the exported version." ;; Blockquotes and verse (org-export-mark-blockquote-and-verse) - ;; Remove comment environment and comment subtrees - (org-export-remove-comment-blocks-and-subtrees) - - ;; Find matches for radio targets and turn them into internal links (org-export-mark-radio-links) @@ -1783,15 +1790,21 @@ These special cookies will later be interpreted by the backend." "ORG-VERSE-END" "ORG-VERSE-START") t t))) -(defun org-export-remove-comment-blocks-and-subtrees () - "Remove the comment environment, and also commented subtrees." +(defun org-export-handle-comment-blocks-and-subtrees (comment-blocks) + "Prepare comment blocks and comment subtrees for export. If +COMMENT-BLOCKS is non-nil then format comment blocks using +`org-export-format-comment', otherwise hide all comment blocks +during export. Hides all comment subtrees." (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>")) - (case-fold-search nil)) + (case-fold-search t)) ;; Remove comment environment (goto-char (point-min)) (while (re-search-forward - "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t) - (replace-match "" t t)) + "^#\\+begin_comment\\([ \t]+\\(\\S-+\\)\\)?[ \t]*\\(.*\\)?[\r\n]\\([^\000]*?\\)#\\+end_comment" + nil t) + (replace-match (if comment-blocks + (org-export-format-comment (match-string 4) (match-string 2) (match-string 3)) + "") t t)) ;; Remove subtrees that are commented (goto-char (point-min)) (while (re-search-forward re-commented nil t) @@ -2170,6 +2183,34 @@ backends, it converts the segment into an EXAMPLE segment." (if (string-match "\n\\'" code) "" "\n") "#+END_EXAMPLE\n"))))) +(defun org-export-format-comment (body &optional owner title) + "Format comment BODY by OWNER and return it formatted for export. +Currently, this only does something for HTML export, for all +other backends, it converts the comment into an EXAMPLE segment." + (save-match-data + (cond + (htmlp ;; We are exporting to HTML + (concat "#+BEGIN_HTML\n" + "
\n" + (if owner (concat "" owner " ") "") + (if (and title (> (length title) 0)) (concat " -- " title "
\n") "
\n") + "

\n" + "#+END_HTML\n" + body + "#+BEGIN_HTML\n" + "

\n" + "
\n" + "\n#+END_HTML\n")) + (t ;; This is not HTML, so just make it an example. + (concat "#+BEGIN_EXAMPLE\n" + (if title (concat "Title:" title "\n") "") + (if owner (concat "By:" owner "\n") "") + body + (if (string-match "\n\\'" body) "" "\n") + "#+END_EXAMPLE\n"))))) + ;;; ASCII export (defvar org-last-level nil) ; dynamically scoped variable @@ -2250,6 +2291,7 @@ underlined headlines. The default is 3." :verbatim-multiline t :select-tags (plist-get opt-plist :select-tags) :exclude-tags (plist-get opt-plist :exclude-tags) + :comment-blocks (plist-get opt-plist :comment-blocks) :archived-trees (plist-get opt-plist :archived-trees) :add-text (plist-get opt-plist :text)) @@ -2924,7 +2966,9 @@ PUB-DIR is set, use this as the publishing directory." :add-text (plist-get opt-plist :text) :LaTeX-fragments - (plist-get opt-plist :LaTeX-fragments)) + (plist-get opt-plist :LaTeX-fragments) + :comment-blocks + (plist-get opt-plist :comment-blocks)) "[\r\n]")) table-open type table-buffer table-orig-buffer