Thanks! I tried that and the filter indeed compiles but converting a single `CodeBlock` into a list of `CodeBlock` and `latex` blocks 
has the unfortunate effect of introducing line breaks everywhere (I think this is because a line break is introduced wherever a code block ends, right?)


On Saturday, January 17, 2015 at 4:45:54 PM UTC-8, Matthew Pickering wrote:
f :: Maybe Format -> Block -> [Block] should work fine.

https://hackage.haskell.org/package/pandoc-types-1.12.2.1/docs/Text-Pandoc-JSON.html

On Sun, Jan 18, 2015 at 12:44 AM, Ranjit Jhala <rjh...-fWt/sZ2FBdz2fBVCVOL8/A@public.gmane.org> wrote:
> Hi Matthew,
>
> The catch is that there's a bunch of other stuff in the `Block`.
>
> That is, the special token is some substring of `s`
>
> f :: Block -> Block
> f (CodeBlock _ s) = RawBlock (Format "latex")  ("\\MySpecialToken{" ++ s ++
> "}")
> f b = b
>
> and I don't want to lose that. So I can write a function
>
>     f :: Block -> [Block]
>
> where each CodeBlock is expanded into a list of :
>
>   `RawBlock (Format "latex")` of the kind above,
>   and the remaining, unchanged CodeBlock
>
> But that causes problems with toJSONFilter as I can't pass in a
> transformation of the form
>
>    [Block] -> [Block]
>
> Because there is no instance of Walkable for [Block] ... :(
>
> On Saturday, January 17, 2015 at 3:06:04 PM UTC-8, Matthew Pickering wrote:
>>
>> You can write a filter ... f :: Block -> Block and have something like
>> the following.
>>
>> f :: Block -> Block
>> f (CodeBlock _ s) = RawBlock (Format "latex")  ("\\MySpecialToken{" ++ s
>> ++ "}")
>> f b = b
>>
>> Do you also plan to output to other formats? If so then "toJSONFilter"
>> can take a function of type "f :: Maybe Format -> Block -> Block"
>> where the first argument is the output format.
>>
>> Does that make sense?
>>
>> On Sat, Jan 17, 2015 at 9:05 PM, Ranjit Jhala <rjh...@eng.ucsd.edu> wrote:
>> > Hi,
>> >
>> > I'd like to write a filter that runs on `CodeBlock` such that each
>> > identifier that begins
>> > with (say) "$$$mytoken" gets rendered in latex not as a
>> >
>> >     \NormalTok{$$$mytoken}
>> >
>> > but as
>> >
>> >     \MySpecialToken{$$$mytoken}
>> >
>> > Can anyone give me a hint as to how to proceed? The stumbling block is
>> > that
>> > it seems like
>> > the filter should "preserve" the type, so I can write a
>> >
>> >     myFilter :: CodeBlock -> CodeBlock
>> >
>> > But the `CodeBlock` type only allows strings -- presumably just
>> > replacing
>> > (substrings) of the form
>> >
>> >     $$$mytoken
>> >
>> > with
>> >
>> >    \MySpecialToken{$$$mytoken}
>> >
>> > will only cause the latter to then get "escaped" out during the final
>> > latex
>> > conversion?
>> >
>> > Any pointers would be most welcome!
>> >
>> > Thanks!
>> >
>> > - Ranjit.
>> >
>> > --
>> > 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-discus...@googlegroups.com.
>> > To post to this group, send email to pandoc-...@googlegroups.com.
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/pandoc-discuss/5699588b-678c-4de6-96c0-6505e7fbd950%40googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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-discus...@googlegroups.com.
> To post to this group, send email to pandoc-...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/0d47cfc0-2a3d-4248-bd35-317dcd6a738b%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/ca72b4ed-aac7-4a6a-9e0f-580bcc450f5f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.