emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* # Comments export
@ 2022-05-28 14:58 Ypo
  2022-05-28 15:44 ` Timothy
  0 siblings, 1 reply; 13+ messages in thread
From: Ypo @ 2022-05-28 14:58 UTC (permalink / raw)
  To: Org-mode

[-- Attachment #1: Type: text/plain, Size: 238 bytes --]

Is it possible to export the (# comments)? I haven't seen that option in 
org export general customization.

I am making some (# comments) to texts, and I would like to export them 
when I export the subtree to HTML.


Best regards,

Ypo

[-- Attachment #2: Type: text/html, Size: 636 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: # Comments export
  2022-05-28 14:58 # Comments export Ypo
@ 2022-05-28 15:44 ` Timothy
  2022-05-28 15:58   ` Ypo
  0 siblings, 1 reply; 13+ messages in thread
From: Timothy @ 2022-05-28 15:44 UTC (permalink / raw)
  To: Ypo; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 169 bytes --]

Hi Ypo,

As I understand it, the whole point of comments is that they’re not exported.
Perhaps you’re looking for note blocks instead?

All the best,
Timothy

[-- Attachment #1.2: Type: text/html, Size: 3173 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: # Comments export
  2022-05-28 15:44 ` Timothy
@ 2022-05-28 15:58   ` Ypo
  2022-05-28 16:05     ` Timothy
  0 siblings, 1 reply; 13+ messages in thread
From: Ypo @ 2022-05-28 15:58 UTC (permalink / raw)
  To: Timothy; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 813 bytes --]

Thanks, Timothy

Do you mean blocks like #+BEGIN_COMMENT ?

Does that kind of blocks already exist?


https://i.ibb.co/xHJDgCR/Captura.jpg


Ypo

