* How to extract header arguments of a special block?
@ 2015-01-20 0:27 Marcin Borkowski
2015-01-20 1:02 ` Rasmus
2015-01-20 17:45 ` Charles C. Berry
0 siblings, 2 replies; 3+ messages in thread
From: Marcin Borkowski @ 2015-01-20 0:27 UTC (permalink / raw)
To: Org-Mode mailing list
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to extract header arguments of a special block?
2015-01-20 0:27 How to extract header arguments of a special block? Marcin Borkowski
@ 2015-01-20 1:02 ` Rasmus
2015-01-20 17:45 ` Charles C. Berry
1 sibling, 0 replies; 3+ messages in thread
From: Rasmus @ 2015-01-20 1:02 UTC (permalink / raw)
To: emacs-orgmode
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to extract header arguments of a special block?
2015-01-20 0:27 How to extract header arguments of a special block? Marcin Borkowski
2015-01-20 1:02 ` Rasmus
@ 2015-01-20 17:45 ` Charles C. Berry
1 sibling, 0 replies; 3+ messages in thread
From: Charles C. Berry @ 2015-01-20 17:45 UTC (permalink / raw)
To: Marcin Borkowski; +Cc: Org-Mode mailing list
[-- 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-01-20 17:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-20 0:27 How to extract header arguments of a special block? Marcin Borkowski
2015-01-20 1:02 ` Rasmus
2015-01-20 17:45 ` Charles C. Berry
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).