emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Rohit Patnaik" <quanticle@quanticle.net>
To: emacs-orgmode@gnu.org
Subject: In an export transcoder, when should I use org-element-property to get values vs. the contents parameter
Date: Fri, 02 Sep 2022 12:07:57 -0500	[thread overview]
Message-ID: <cdf8d06a-3f8a-4b42-980c-89bf2b9be60d@www.fastmail.com> (raw)

I'm looking at function that handles transcoding inline code and verbatim text
in ox-md: 

(defun org-md-verbatim (verbatim _contents _info)
  "Transcode VERBATIM object into Markdown format.
CONTENTS is nil.  INFO is a plist used as a communication
channel."
  (let ((value (org-element-property :value verbatim)))
    (format (cond ((not (string-match "`" value)) "`%s`")
		  ((or (string-prefix-p "`" value)
		       (string-suffix-p "`" value))
		   "`` %s ``")
		  (t "``%s``"))
	    value)))

My question is, why does org-md-verbatim use org-element-property to retrieve
the text to be transcoded, when org-md-bold and org-md-italic use the contents
parameter. In other words, couldn't the function be simplified to something like
this:

(defun org-md-verbatim (_verbatim contents _info)
  "Transcode VERBATIM object into Markdown format.
CONTENTS is nil.  INFO is a plist used as a communication
channel."
  (format (cond ((not (string-match "`" contents)) "`%s`")
                ((or (string-prefix-p "`" contents)
                     (string-suffix-p "`" contents))
                 "`` %s ``")
                (t "``%s``"))
          contents))

The broader context for my question is that I'm writing my own org exporter, and
I'd like some more clarity on what the distinction is between getting the value
of the element with org-element-property and relying on the export framework to
pass the value to the transcoder via the contents parameter.

Thanks,
Rohit


             reply	other threads:[~2022-09-02 17:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-02 17:07 Rohit Patnaik [this message]
2022-09-03  3:49 ` In an export transcoder, when should I use org-element-property to get values vs. the contents parameter Ihor Radchenko

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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cdf8d06a-3f8a-4b42-980c-89bf2b9be60d@www.fastmail.com \
    --to=quanticle@quanticle.net \
    --cc=emacs-orgmode@gnu.org \
    /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 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).