I’m playing around with Haskell and Happstack and I’m trying to output string-based HTML directly without using formal Happstack functions. Specifically I’m trying to output SVG directly into the page (with <svg> ... </svg>) which comes from another module already fully generated as a string.
It’s just a little toy program so I’m trying to avoid having to refactor the SVG generator module.
So my question is, in the following:
(f "<b> test </b>")
what is f such that test will appear in bold in my browser?
If that’s not reasonably possible, what would be a more structured approach?
The easy way is to use
toResponseBS:Another option is to make a
ToMessageinstance:Now you can do
toResponse (SVG svg)or evenok $ SVG svgbut the latter will not compose well with non-SVG handlers viamsum…edit: The above is relevant for serving an SVG file from a handler but you actually asked for embedding SVG in HTML which I first missed.
The answer depends on how you’re generating your HTML.
If you’re using
blaze-htmlyou want to use thepreEscapedToHtmlfunction:If you’re using HSP you want to use the
cdataorpcdatafunction (I can never remember which, so try both):Hope that helps!