Hello Orgers, assume that I have this in my Org file: #+BEGIN_FOO :bar baz qux whatever #+END_FOO and I want to extract the value of the header argument "bar" (i.e., the string "baz qux" in this case). How do I do it? (I'm writing – still – the custom exporter, and would like to be able to set something spearately for each special block of some kind.) BTW, a shameless plug: while Org-edu-HTML (https://github.com/mbork/org-edu-html) is not yet production-ready, it was nevertheless used for a real life project, and it seems to be working (despite some rough edges). Let me remind you that it is an HTML exporter for educational materials (currently: single and multiple choice tests, cloze tests and “show the answer” buttons). In case any of you finds this interesting, all feedback is welcome. TIA, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University
Hi,
Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:
> #+BEGIN_FOO :bar baz qux
> whatever
> #+END_FOO
>
> and I want to extract the value of the header argument "bar" (i.e., the
> string "baz qux" in this case). How do I do it?
Here's something to get you started.
#+BEGIN_FOO :bar baz qux
whatever
#+END_FOO
#+BEGIN_SRC emacs-lisp
(goto-char (point-min)) ; to make the example work
(let ((str (and (search-forward-regexp org-block-regexp nil t)
(match-string 3))))
(when str
(string-match "[ \t]:\\w+[ \t]+\\([^:]+\\)" str)
(org-trim (match-string 1 str))))
#+END_SRC
#+RESULTS:
: baz qux
There's a similar "parser" in org-export-expand-include-keyword. If you
know which argument you are looking for you can replace the \\w+ above.
Hope it helps,
Rasmus
--
Send from my Emacs
[-- Attachment #1: Type: TEXT/PLAIN, Size: 899 bytes --] On Tue, 20 Jan 2015, Marcin Borkowski wrote: > Hello Orgers, > > assume that I have this in my Org file: > > #+BEGIN_FOO :bar baz qux > whatever > #+END_FOO > > and I want to extract the value of the header argument "bar" (i.e., the > string "baz qux" in this case). How do I do it? (I'm writing – still – > the custom exporter, and would like to be able to set something > spearately for each special block of some kind.) It will be easier to use a src block for a faux language (say FOO). Customize `org-babel-execute:FOO' as needed and you should be set: #+BEGIN_SRC emacs-lisp (defun org-babel-execute:FOO (body params &optional etc) (concat body (format " %S" (assoc :bar params)))) #+END_SRC #+RESULTS: : org-babel-execute:FOO #+NAME: example1 #+BEGIN_SRC FOO :bar baz qux :exports results whatever #+END_SRC #+RESULTS: example1 : whatever (:bar . "baz qux") HTH, Chuck