emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] Custom export backend based on HTML: how to implement own blocks


From: Richard Lawrence
Subject: Re: [O] Custom export backend based on HTML: how to implement own blocks?
Date: Sun, 23 Nov 2014 09:28:17 -0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

Hi Marcin,

Marcin Borkowski <address@hidden> 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




reply via email to

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