El 28/05/2022 a las 17:44, Timothy escribió:
>
> Hi Ypo,
>
> As I understand it, the whole point of comments is that they’re not 
> exported. Perhaps you’re looking for note blocks instead?
>
> All the best,
> *Timothy*
>
> *From*: Ypo <mailto:"Ypo" <ypuntot@gmail.com>>
> *Subject*: # Comments export
> *To*: Org-mode <mailto:"Org-mode" <emacs-orgmode@gnu.org>>
> *Date*: Sat, 28 May 2022 22:58:28 +0800
>
> Is it possible to export the (# comments)? I haven't seen that option 
> in org export general customization.
>
> I am making some (# comments) to texts, and I would like to export 
> them when I export the subtree to HTML.
>
>
> Best regards,
>
> Ypo
>

[-- Attachment #2: Type: text/html, Size: 4597 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: # Comments export
  2022-05-28 15:58   ` Ypo
@ 2022-05-28 16:05     ` Timothy
  2022-05-28 23:15       ` Samuel Wales
  0 siblings, 1 reply; 13+ messages in thread
From: Timothy @ 2022-05-28 16:05 UTC (permalink / raw)
  To: Ypo; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 184 bytes --]

Hi Ypo,

Well, `#+begin_comment' is for content you /don’t/ want exported, but if you want to
add a note to be included in exports, try `#+begin_note'.

All the best,
Timothy

[-- Attachment #1.2: Type: text/html, Size: 7618 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: # Comments export
  2022-05-28 16:05     ` Timothy
@ 2022-05-28 23:15       ` Samuel Wales
  2022-05-29  0:46         ` Ypo
  0 siblings, 1 reply; 13+ messages in thread
From: Samuel Wales @ 2022-05-28 23:15 UTC (permalink / raw)
  To: Timothy; +Cc: Ypo, emacs-orgmode

to op: do you mean to sometimes export comments and sometimes not?


On 5/28/22, Timothy <tecosaurus@gmail.com> wrote:
> Hi Ypo,
>
> Well, `#+begin_comment' is for content you /don’t/ want exported, but if you
> want to
> add a note to be included in exports, try `#+begin_note'.
>
> All the best,
> Timothy
>


-- 
The Kafka Pandemic

A blog about science, health, human rights, and misopathy:
https://thekafkapandemic.blogspot.com


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: # Comments export
  2022-05-28 23:15       ` Samuel Wales
@ 2022-05-29  0:46         ` Ypo
  2022-05-29  1:19           ` Ihor Radchenko
                             ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Ypo @ 2022-05-29  0:46 UTC (permalink / raw)
  To: Samuel Wales; +Cc: Timothy, emacs-orgmode

Hi, Timothy

I wanted to export my # comments so I could share my notes with more people, using HTML export. I would export all of them.

But, as it seems not possible, I think I will use footnotes. I liked # comments more, because their face can be customized and because they are nearer to the commented text (although footnotes can be moved manually wherever user wants to), # comments are like more "natural".

Best regards

29 may 2022 1:15:52 Samuel Wales <samologist@gmail.com>:

> to op: do you mean to sometimes export comments and sometimes not?
> 
> 
> On 5/28/22, Timothy <tecosaurus@gmail.com> wrote:
>> Hi Ypo,
>> 
>> Well, `#+begin_comment' is for content you /don’t/ want exported, but if you
>> want to
>> add a note to be included in exports, try `#+begin_note'.
>> 
>> All the best,
>> Timothy
>> 
> 
> 
> -- 
> The Kafka Pandemic
> 
> A blog about science, health, human rights, and misopathy:
> https://thekafkapandemic.blogspot.com


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: # Comments export
  2022-05-29  0:46         ` Ypo
@ 2022-05-29  1:19           ` Ihor Radchenko
  2022-05-29 11:33             ` Ypo
  2022-05-30  7:35           ` Eric S Fraga
  2022-06-02  6:24           ` Phil Estival
  2 siblings, 1 reply; 13+ messages in thread
From: Ihor Radchenko @ 2022-05-29  1:19 UTC (permalink / raw)
  To: Ypo; +Cc: Samuel Wales, Timothy, emacs-orgmode

Ypo <ypuntot@gmail.com> writes:

> I wanted to export my # comments so I could share my notes with more people, using HTML export. I would export all of them.
>
> But, as it seems not possible, I think I will use footnotes. I liked # comments more, because their face can be customized and because they are nearer to the commented text (although footnotes can be moved manually wherever user wants to), # comments are like more "natural".

It is actually possible, but you will need to write an
org-export-before-parsing-hook that will convert all the comments into
exportable elements.

Not tested, but the hook might be something like

(defun org-export-replace-comments (_)
"Replace all the comments with note blocks."
  (org-element-cache-map
   (lambda (comment)
     (setf (buffer-substring (org-element-property :begin comment) (org-element-property :end comment))
	   (format "#+begin_note\n%s\n#+end_node\n" (org-element-property :value comment))))
   :granularity 'element
   :restrict-elements '(comment)))

Best,
Ihor


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: # Comments export
  2022-05-29  1:19           ` Ihor Radchenko
@ 2022-05-29 11:33             ` Ypo
  2022-05-29 11:59               ` Ihor Radchenko
  0 siblings, 1 reply; 13+ messages in thread
From: Ypo @ 2022-05-29 11:33 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1224 bytes --]

Thanks for your effort, Ihor

But that code is so difficult for me, that I can barely understand it.

El 29/05/2022 a las 3:19, Ihor Radchenko escribió:
> Ypo<ypuntot@gmail.com>  writes:
>
>> I wanted to export my # comments so I could share my notes with more people, using HTML export. I would export all of them.
>>
>> But, as it seems not possible, I think I will use footnotes. I liked # comments more, because their face can be customized and because they are nearer to the commented text (although footnotes can be moved manually wherever user wants to), # comments are like more "natural".
> It is actually possible, but you will need to write an
> org-export-before-parsing-hook that will convert all the comments into
> exportable elements.
>
> Not tested, but the hook might be something like
>
> (defun org-export-replace-comments (_)
> "Replace all the comments with note blocks."
>    (org-element-cache-map
>     (lambda (comment)
>       (setf (buffer-substring (org-element-property :begin comment) (org-element-property :end comment))
> 	   (format "#+begin_note\n%s\n#+end_node\n" (org-element-property :value comment))))
>     :granularity 'element
>     :restrict-elements '(comment)))
>
> Best,
> Ihor

[-- Attachment #2: Type: text/html, Size: 1881 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: # Comments export
  2022-05-29 11:33             ` Ypo
@ 2022-05-29 11:59               ` Ihor Radchenko
  0 siblings, 0 replies; 13+ messages in thread
From: Ihor Radchenko @ 2022-05-29 11:59 UTC (permalink / raw)
  To: Ypo; +Cc: emacs-orgmode

Ypo <ypuntot@gmail.com> writes:

> Thanks for your effort, Ihor
>
> But that code is so difficult for me, that I can barely understand it.

Well. The basic idea is to go through the document right before
exporting and replace all the comments with some kind of exportable
environment. Below is the working code that you can try directly. The
code replaces comments with quote blocks. You might want to tweak
"#+begin_quote\n%s\n#+end_quote\n"
to something else if you want to customize how the comments are
exported. Just put %s where you want to put the comment text and do not
forget to leavee the trailing newline "\n". Hope it helps.

(defun org-export-replace-comments (_)
  "Replace all the comments with QUOTE blocks."
  (org-with-wide-buffer
   ;; Search the all the comments in temporary export buffer.
   (goto-char (point-min))
   (while (re-search-forward org-comment-regexp nil t)
     (let ((comment (org-element-at-point)))
       ;; We just called Org parser to determine the syntactic element at point.
       (when (eq 'comment (org-element-type comment))
	 ;; The current element is really comment. Replace its contents with
	 ;; QUOTE block. `setf' here is replacing buffer region defined by
	 ;; `buffer-substring' with new string containing the QUOTE block.
	 (setf (buffer-substring (org-element-property :begin comment)
				 (org-element-property :end comment))
               (format "#+begin_quote\n%s\n#+end_quote\n"
		       (org-element-property :value comment))))))))
(add-hook 'org-export-before-parsing-hook #'org-export-replace-comments)

Best,
Ihor


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: # Comments export
  2022-05-29  0:46         ` Ypo
  2022-05-29  1:19           ` Ihor Radchenko
@ 2022-05-30  7:35           ` Eric S Fraga
  2022-05-30 10:46             ` Juan Manuel Macías
  2022-06-02  6:24           ` Phil Estival
  2 siblings, 1 reply; 13+ messages in thread
From: Eric S Fraga @ 2022-05-30  7:35 UTC (permalink / raw)
  To: Ypo; +Cc: Samuel Wales, Timothy, emacs-orgmode

On Sunday, 29 May 2022 at 00:46, Ypo wrote:
> I wanted to export my #comments so I could share my notes with more
> people, using HTML export. I would export all of them.

I use drawers for this and then have specific processing of different
types of drawers, depending on target.

For instance, I might have :note: drawers (similar to inline tasks) with
the following processing (for odt export; similar for LaTeX):

--8<---------------cut here---------------start------------->8---
(setq-local org-odt-format-drawer-function
            (lambda (name contents)
              (if (string= name "note")
                  (progn
                    (format "<text:span text:background=\"#FFFF00\">%s</text:span>" contents)))))
--8<---------------cut here---------------end--------------->8---

(progn because I used to do more in there...)

-- 
: Eric S Fraga, with org release_9.5.3-511-g8e69ad in Emacs 29.0.50


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: # Comments export
  2022-05-30  7:35           ` Eric S Fraga
@ 2022-05-30 10:46             ` Juan Manuel Macías
  2022-05-30 21:49               ` Tim Cross
  0 siblings, 1 reply; 13+ messages in thread
From: Juan Manuel Macías @ 2022-05-30 10:46 UTC (permalink / raw)
  To: Eric S Fraga; +Cc: orgmode

Eric S Fraga writes:

> I use drawers for this and then have specific processing of different
> types of drawers, depending on target.
>
> For instance, I might have :note: drawers (similar to inline tasks) with
> the following processing (for odt export; similar for LaTeX):
>
> --8<---------------cut here---------------start------------->8---
> (setq-local org-odt-format-drawer-function
>             (lambda (name contents)
>               (if (string= name "note")
>                   (progn
>                     (format "<text:span text:background=\"#FFFF00\">%s</text:span>" contents)))))
> --8<---------------cut here---------------end--------------->8---
>
> (progn because I used to do more in there...)

I use a special type of footnote, which is exported to LaTeX as pdf
annotations (with the pdfannotate package) and to odt as comments. The
use of footnotes allows me to put comments and annotations within the
paragraph:

https://list.orgmode.org/877de55cjf.fsf@posteo.net/

Best regards,

Juan Manuel 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: # Comments export
  2022-05-30 10:46             ` Juan Manuel Macías
@ 2022-05-30 21:49               ` Tim Cross
  0 siblings, 0 replies; 13+ messages in thread
From: Tim Cross @ 2022-05-30 21:49 UTC (permalink / raw)
  To: emacs-orgmode


Juan Manuel Macías <maciaschain@posteo.net> writes:

> Eric S Fraga writes:
>
>> I use drawers for this and then have specific processing of different
>> types of drawers, depending on target.
>>
>> For instance, I might have :note: drawers (similar to inline tasks) with
>> the following processing (for odt export; similar for LaTeX):
>>
>> --8<---------------cut here---------------start------------->8---
>> (setq-local org-odt-format-drawer-function
>>             (lambda (name contents)
>>               (if (string= name "note")
>>                   (progn
>>                     (format "<text:span text:background=\"#FFFF00\">%s</text:span>" contents)))))
>> --8<---------------cut here---------------end--------------->8---
>>
>> (progn because I used to do more in there...)
>
> I use a special type of footnote, which is exported to LaTeX as pdf
> annotations (with the pdfannotate package) and to odt as comments. The
> use of footnotes allows me to put comments and annotations within the
> paragraph:
>
> https://list.orgmode.org/877de55cjf.fsf@posteo.net/
>

I think this is a much better solution. I don't like the idea of adding
the ability to export comments - the whole point of comments are to
provide content which is NOT exported. If you find you have content as
comments which you then want to export, my view would be that these are
not 'comments' in the sense of org-mode. These sound like notes or
annotations and there is likely a better approach than treating them as
org comments. Org comments are probably best thought of as comments
about org content and not org content per se. If you want your comments
to appear as part of yhour exported data at some level, they are no
longer comments, but rather a different class of content and should be
categorised using one of the org content block types or a footnote. 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: # Comments export
  2022-05-29  0:46         ` Ypo
  2022-05-29  1:19           ` Ihor Radchenko
  2022-05-30  7:35           ` Eric S Fraga
@ 2022-06-02  6:24           ` Phil Estival
  2 siblings, 0 replies; 13+ messages in thread
From: Phil Estival @ 2022-06-02  6:24 UTC (permalink / raw)
  To: Ypo, Samuel Wales; +Cc: Timothy, emacs-orgmode


On 29/05/2022 à 02:46, Ypo wrote:
 >
 > I wanted to export my # comments so I could
 > share my notes with more people, using HTML
 > export. I would export all of them.
 >

Ypo,

As it is very close to what you're asking,
here I'm suggesting how to export # comments in org,
as <!-- comments --> to the HTML
and % comments to the latex backends.

Modifying Org sources instead of providing a
peripheral mechanism may be considered as
unorthodox, but it's not difficult at all and
the modifications to remove the censorship over
comments are small.


ox.el: add a customization option to export comments

#+begin_src elisp
(defcustom org-export--with-comments nil
   "Non-nil means provides comments to the backends"
   :group 'org-export-general
   :type 'boolean
   :safe #'booleanp)
#+end_src

Let comments flow to exporters when this option is active

#+begin_src elisp
(defun org-export--skip-p (datum options selected excluded)
   [...]
     (cl-case (org-element-type datum)
     ((comment comment-block)
      (if org-export--with-comments nil ;; do not skip comments and 
comment blocks.
        ;; Skip all comments and comment blocks.  Make to keep maximum
        ;; number of blank lines around the comment so as to preserve
        ;; local structure of the document upon interpreting it back into
        ;; Org syntax.
        (let* ((previous (org-export-get-previous-element datum options))
            (before (or (org-element-property :post-blank previous) 0))
            (after (or (org-element-property :post-blank datum) 0)))
           (when previous
         (org-element-put-property previous :post-blank (max before 
after 0)))
         t)))
     [...]
#+end_src


ox-html.el: modify the backend derivation to add a comment transcoder

#+begin_src elisp
(org-export-define-backend 'html
   '(...
     (clock . org-html-clock)
     (code . org-html-code)
     (comment . org-html-comment)
     ...
#+end_src

ox-html.el: declare the additional transcoder:

#+begin_src elisp

;;;; Comment
(defun org-html-comment (comment _contents info)
   "Transcode COMMENT from Org to HTML.
CONTENTS is nil.  INFO is a plist holding contextual
information."
   (concat "<!-- " (org-element-property :value comment)))

#+end_src

Here it is for latex too
ox-latex.el:

#+begin_src elisp

;;;; Comment
(defun org-latex-comment (comment _contents info)
   "Transcode COMMENT from Org to latex.
CONTENTS is nil.  INFO is a plist holding contextual
information."
   (concat "% " (org-element-property :value comment)))

#+end_src


Best regards,

Phil





^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-06-02  6:25 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-28 14:58 # Comments export Ypo
2022-05-28 15:44 ` Timothy
2022-05-28 15:58   ` Ypo
2022-05-28 16:05     ` Timothy
2022-05-28 23:15       ` Samuel Wales
2022-05-29  0:46         ` Ypo
2022-05-29  1:19           ` Ihor Radchenko
2022-05-29 11:33             ` Ypo
2022-05-29 11:59               ` Ihor Radchenko
2022-05-30  7:35           ` Eric S Fraga
2022-05-30 10:46             ` Juan Manuel Macías
2022-05-30 21:49               ` Tim Cross
2022-06-02  6:24           ` Phil Estival

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).