* Custom export backend based on HTML: how to implement own blocks?
@ 2014-11-23 15:44 Marcin Borkowski
2014-11-23 17:28 ` Richard Lawrence
2014-11-23 19:17 ` Charles Berry
0 siblings, 2 replies; 3+ messages in thread
From: Marcin Borkowski @ 2014-11-23 15:44 UTC (permalink / raw)
To: Org-Mode mailing list
Hello,
I'd like to (ab)use the "underline" syntax for something else.
Basically, I'd like to translate
_underlined_
to
<span class="my-own"><variant>underlined<variant></span>
and
_underlined|with variant_
to
<span class="my own"><variant>underlined</variant><variant>with
variant</variant></span>
but only if the underlining is between
#+BEGIN_MYBLOCK
...
#+END_MYBLOCK
How to achieve this? In particular, I'd like to know:
1. How can I know (in org-html-underline, for instance) whether I am in
a MYBLOCK or not?
2. How do I best translate the "|" syntax into "variants"? More
specifically: is it a good idea to do it in org-my-html-underline, by
analysing the "underlined" text (as a string) or maybe it's better to
write a filter? (I guess the former idea is better.)
Best,
--
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: Custom export backend based on HTML: how to implement own blocks?
2014-11-23 15:44 Custom export backend based on HTML: how to implement own blocks? Marcin Borkowski
@ 2014-11-23 17:28 ` Richard Lawrence
2014-11-23 19:17 ` Charles Berry
1 sibling, 0 replies; 3+ messages in thread
From: Richard Lawrence @ 2014-11-23 17:28 UTC (permalink / raw)
To: emacs-orgmode
Hi Marcin,
Marcin Borkowski <mbork@wmi.amu.edu.pl> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Custom export backend based on HTML: how to implement own blocks?
2014-11-23 15:44 Custom export backend based on HTML: how to implement own blocks? Marcin Borkowski
2014-11-23 17:28 ` Richard Lawrence
@ 2014-11-23 19:17 ` Charles Berry
1 sibling, 0 replies; 3+ messages in thread
From: Charles Berry @ 2014-11-23 19:17 UTC (permalink / raw)
To: emacs-orgmode
Marcin Borkowski <mbork <at> wmi.amu.edu.pl> writes:
>
> Hello,
>
> I'd like to (ab)use the "underline" syntax for something else.
> Basically, I'd like to translate
>
> _underlined_
>
> to
>
> <span class="my-own"><variant>underlined<variant></span>
>
> and
>
> _underlined|with variant_
>
> to
>
> <span class="my own"><variant>underlined</variant><variant>with
> variant</variant></span>
>
> but only if the underlining is between
>
> #+BEGIN_MYBLOCK
> ...
> #+END_MYBLOCK
>
> How to achieve this? In particular, I'd like to know:
>
> 1. How can I know (in org-html-underline, for instance) whether I am in
> a MYBLOCK or not?
>
You do not need to know this directly. See below:
> 2. How do I best translate the "|" syntax into "variants"? More
> specifically: is it a good idea to do it in org-my-html-underline, by
> analysing the "underlined" text (as a string) or maybe it's better to
> write a filter? (I guess the former idea is better.)
>
Define two derived backends:
backend 1) Use 'html as the parent. Add 'MYBLOCK' to the `:export-block'
list and define your own `org-backend1-export-block' transcoder with a fallback
to the parent backend for HTML blocks.
You will have access to the :value of MYBLOCK as a string. You can use
`org-export-string-as' to process that value according to an arbitrary backend -
in this case you use `backend2'.
backend 2) Use html as the parent of this backend and define
`org-backend2-underline' to use the rules you outline above. You can
parse the `contents' arg for the `|' etc.
There might be a case for making `backend2' anonymous since you only replace
one transcoder of the parent. There is an example in
` org-html--format-toc-headline'.
HTH,
Chuck
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-11-23 19:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-23 15:44 Custom export backend based on HTML: how to implement own blocks? Marcin Borkowski
2014-11-23 17:28 ` Richard Lawrence
2014-11-23 19:17 ` Charles 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).