a" ! class_ "c" "
a
" or to an HTML generated by a hamle" /> a" ! class_ "c" "
a
" or to an HTML generated by a hamle" /> a" ! class_ "c" "
a
" or to an HTML generated by a hamle"/>

How can I add class_ to preEscapedToHtml in Haskell Blaze or Hamlet?

137 Views Asked by At

How can I add a class to a preEscapedToHtml?

renderHtml $ preEscapedText "<div>a</div>" ! class_ "c"
"<div>a</div>"

or to an HTML generated by a hamlet template?

however this works:

renderHtml $ H.div "a" ! class_ "c"
"<div class=\"c\">a</div>"
1

There are 1 best solutions below

1
Bjartur Thorlacius On

The most accurate type in Blaze for an HTML tag is Tag. H.div is of that type, is it not? What should preEscapedText "<title>Example</title><p>HTML document" ! class_ "c" do anyway? Attributes can only be added to tags, and not to HTML documents or fragments. Thus you should keep your tags with type Tag until you've added all attributes you need and are ready to combine multiple tags into a HTML fragment or document. If you need to keep track of multiple nodes you're generating in parallel, you can store them in a list, tuple or a record while you're modifying them. Then merge then into an HTML at the end.