public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* How to write a filter that modifies existing Pandoc output for a given format
@ 2017-01-26 18:36 Guillermo Rodriguez Garcia
       [not found] ` <057183b6-1f28-402c-b5be-2abd63bf9e16-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Guillermo Rodriguez Garcia @ 2017-01-26 18:36 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1344 bytes --]

Hello all,

I have written simple Pandoc filters that do some modifications on Pandoc's 
AST -- for example, to generate certain LaTeX environments/constructs when 
a Div with certain classes is used in the input file. This worked fine.

However I am not sure how to write a filter that will only make some minor 
changes to the output for a given writer. Here's an example: I would like 
to write a filter so that if an image link contains a ".framed" class, then 
if generating LaTeX output, the \includegraphics command should include a 
[frame] option (this requires the adjustbox package to work).

I am not sure how to do this without replicating all the code Pandoc 
already uses to write out an image link in LaTeX.

Is there a way to do this?

Best, 

Guillermo


-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/057183b6-1f28-402c-b5be-2abd63bf9e16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 1941 bytes --]

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

* How to write a filter that modifies existing Pandoc output for a given format
       [not found] ` <057183b6-1f28-402c-b5be-2abd63bf9e16-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2017-01-27  8:02   ` Kolen Cheung
       [not found]     ` <87384a6a-0d44-4c37-889f-2336df472b5d-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Kolen Cheung @ 2017-01-27  8:02 UTC (permalink / raw)
  To: pandoc-discuss

[-- Attachment #1: Type: text/plain, Size: 1040 bytes --]

I think your filter need to output raw LaTeX, i.e. to convert that element into LaTeX code by your code, and put it in a raw element.

Or you can try to think of some LaTeX magic to do it. I think you still need a filter to capture the difference between a normal image to the one with class, and may be some LaTeX def in the preamble together with a command inserted by your filter could do it. After all, LaTeX is Turning Complete so it might be possible.

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/87384a6a-0d44-4c37-889f-2336df472b5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

* Re: How to write a filter that modifies existing Pandoc output for a given format
       [not found]     ` <87384a6a-0d44-4c37-889f-2336df472b5d-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2017-01-27  8:12       ` Guillermo Rodriguez Garcia
       [not found]         ` <CABDcavaTvmTwhO8ZxLALO-m5XpmHQ7e_KC1C2eEQm+hVBzTKcQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Guillermo Rodriguez Garcia @ 2017-01-27  8:12 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Hello,

Thank you for your answer.

2017-01-27 9:02 GMT+01:00 Kolen Cheung <christian.kolen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:
> I think your filter need to output raw LaTeX, i.e. to convert that element into LaTeX code by your code, and put it in a raw element.

Yes. I know how to do that but then I need to replicate everything
Pandoc already does for image links (which is doable, but no the best
way)

Other cases are more difficult; for example tweaking the way tables
are generated just to add horizontal lines between rows would require
that I replicate all the code Pandoc already has for writing out
tables. That's quite a bit of work, and also a fragile approach.

>
> Or you can try to think of some LaTeX magic to do it. I think you still need a filter to capture the difference between a normal image to the one with class, and may be some LaTeX def in the preamble together with a command inserted by your filter could do it. After all, LaTeX is Turning Complete so it might be possible.

So I guess it is not possible to "modify" Pandoc output, only replace it.

It would be great if a filter could retrieve the output Pandoc intends
to generate for a given node, as a string, then modify that locally.

Best,

Guillermo Rodriguez Garcia
guille.rodriguez-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CABDcavaTvmTwhO8ZxLALO-m5XpmHQ7e_KC1C2eEQm%2BhVBzTKcQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


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

* Re: How to write a filter that modifies existing Pandoc output for a given format
       [not found]         ` <CABDcavaTvmTwhO8ZxLALO-m5XpmHQ7e_KC1C2eEQm+hVBzTKcQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2017-01-27  8:59           ` Kolen Cheung
       [not found]             ` <13e970b8-19e5-4cce-a72e-00e8d74f878c-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Kolen Cheung @ 2017-01-27  8:59 UTC (permalink / raw)
  To: pandoc-discuss

[-- Attachment #1: Type: text/plain, Size: 947 bytes --]

Ah, yes, it is actually possible to do that. e.g. if you use panflute, it has a function convert_text that call pandoc to make the conversion. So you could convert that element from "panflute AST" to LaTeX, then use the re module to regex it to your liking. A potential issue is if a certain conversion is context-dependent (I can't name any example for the moment).

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/13e970b8-19e5-4cce-a72e-00e8d74f878c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

* Re: How to write a filter that modifies existing Pandoc output for a given format
       [not found]             ` <13e970b8-19e5-4cce-a72e-00e8d74f878c-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2017-01-27  9:07               ` Guillermo Rodriguez Garcia
       [not found]                 ` <CABDcavbj898MDS1s02ZP_sakG_vgnW7eEyKDXUmPExeF1evhUA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Guillermo Rodriguez Garcia @ 2017-01-27  9:07 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

I think the use case I described is a good example of a
context-dependent conversion.

Pandoc handles image links differently depending on whether they are
the only thing in a paragraph (in LaTeX this results in a float) or
whether they are inline in the text. This is (a simplified example of)
the kind of logic I don't want to duplicate...

2017-01-27 9:59 GMT+01:00 Kolen Cheung <christian.kolen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:
> Ah, yes, it is actually possible to do that. e.g. if you use panflute, it has a function convert_text that call pandoc to make the conversion. So you could convert that element from "panflute AST" to LaTeX, then use the re module to regex it to your liking. A potential issue is if a certain conversion is context-dependent (I can't name any example for the moment).

Guillermo Rodriguez Garcia
guille.rodriguez-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CABDcavbj898MDS1s02ZP_sakG_vgnW7eEyKDXUmPExeF1evhUA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


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

* Re: How to write a filter that modifies existing Pandoc output for a given format
       [not found]                 ` <CABDcavbj898MDS1s02ZP_sakG_vgnW7eEyKDXUmPExeF1evhUA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2017-01-27 17:33                   ` Kolen Cheung
  0 siblings, 0 replies; 6+ messages in thread
From: Kolen Cheung @ 2017-01-27 17:33 UTC (permalink / raw)
  To: pandoc-discuss

[-- Attachment #1: Type: text/plain, Size: 115 bytes --]

I think you can sent the whole block to convert_text and it should know it is "in its own line" in the conversion.

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

end of thread, other threads:[~2017-01-27 17:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-26 18:36 How to write a filter that modifies existing Pandoc output for a given format Guillermo Rodriguez Garcia
     [not found] ` <057183b6-1f28-402c-b5be-2abd63bf9e16-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2017-01-27  8:02   ` Kolen Cheung
     [not found]     ` <87384a6a-0d44-4c37-889f-2336df472b5d-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2017-01-27  8:12       ` Guillermo Rodriguez Garcia
     [not found]         ` <CABDcavaTvmTwhO8ZxLALO-m5XpmHQ7e_KC1C2eEQm+hVBzTKcQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-27  8:59           ` Kolen Cheung
     [not found]             ` <13e970b8-19e5-4cce-a72e-00e8d74f878c-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2017-01-27  9:07               ` Guillermo Rodriguez Garcia
     [not found]                 ` <CABDcavbj898MDS1s02ZP_sakG_vgnW7eEyKDXUmPExeF1evhUA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-01-27 17:33                   ` Kolen Cheung

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 NNTP newsgroup(s).