emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How to export drawer?
@ 2014-04-04  9:25 Marcin Antczak
  2014-04-04 19:10 ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Marcin Antczak @ 2014-04-04  9:25 UTC (permalink / raw)
  To: emacs-orgmode


Hi List,

I got a problem which is blocker for me and this is why I have to ask
here for help.

I would like to export some org to html with custom backend based on
'html.

What I need is to override function org-html-headline from ox-html.el

I just want to export drawer with some specific name. For example
LOGBOOK or CLOCKTABLE.

So, I got this piece of code

#+BEGIN_SRC el
(let* (clocktable (and (plist-get info :with-drawers)
                  (let* ((drawers (org-element-map headline 'drawer 'identity info nil 'headline)))
                    (mapconcat (lambda (d)
                                 (when (string= (org-element-property :drawer-name d) "CLOCKTABLE")
                                   (org-export-data-with-backend d 'html info)))
                               drawers "")))))
#+END_SRC

And this does what I need.... well not exactly.

This code returns drawer in html format.
Unfortunately it returns drawers recursively.

If my org file is flat then everything is ok.

If my org file is like this:

#+BEGIN_SRC
* TODO  No clocktable here
  Task with no clocktable
** TODO First clocktable
   :CLOCKTABLE:
   CLOCK: [2014-04-04 pią 02:45]--[2014-04-04 pią 02:45] =>  0:00
   CLOCK: [2014-04-04 pią 02:45]--[2014-04-04 pią 02:45] =>  0:00
   :END:
   Placeholder
*** DONE First SUB clocktable
    :CLOCKTABLE:
    CLOCK: [2014-04-04 pią 02:45]--[2014-04-04 pią 05:45] =>  3:00
    :END:
    Sub clocktable here
** TODO Second clocktable
   :CLOCKTABLE:
   CLOCK: [2014-04-04 pią 02:45]--[2014-04-04 pią 03:45] =>  1:00
   :END:
   Second clocktable
#+END_SRC

Then in my task "No clocktable here " I can see all CLOCKTABLES from
children tasks.

Could someone help me to disable this recursion properly?


Cheers,
Marcin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to export drawer?
  2014-04-04  9:25 How to export drawer? Marcin Antczak
@ 2014-04-04 19:10 ` Nicolas Goaziou
  2014-04-04 21:06   ` Marcin Antczak
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2014-04-04 19:10 UTC (permalink / raw)
  To: Marcin Antczak; +Cc: emacs-orgmode

Hello,

Marcin Antczak <marcin.antczak@neutrico-themes.pl> writes:

> I would like to export some org to html with custom backend based on
> 'html.
>
> What I need is to override function org-html-headline from ox-html.el

OK. But this isn't related to drawers, is it? If you want to alter
drawers export, you need to override `org-html-drawer' too.

> I just want to export drawer with some specific name. For example
> LOGBOOK or CLOCKTABLE.

You can set `org-export-with-drawers'. You can also hard-code the list
into `org-mybackend-drawer':

  (defun org-mybackend-drawer (drawer contents info)
    (when (member-ignore-case (org-element-property :drawer-name drawer)
                              '("LOGBOOK" "CLOCKTABLE"))
      (org-export-data-with-backend drawer 'html info)))

Of course, you need to install this function in your custom back-end:

  (org-export-define-derived-backend 'mybackend 'html
    ...
    :translate-alist '(...
                       (drawer . org-mybackend-drawer)
                       ...)
    ...)


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to export drawer?
  2014-04-04 19:10 ` Nicolas Goaziou
@ 2014-04-04 21:06   ` Marcin Antczak
  2014-04-04 21:49     ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Marcin Antczak @ 2014-04-04 21:06 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode


Nicolas Goaziou writes:

> Hello,
>
> Marcin Antczak <marcin.antczak@neutrico-themes.pl> writes:
>
>> I would like to export some org to html with custom backend based on
>> 'html.
>>
>> What I need is to override function org-html-headline from ox-html.el
>
> OK. But this isn't related to drawers, is it? If you want to alter
> drawers export, you need to override `org-html-drawer' too.

Unfortunately you misunderstood me.

What I want to do is to override drawers export to exclude some
predefined drawers. Let's say: LOGBOOK and CLOCKTABLE.

Then I want to attach these drawers to headline(!)
This is why I want to add a piece of code to return drawer in org-html-headline.

>
>> I just want to export drawer with some specific name. For example
>> LOGBOOK or CLOCKTABLE.
>
> You can set `org-export-with-drawers'. You can also hard-code the list
> into `org-mybackend-drawer':
>
>   (defun org-mybackend-drawer (drawer contents info)
>     (when (member-ignore-case (org-element-property :drawer-name drawer)
>                               '("LOGBOOK" "CLOCKTABLE"))
>       (org-export-data-with-backend drawer 'html info)))

Yes. I want to hard-code these drawers and ignore them in default export.

Anyway thing is that I want to export drawer with specific name while
I'm in org-html-headline function.

(defun org-html-headline (headline contents info)
  "Transcode a HEADLINE element from Org to HTML.
CONTENTS holds the contents of the headline.  INFO is a plist
holding contextual information."
  ;; Empty contents?
  (setq contents (or contents ""))
  (let* ((numberedp (org-export-numbered-headline-p headline info))
         (level (org-export-get-relative-level headline info))

         And here I wan't to add:

         (clocktable (and (plist-get info :with-drawers)
                  (let* ((drawers (org-element-map headline 'drawer 'identity info nil 'headline)))
                    (mapconcat (lambda (d)
                                 (when (string= (org-element-property :drawer-name d) "CLOCKTABLE")
                                   (org-export-data-with-backend d 'html info)))
                               drawers ""))))


In this way I could attach HTML code with CLOCKTABLE drawer to headline.
Unfortunately as I mentioned before I don't know how to achieve this
without recursion. My code returns all CLOCKTABLE drawers in child
tasks.

org-element-map has optional argument 'no-recursion' but I don't know
how to set it up properly.


Regards,

--
Marcin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to export drawer?
  2014-04-04 21:06   ` Marcin Antczak
@ 2014-04-04 21:49     ` Nicolas Goaziou
  2014-04-04 22:06       ` Marcin Antczak
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2014-04-04 21:49 UTC (permalink / raw)
  To: Marcin Antczak; +Cc: emacs-orgmode

Marcin Antczak <marcin.antczak@neutrico-themes.pl> writes:

> Yes. I want to hard-code these drawers and ignore them in default
> export.

OK, I get it. You want to move some drawers (relatively to the flow of
the document) and ignore others.

> Anyway thing is that I want to export drawer with specific name while
> I'm in org-html-headline function.
>
> (defun org-html-headline (headline contents info)
>   "Transcode a HEADLINE element from Org to HTML.
> CONTENTS holds the contents of the headline.  INFO is a plist
> holding contextual information."
>   ;; Empty contents?
>   (setq contents (or contents ""))
>   (let* ((numberedp (org-export-numbered-headline-p headline info))
>          (level (org-export-get-relative-level headline info))
>
>          And here I wan't to add:
>
>          (clocktable (and (plist-get info :with-drawers)
>                   (let* ((drawers (org-element-map headline 'drawer 'identity info nil 'headline)))
>                     (mapconcat (lambda (d)
>                                  (when (string= (org-element-property :drawer-name d) "CLOCKTABLE")
>                                    (org-export-data-with-backend d 'html info)))
>                                drawers ""))))
>
>
> In this way I could attach HTML code with CLOCKTABLE drawer to headline.
> Unfortunately as I mentioned before I don't know how to achieve this
> without recursion. My code returns all CLOCKTABLE drawers in child
> tasks.
>
> org-element-map has optional argument 'no-recursion' but I don't know
> how to set it up properly.

You can set it to `headline', like you did, but you must skip the
current headline or `org-element-map' will never enter it:

  (org-element-map (org-element-contents headline) 'drawer #'identity info nil 'headline)


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to export drawer?
  2014-04-04 21:49     ` Nicolas Goaziou
@ 2014-04-04 22:06       ` Marcin Antczak
  0 siblings, 0 replies; 5+ messages in thread
From: Marcin Antczak @ 2014-04-04 22:06 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode


Nicolas Goaziou writes:

> Marcin Antczak <marcin.antczak@neutrico-themes.pl> writes:
>
>> Yes. I want to hard-code these drawers and ignore them in default
>> export.
>
> OK, I get it. You want to move some drawers (relatively to the flow of
> the document) and ignore others.
>

Exactly.

I want to append LOGBOOK and CLOCKTABLE to task headline while any other
drawer should go to content as usual.

>> In this way I could attach HTML code with CLOCKTABLE drawer to headline.
>> Unfortunately as I mentioned before I don't know how to achieve this
>> without recursion. My code returns all CLOCKTABLE drawers in child
>> tasks.
>>
>> org-element-map has optional argument 'no-recursion' but I don't know
>> how to set it up properly.
>
> You can set it to `headline', like you did, but you must skip the
> current headline or `org-element-map' will never enter it:
>
>   (org-element-map (org-element-contents headline) 'drawer #'identity
>   info nil 'headline)


AWESOME!

Thank you very, very much.
Now I need to understand this code. But it works!


Regards,

--
Marcin

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-04-04 22:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-04  9:25 How to export drawer? Marcin Antczak
2014-04-04 19:10 ` Nicolas Goaziou
2014-04-04 21:06   ` Marcin Antczak
2014-04-04 21:49     ` Nicolas Goaziou
2014-04-04 22:06       ` Marcin Antczak

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).