emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* More export filter examples out there?
@ 2015-03-17 22:15 Allen S. Rout
  2015-03-17 22:53 ` Nicolas Goaziou
  0 siblings, 1 reply; 2+ messages in thread
From: Allen S. Rout @ 2015-03-17 22:15 UTC (permalink / raw)
  To: emacs-orgmode


I'm trying to accomplish a custom export task which I'd hoped to be
pretty simple:  something like:


In each status section, only export the first child headline.


After several dumb ideas, I decided that doing it with a filter was
probably the Right Place.  I built a filter intended to be used on

:filter-parse-tree

and attempted to express:

If you're parent is a headline
and your parent's title is 'Status'
and you're not the first of your siblings

then don't be included.  I've added my malfunctioning filter below,to
clearly display my "thinking".

I don't seem to be able to get the title as a string.  org-export-data
seems to expect a different 'info' than the 'info' present at filter
time.  I get complaints about

org-export-data: Wrong type argument: hash-table-p, nil

if I uncomment the attempt to string compare the title.


I'm finding my experience with XSLT to be a handicap; I bring
expectations to the table that are misguided.  Is there a pretty-printer
or other dump for the export parse tree?   The dump I sometimes get in
*Messages* is not all that readable.

Should I be thinking of this as a parse-table operation, or should I be
reasoning about it from :filter-headline?


More generally, anyone got some art for some similar reconstruction
they've done, which they might like to share?


- Allen S. Rout




(defun ox-asr-only-first-status  ( tree backend info )
  " Arrange that, under headlines marked 'Status', only the first of
them is included.

"
  ( org-element-map tree (remq 'item org-element-all-elements)

    ( lambda (e)
      ( let* ( ( parent       ( org-element-property :parent e) )
	       ( first-sib    ( car (org-element-contents parent )))
	       ( parent-type  ( org-element-type parent ))
	       ( parent-title ( org-element-property :title e))
;	       ( pt-string    ( org-export-data parent-title info ))
	       )
	
	(if (and
	     ( eq parent-type 'headline )
	     ( not (eq e first-sib ))
;	     ( string= (org-export-data parent-title) "Status")
	     )
	    ( org-element-set-contents e  "-->" parent-title "<---  "
(org-element-contents e))
	  )
	
	)
      )

    )


  tree
  )

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

* Re: More export filter examples out there?
  2015-03-17 22:15 More export filter examples out there? Allen S. Rout
@ 2015-03-17 22:53 ` Nicolas Goaziou
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Goaziou @ 2015-03-17 22:53 UTC (permalink / raw)
  To: Allen S. Rout; +Cc: emacs-orgmode

Hello,

"Allen S. Rout" <asr@ufl.edu> writes:

> I'm trying to accomplish a custom export task which I'd hoped to be
> pretty simple:  something like:
>
>
> In each status section, only export the first child headline.
>
>
> After several dumb ideas, I decided that doing it with a filter was
> probably the Right Place.  I built a filter intended to be used on
>
> :filter-parse-tree
>
> and attempted to express:
>
> If you're parent is a headline
> and your parent's title is 'Status'
> and you're not the first of your siblings
>
> then don't be included.  I've added my malfunctioning filter below,to
> clearly display my "thinking".

Untested:

  (defun ox-asr-only-first-status (tree backend info)
    (org-element-map tree 'headline
      (lambda (h)
        (let ((parent (org-export-get-parent-headline h)))
          (when (and parent
                     (string= (org-element-property :raw-value parent) "Status")
                     (not (org-export-first-sibling-p h info)))
            (org-element-extract-element h)))))
    tree)

> I don't seem to be able to get the title as a string.

Use `:raw-value' property.

> org-export-data seems to expect a different 'info' than the 'info'
> present at filter time. I get complaints about
>
> org-export-data: Wrong type argument: hash-table-p, nil
>
> if I uncomment the attempt to string compare the title.

Indeed. One cannot use `org-export-data' during parse tree filtering.
Export output really depends on the tree and the options, which are
being re-arranged.


Regards,

-- 
Nicolas Goaziou

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

end of thread, other threads:[~2015-03-17 22:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-17 22:15 More export filter examples out there? Allen S. Rout
2015-03-17 22:53 ` Nicolas Goaziou

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