[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Help with export filter?
From: |
Thomas S. Dye |
Subject: |
Re: [O] Help with export filter? |
Date: |
Mon, 21 Jul 2014 05:55:56 -1000 |
Aloha Rasmus,
Rasmus <address@hidden> writes:
> Hi Tom,
>
>
> Here's an edited filter that works with the enclosed test document.
> Note that you could split this into different filters, but it may be
> non-trivial with this identification-scheme since things would be
> moving around.
>
> (defun tsd-filter-headline-tags (contents backend info)
> "Ignore headlines with tag `ignoreheading' and/or start LaTeX
> section with `newpage' or `clearpage' command."
> (cond ((and (org-export-derived-backend-p backend 'latex)
> (string-match "\\`.*newpage.*\n" (downcase contents))
> ;; if you want to get rid of labels use the string
> ;; "\\`.*ignoreheading.*\n.*\n"
> (string-match "\\`.*ignoreheading.*\n" (downcase contents)))
> (replace-match "\\\\newpage\n" nil nil contents))
> ((and (org-export-derived-backend-p backend 'latex)
> (string-match "\\`.*clearpage.*\n" (downcase contents))
> (string-match "\\`.*ignoreheading.*\n" (downcase contents)))
> (replace-match "\\\\clearpage\n" nil nil contents))
> ((and (org-export-derived-backend-p backend 'latex 'html 'ascii)
> (string-match "\\`.*ignoreheading.*\n" (downcase contents)))
> (replace-match "" nil nil contents))
> ((and (org-export-derived-backend-p backend 'latex)
> (string-match
> "\\(\\`.*?\\)\\(?:\\\\hfill{}\\)?\\\\textsc{.*?newpage.*?}\\(.*\n\\)"
> (downcase contents)))
> (replace-match "\\\\newpage\n\\1\\2" nil nil contents))
> ((and (org-export-derived-backend-p backend 'latex)
> (string-match
> "\\(\\`.*?\\)\\(?:\\\\hfill{}\\)?\\\\textsc{.*?clearpage.*?}\\(.*\n\\)"
> (downcase contents)))
> (replace-match "\\\\clearpage\n\\1\\2" nil nil contents))))
>
> (add-to-list 'org-export-filter-headline-functions 'tsd-filter-headline-tags)
>
> * my first headline
> cont0
> * ignored headline :ignoreheading:
> cont1 (ignored headline)
> * heading with newpage
> :newpage:
> newline before *here*
> * heading with clearpage :clearpage:
> clearpage before *here*
> * ignored heading with newpage
> :newpage:tag2:
> newline before *here*. =tag2= is lost.
> * ignore heading with clearpage
> :ignoreheading:clearpage:
> clearpage before *here*
>
> —Rasmus
Thanks very much for your help. The new filter does just what I want.
All the best,
Tom
--
Thomas S. Dye
http://www.tsdye.com