0

I'm working on updating the social status of a company.

The original document has been made with Org-Mode and exported to PDF.

In order to keep track of the modifications I'm putting the old parts into comments.

This is an updated part
# This is an original part

Ultimately, the old parts won't appear in the final new PDF. But before that, I have to send an HTML version (for reviewing), where the comments will appear. The reviewer doesn't use Emacs/Org-Mode, that's why I thought of sending him the document in the body of an email copied from an HTML export.

How could I export an HTML showing the commented old parts?

I read the Org-Mode manual (mainly Export Settings and The Export Dispatcher), but I didn't find the option.

2 Answers 2

1

One way is to replace or delete the comment symbol when exporting to HTML.

(defun show-comments (backend)
  (when (org-export-derived-backend-p backend 'html)
    (save-excursion
      (while (not (eobp))
        (forward-line)
        (when (looking-at org-comment-regexp)
          (replace-match ": " ))))))

(add-to-list 'org-export-before-parsing-hook 'show-comments)

The following should make comments red.

(defun show-comments-in-red (backend)
  (when (org-export-derived-backend-p backend 'html)
    (save-excursion
      (while (not (eobp))
        (forward-line)
        (when (and (null (org-at-keyword-p))
                   (looking-at "^[ \t]*#\\(?: \\|$\\)*\\(.+\\)*"))
          (replace-match "#\+html: <div style=\"color:red;\">\\1</div>\n"))))))

(add-to-list 'org-export-before-parsing-hook 'show-comments-in-red)
17
  • Thanks. So with this code, all # will be replaced by : ?
    – crocefisso
    Commented Feb 12, 2023 at 16:32
  • When I execute the code, I have the following message : progn: Symbol’s value as variable is void: org-export-before-parsing-functionsInvalid face attribute :bold t
    – crocefisso
    Commented Feb 12, 2023 at 16:36
  • 1
    You may have to require the ox library with (require 'ox).
    – jagrg
    Commented Feb 12, 2023 at 20:53
  • 1
    It doesn't. There's no org-export-before-parsing-functions in Org version 9.5. Try replacing org-export-before-parsing-functions with org-export-before-parsing-hook and see if that works.
    – jagrg
    Commented Feb 12, 2023 at 21:31
  • 1
    Thanks. It should skip keywords now.
    – jagrg
    Commented Feb 12, 2023 at 23:12
0
  • Function that export (HTML) text commented with # as blocks (code from @jagrg):
(defun comments-as-blocks (backend)
  (when (org-export-derived-backend-p backend 'html)
    (save-excursion
      (while (not (eobp))
        (forward-line)
        (when (looking-at org-comment-regexp)
          (replace-match ": " ))))))
  • If you want the comments to be shown in the exported format, regardless of the export backend, use this function instead:
(defun comments-as-blocks (backend)
  (save-excursion
    (while (not (eobp))
      (forward-line)
      (when (looking-at org-comment-regexp)
      (replace-match ": " )))))
  • Function that allows to activate (toggle) or desactivate # comments exports as blocks (replace org-export-before-parsing-hook with org-export-before-parsing-functions when Org-Mode ≥ 9.6):
(defun mda/toggle-comments-export ()
  (interactive)
  (if (get 'mda/toggle-comments-export 'state)
      (progn
        (setq org-export-before-parsing-hook (remove 'comments-as-blocks org-export-before-parsing-hook))
        (put 'mda/toggle-comments-export 'state nil))
    (progn
      (add-to-list 'org-export-before-parsing-hook 'comments-as-blocks)
      (put 'mda/toggle-comments-export 'state t))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.