Re: # Comments export

2022-06-02 Thread Phil Estival



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

Re: # Comments export

2022-05-30 Thread Tim Cross


Juan Manuel Macías  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:background=\"#00\">%s" 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@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. 



Re: # Comments export

2022-05-30 Thread Juan Manuel Macías
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:background=\"#00\">%s" 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@posteo.net/

Best regards,

Juan Manuel 



Re: # Comments export

2022-05-30 Thread Eric S Fraga
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 "%s" 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



Re: # Comments export

2022-05-29 Thread Ihor Radchenko
Ypo  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



Re: # Comments export

2022-05-29 Thread Ypo

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

Re: # Comments export

2022-05-28 Thread Ihor Radchenko
Ypo  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



Re: # Comments export

2022-05-28 Thread Ypo
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 :

> to op: do you mean to sometimes export comments and sometimes not?
> 
> 
> On 5/28/22, Timothy  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



Re: # Comments export

2022-05-28 Thread Samuel Wales
to op: do you mean to sometimes export comments and sometimes not?


On 5/28/22, Timothy  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



Re: # Comments export

2022-05-28 Thread Timothy
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


Re: # Comments export

2022-05-28 Thread Ypo

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 
*Subject*: # Comments export
*To*: Org-mode 
*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


Re: # Comments export

2022-05-28 Thread Timothy
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