From: Ihor Radchenko <yantar92@gmail.com>
To: Ypo <ypuntot@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: # Comments export
Date: Sun, 29 May 2022 19:59:40 +0800 [thread overview]
Message-ID: <87sfoswnv7.fsf@localhost> (raw)
In-Reply-To: <f7a91e6b-9f13-04e0-483e-1dd875d50cd7@gmail.com>
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
next prev parent reply other threads:[~2022-05-29 11:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sfoswnv7.fsf@localhost \
--to=yantar92@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=ypuntot@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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.