function to parse from raw string to (optionally failing) Maybe (HSP XML) or something similar, in IO monad, not checked at compile time.

5 views
Skip to first unread message

thomas hartman

unread,
Apr 5, 2011, 4:15:15 PM4/5/11
to haskell-se...@googlegroups.com
I want to parse something like: "<p>a fragment kept in a simple cms-ish system</p>" into IO HSP XML.

If it fails, it should report failure similarly to compile time hsp failures. 

This would enable me to keep some parts of hsp application in text files that would be easy for power users to edit, but wouldn't be checked at compile time.

Is there a way to do this?

thomas hartman

unread,
Apr 7, 2011, 12:36:39 AM4/7/11
to haskell-se...@googlegroups.com
Actually I suppose what I actually want is Maybe XML, it doesn't need to be in the HSP monad.


Niklas Broberg

unread,
Apr 7, 2011, 4:44:56 AM4/7/11
to haskell-se...@googlegroups.com
Hi Thomas,

What you're asking is, is there a parser for the XML type? Such a parser would certainly be conceivable, not even difficult, but it doesn't exist yet. It would make a nice addition to the HSP library though. :-)minns - tar du ansvar för att jag kommer hem från säve?

Cheers,

/Niklas

On Thu, Apr 7, 2011 at 6:36 AM, thomas hartman <thomash...@googlemail.com> wrote:
Actually I suppose what I actually want is Maybe XML, it doesn't need to be in the HSP monad.


--
You received this message because you are subscribed to the Google Groups "Haskell Server Pages" group.
To post to this group, send email to haskell-se...@googlegroups.com.
To unsubscribe from this group, send email to haskell-server-p...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haskell-server-pages?hl=en.

stepcut

unread,
Apr 8, 2011, 10:42:11 AM4/8/11
to Haskell Server Pages
Here is my trick. Use cdata:

<div>
<p>The next line is inserted verbatim</p>
<% cdata $ "<p>a fragment kept in a simple cms-ish system</p>" %>
</div>

Now, that is only good if the String you are inserting is actually
valid HTML. But you can validate those HTML fragments using anything
you want..

It's probably a good idea to use sanitizeBalance from xss-sanitize as
well,

<div>
<p>The next line is inserted verbatim</p>
<% cdata $ sanitizeBalance "<p>a fragment kept in a simple cms-ish
system</p>" %>
</div>

If you actually wanted to process the XML -- then this won't work.
But if all you are trying to do is splice stuff in -- then this trick
works.

I use this trick so that posts and comments can be written in markdown
and run through the markdown perl script (since pandoc has a
restrictive license).

hope this helps!
- jeremy

On Apr 5, 3:15 pm, thomas hartman <thomashartm...@googlemail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages