public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: Mark Szepieniec <mszepien-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: filter to remove inline HTML comments
Date: Sat, 13 Dec 2014 20:29:04 +0100	[thread overview]
Message-ID: <CAE4-1rVuUuGss_x43gr80TgfHaxhRF8-MEyhM335Au3RZ-HGgg@mail.gmail.com> (raw)
In-Reply-To: <548C8EF8.8050007-S0/GAf8tV78@public.gmane.org>

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

Merging the two filters is not straightforward, as one operates on Blocks
and the other on Inlines. It would be doable by merging them into a
function that operates on Pandocs (the datatype pandoc uses to represent
complete documents). However, I don't see why you would want to go to the
trouble of doing that; I think it's more elegant to keep them separate and
if you need to use both just do `pandoc ... --filter removeInlineComments
--filter removeBlockComments` which would apply the filters in that order.
That way, things are more modular and therefore easier to repurpose for
future use cases.

On Sat, Dec 13, 2014 at 8:09 PM, Pablo Rodríguez <oinos-S0/GAf8tV78@public.gmane.org> wrote:
>
> Many thanks for your reply and the code, Mark.
>
> How can I merge both filters (for block and inline comments) into a
> single one.
>
> I tried something like:
>
> #!/usr/bin/runhaskell
>
> module Main where
>
> import Text.Pandoc.JSON
> import Data.List
>
> main :: IO ()
> main = do
>     toJSONFilter removeBlockComments removeInlineComments
>     toJSONFilter removeBlockComments removeInlineComments
>
> removeBlockComments :: Block -> [Block]
> removeBlockComments e@(RawBlock (Format "html") _) = if isComment s then
> [] else [e]
> removeBlockComments e = [e]
>
> removeInlineComments :: Inline -> [Inline]
> removeInlineComments e@(RawInline (Format "html") s) = if isComment s
> then [] else [e]
> removeInlineComments e = [e]
>
> isComment :: String -> Bool
> isComment = isPrefixOf "<!--"
>
> But I must confess that this is the first time I try to write (or even
> read) something in Haskell.
>
> How could be both filters merged?
>
> Many thanks for your help,
>
>
> Pablo
>
>
>
> On 12/13/2014 03:09 PM, Mark Szepieniec wrote:
> > module Main where
> >
> > import Text.Pandoc.JSON
> > import Data.List
> >
> > main = toJSONFilter removeComments
> >
> > removeComments :: Inline -> [Inline]
> > removeComments e@(RawInline (Format "html") s) = if isComment s then []
> else [e]
> > removeComments e = [e]
> >
> > isComment :: String -> Bool
> > isComment = isPrefixOf "<!--"
> >
> > This should work, although I've not tested it myself.
> >
> > Mark
>
>
> --
> http://www.ousia.tk
>
> --
> 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/548C8EF8.8050007%40web.de
> .
> 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-/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/CAE4-1rVuUuGss_x43gr80TgfHaxhRF8-MEyhM335Au3RZ-HGgg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 4906 bytes --]

  parent reply	other threads:[~2014-12-13 19:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-12 21:53 Pablo Rodríguez
     [not found] ` <548B63DF.5050902-S0/GAf8tV78@public.gmane.org>
2014-12-12 23:39   ` BPJ
     [not found]     ` <CADAJKhA2zy5KJ-FC44BKTeuTkw_CCwZa3c+NJAgScBFEOjLnog-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-13 10:14       ` Pablo Rodríguez
     [not found]         ` <548C1181.6010806-S0/GAf8tV78@public.gmane.org>
2014-12-13 14:09           ` Mark Szepieniec
     [not found]             ` <CAE4-1rUH+guOdJvpmMNLS8_xKKbj=oBXcdqrF8eT7uEAZWPkrQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-13 19:09               ` Pablo Rodríguez
     [not found]                 ` <548C8EF8.8050007-S0/GAf8tV78@public.gmane.org>
2014-12-13 19:29                   ` Mark Szepieniec [this message]
2014-12-14 21:29           ` BP Jonsson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAE4-1rVuUuGss_x43gr80TgfHaxhRF8-MEyhM335Au3RZ-HGgg@mail.gmail.com \
    --to=mszepien-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).