From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Lawrence Subject: Re: Custom export backend based on HTML: how to implement own blocks? Date: Sun, 23 Nov 2014 09:28:17 -0800 Message-ID: <87ppcd7rny.fsf@berkeley.edu> References: <87sih9q5u3.fsf@wmi.amu.edu.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47394) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xsayb-00015l-7A for emacs-orgmode@gnu.org; Sun, 23 Nov 2014 12:29:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XsayV-0007kf-Uq for emacs-orgmode@gnu.org; Sun, 23 Nov 2014 12:29:33 -0500 Received: from plane.gmane.org ([80.91.229.3]:42701) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XsayV-0007kV-Nb for emacs-orgmode@gnu.org; Sun, 23 Nov 2014 12:29:27 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XsayU-0006m8-Cp for emacs-orgmode@gnu.org; Sun, 23 Nov 2014 18:29:26 +0100 Received: from c-67-169-117-151.hsd1.ca.comcast.net ([67.169.117.151]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 23 Nov 2014 18:29:26 +0100 Received: from richard.lawrence by c-67-169-117-151.hsd1.ca.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 23 Nov 2014 18:29:26 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Hi Marcin, Marcin Borkowski 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