I am trying to write on org-mode backend to generate Jupyter Notebook, specifically optimized for producing slides using RISE (see https://github.com/hkarl/org-juslides if interested).

Suppose I have a src-code block. How can I find out the tags of its enclosing headline (if any tags exist)?

The closest thing I found is this How can I get the tags for a headline in a clock report formula?, and Org-mode backend: access properties in heading - but they are after somewhat different problems.

I know how to get at attributes of the src-block itself, but I'd rather not have to repeat a "skipslide" tag already set in the headline.

I suppose it would be possible traversing org-element-lineage, but that seems like vast overkill. Is there any simpler option?

Any pointers much appreciated!

Thanks a lot,

Holger

(defun org-juslides-src-block (src-block contents info)
  (let ( (code (org-export-format-code-default src-block info))
     (animate (org-export-read-attribute :attr_juslides src-block :animate))
     )
    (print "src block")
    (print (org-element-lineage src-block '('heading) ))
    (print animate)
    (org-juslides-cell "code"
               (if animate
               "fragment"
             "-")
               code)
    )
  )
  • Untested, but maybe (org-export-get-tags (org-export-get-parent-headline src-block) info '("invalid" "tags") t) – rasmus Jun 14 '16 at 16:34
  • Wonderful, right on spot! Thanks a lot! – Holger Karl Jun 15 '16 at 9:26

Solved by rasmus, with kudos:

(org-export-get-tags (org-export-get-parent-headline src-block) info '("invalid" "tags") t) 

(or, in detail, to also consider the option to use an attribute in the src-block itself):

  (let* ( 
     (tags (org-export-get-tags (org-export-get-parent-headline src-block) info '("invalid" "tags") t))
     (skipslide (or (member "skipslide" tags)
            (org-export-read-attribute :attr_juslides src-block :skip)
            ))
     )

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.