2

With org-export-define-backend, I want to make quote-block get current headline's properties.

For example, define a function org-my-headline(headline contents info) for exporting headline , I can get the values within :PROPERTIES: ... :END: in org-my-headline like this:

(defun org-my-headline (headline contents info)
    ...
    (org-element-property :PROPERTY_NAME headline)
    ...
)

Now I want to define a function org-my-quote-block(quote-block contents info) for exporting quote-block, and its behavior can be changed by current headline's property (e.g. :QUOTE_BLOCK: hide), can this task be done?

Or another way: is #+BEGIN_QUOTE able to get the options in title like #+BEGIN_SRC python can get the value python via (org-element-property :language src-block)?

(update: the second way should be impossible...just tried org-element-parse-buffer, and found it will ignore all options strings in #+BEGIN_QUOTE)

1 Answer 1

3

Babel solution

Note that the value of Babel parameters can be lisp code. Thus you can have

#+BEGIN_SRC emacs-lisp :exports (if t "results") :results raw
  "\#+begin_quote 
  my quote
  \#+end_quote"
#+END_SRC

Filter solution

You can easily adapt this for a derived backend.

(defun rasmus/get-org-string-element  (headline backend info)
"Return the org element representation of an element."
(let ((prop-point (next-property-change 0 headline)))
  (if prop-point (plist-get (text-properties-at prop-point headline) :parent))))

(defun rasmus/org-export-quotes-inherit-from-headlne (quote backend info)
  "Discard some quotes based on headline properties."
  (let* ((elm (rasmus/get-org-string-element quote backend info))
     (parent (and elm (org-export-get-parent-headline elm))))
(when (equal (org-element-property :QUOTE_BLOCK parent)
         "hide")
  "")))

(add-to-list 'org-export-filter-quote-block-functions
     'rasmus/org-export-quotes-inherit-from-headlne)

Example

(with-temp-buffer
  (require 'ox-org)
  (insert "
* foo
 :PROPERTIES:
 :quote_block: hide
 :END:
 bar
 \#+BEGIN_QUOTE
 bar
 \#+END_QUOTE
* foo2
 \#+BEGIN_QUOTE
 bar2
 \#+END_QUOTE")
  (org-org-export-as-org nil nil nil t))

Which outputs:

* foo
bar
* foo2
#+BEGIN_QUOTE
bar2
#+END_QUOTE

Derived backend solution w/example

(require 'ox-org)

(org-export-define-derived-backend 'my-backend 'org
  :translate-alist '((quote-block . rasmus/org-export-quotes-inherit-from-headline)))

(defun rasmus/org-export-quotes-inherit-from-headline (quote backend info)
  "Discard some quotes based on headline properties."
  (let ((parent (org-export-get-parent-headline quote)))
(if (equal (org-element-property :QUOTE_BLOCK parent)
       "hide")
    ""
  (org-org-identity quote backend info))))

(with-temp-buffer
  (require 'ox-org)
  (insert "
* foo
 :PROPERTIES:
 :quote_block: hide
 :END:
 bar
 \#+BEGIN_QUOTE
 UNDESIRED QUOTE
 \#+END_QUOTE
* foo2
 \#+BEGIN_QUOTE
 DESIRED QUOTE
 \#+END_QUOTE")
  (org-export-to-buffer 'my-backend "*my backend export*" nil nil nil t))
4
  • Thaaaanks! You saved my brain's cells :D But I found this filter applies after org-my-quote-block. If anyway to make the filter applies before org-my-quote-block; or more directly, make org-my-quote-block accessible to headlines' properties?
    – kuanyui
    Jan 23, 2015 at 7:37
  • When you use it as part of a backend just skip this step (elm (rasmus/get-org-string-element quote backend info) since you have that element directly.
    – rasmus
    Jan 23, 2015 at 9:35
  • Can you explain more detailed? I still cannot understand how to "skip" this step, and what this action means...
    – kuanyui
    Jan 23, 2015 at 16:46
  • 1
    check the new example. it shows how to apply it to the org backend.
    – rasmus
    Jan 23, 2015 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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