emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: # Comments export


From: Phil Estival
Subject: Re: # Comments export
Date: Thu, 2 Jun 2022 08:24:22 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0


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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]