emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Carsten Dominik <dominik@science.uva.nl>
To: Eric Schulte <schulte.eric@gmail.com>
Cc: Org-mode <emacs-orgmode@gnu.org>
Subject: Re: patch [Feature Addition] exporting comments on org files to html
Date: Thu, 6 Nov 2008 08:05:47 +0100	[thread overview]
Message-ID: <9AF18490-D824-4083-90A0-F616E213DB89@uva.nl> (raw)
In-Reply-To: <87wsfihdjr.fsf@gmail.com>

Hi Eric,

before adding this, I would like to investigate with you if selective  
export (section 12.2 of the manual) could maybe used to achieve pretty  
much the same goal, with the only limiting condition that the part  
treated as a switchable comment does structurally have to be a subtree.

Are you aware of selective export?  Maybe you could give us more  
detail about how you actually used this, and to what end?

- Carsten


On Nov 5, 2008, at 7:50 AM, Eric Schulte wrote:

> Hi,
>
> I have been co-authoring an org-mode file with a co-worker, and we
> started to put comments in org-blocks with the following format
>
> #+begin_comment ems example comment
> body of the comment
> - a list inside
> - of the comment
> #+end_comment
>
> I made the following additions to org-exp.el (patch attached) which
> allows the optional exportation of comment blocks through the use of a
> `block-comments' option line in the file header.
>
> #+OPTIONS:   comment-blocks:t
>
> Currently it only exports to html, and it styles the blocks using css
> (added to the org default html css styles).  It also adds id's to the
> comment divs which include the authors name, so it's possible to style
> the comments by their author (for example different colors by author).
> I used something like the following to style our comments (our  
> initials
> are wrg and ems).  I'm certainly no css expert, so I'm sure it's
> possible to get much nicer looking comment blocks.
>
> ,----[comment-style.css]
> | div#org-comment-wrg {
> |   background: #cdecf8;
> |   border: solid 1px #09abe7;
> |   padding: 0.5em;
> | }
> |
> | div#org-comment-ems {
> |   background: #d1fbaf;
> |   border: solid 1px #78ed19;
> |   padding: 0.5em;
> | }
> `----
>
> Here's the patch to org-exp.el.  I'd love to hear any
> ideas/issues/feedback.
>
> Cheers -- Eric
>
> 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; }
>  ]]>
> </style>"
>   "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"
> +	       "<div class=\"org-comment\" "
> +	       (if owner (format "id=\"org-comment-%s\" " owner))
> +	       ">\n"
> +	       (if owner (concat "<b>" owner "</b> ") "")
> +	       (if (and title (> (length title) 0)) (concat " -- " title  
> "</br>\n") "</br>\n")
> +	       "<p>\n"
> +	       "#+END_HTML\n"
> +	       body
> +	       "#+BEGIN_HTML\n"
> +	       "</p>\n"
> +	       "</div>\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
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

  reply	other threads:[~2008-11-06  7:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-05  6:50 patch [Feature Addition] exporting comments on org files to html Eric Schulte
2008-11-06  7:05 ` Carsten Dominik [this message]
2008-11-07  5:40   ` Eric Schulte
2008-11-07 19:02     ` modular block exportation was " Eric Schulte
2008-11-10  8:26       ` Carsten Dominik
2008-11-10 15:49         ` Eric Schulte
2008-11-12  2:03         ` Eric Schulte
2008-11-12  6:50           ` Carsten Dominik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9AF18490-D824-4083-90A0-F616E213DB89@uva.nl \
    --to=dominik@science.uva.nl \
    --cc=emacs-orgmode@gnu.org \
    --cc=schulte.eric@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).