From: Richard Lawrence <richard.lawrence@berkeley.edu>
To: emacs-orgmode@gnu.org
Subject: Re: Custom export backend based on HTML: how to implement own blocks?
Date: Sun, 23 Nov 2014 09:28:17 -0800 [thread overview]
Message-ID: <87ppcd7rny.fsf@berkeley.edu> (raw)
In-Reply-To: 87sih9q5u3.fsf@wmi.amu.edu.pl
Hi Marcin,
Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:
> 1. How can I know (in org-html-underline, for instance) whether I am in
> a MYBLOCK or not?
I don't know whether this is the best approach, but given an element,
you can walk up its parents in the parse tree until you either reach a
MYBLOCK (in which case, you are in such a block) or the top of the tree
(in which case, you aren't).
Here's an approach I use in a custom backend[1] to do something similar.
The following function is used to identify paragraphs (or other
elements) that are within lists which have an #+ATTR_LINGUISTICS
declaration specifying a :package property. (Because it recursively
walks up the parse tree, this works even for paragraphs in
arbitrarily-nested sublists.)
#+BEGIN_SRC emacs-lisp
(defun org-linguistics-find-enclosing-pkg (element)
"Find the enclosing linguistics package of a (list) element during export."
(let ((pkg (org-export-read-attribute :attr_linguistics element
:package))
(parent (org-export-get-parent element)))
(cond
; return if we found a :package attribute on element
(pkg pkg)
; recurse on the parent if element has a parent but we found no
; :package attribute
(parent (org-linguistics-find-enclosing-pkg parent))
; otherwise, no :package attribute was found
(t nil))))
#+END_SRC
(In your case, a similar function might only need to return a boolean
value that indicates whether an element is inside a MYBLOCK, rather than
returning a string, as this function does.)
Then, in other code, I can treat paragraphs differentially based on
whether they are in a list with this :package attribute set, e.g.
#+BEGIN_SRC emacs-lisp
(defun some-function-that-handles-paragraphs (paragraph)
(let* ((enclosing-pkg (org-linguistics-find-enclosing-pkg paragraph))
; ...
)
; ....
(cond
((string= enclosing-pkg "gb4e")
; do something for paragraphs in lists with :package gb4e ...
)
((string= enclosing-pkg "linguex")
; do something for paragraphs in lists with :package linguex ...
)
(t
; do a default thing for paragraphs that are not in such lists
))))
#+END_SRC
Hope that's helpful!
Best,
Richard
[1] The backend is ox-linguistics, a package for writing
linguistics-style examples in Org:
https://github.com/wyleyr/ox-linguistics
next prev parent reply other threads:[~2014-11-23 17:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-23 15:44 Custom export backend based on HTML: how to implement own blocks? Marcin Borkowski
2014-11-23 17:28 ` Richard Lawrence [this message]
2014-11-23 19:17 ` Charles Berry
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=87ppcd7rny.fsf@berkeley.edu \
--to=richard.lawrence@berkeley.edu \
--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 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.