Apr 14

A lot of my day-to-day haskell scripts produce html that’s intended to go on my stock market blog. Because I generally just hack stuff together, I’m producing the html along with the output via hPutStr. If I wanted to be a little more fancy and pure about it, I would put another step between my domain and the final HTML output. Looking at the hierarchical haskell libraries, I see Text.XHtml just waiting for me to use it.

So, I played with it for a few minutes. Here, for my own reference, is a very basic use of Text.XHtml:

import Text.XHtml.Strict

myheader = thetitle << "My First Page"

mybody = (h1 << "First Off...") +++
         (paragraph << "Hello, there!")

myhtml = (header << myheader) +++ (body << mybody)

main = do
       putStrLn $ showHtml myhtml

You can also use showHtmlFragment to get a just the html you wrote, with no doctype stuff prepended. I was surprised that it doesn’t seem to put the <?xml … > tag at the top, since it’s xhtml, after all. But, it doesn’t.

Had I been familiar with this library when I wrote all those scripts, I would have used it. Since I wasn’t, I didn’t, and I’m not sure it’s worth my time to replace that stuff now. Maybe, whenever I update one of them, I’ll go ahead and convert it. That way, they’ll eventually all get converted… you know… lazily. And what could be more in the haskell spirit than lazy conversion :-)

Apr 9

To avoid non-standard <embed> tags, you can use the <object> tag:


<object data="file:///tmp/test.pdf"
       width="640"
       height="480"
       type="application/pdf">
  <a href="file:///tmp/test.pdf">my test pdf file</a>
</object>

Note that the link to the file is only given if the browser cannot figure out what to do with the <object> tag. That way, at least those people can still download the file, or something. When I tried this with Camino it didn’t work until I had supplied the width, height, and type arguments. Makes sense, I guess.