HTML-based e-mails require that all CSS is inlined to prevent it from clashing with the mail client’s user interface. I couldn’t find a CSS inlining tool written in Haskell yet, and it seems like a nice little project with practical uses.
What it would do is take an HTML file and search for CSS that has been applied to it, which is then inlined using the style
attribute.
It might be in your best interest to build on existing parsers for HTML and CSS:
tagsoup
is able to parse HTML / XML and scrape data out of it.pandoc
has a HTML parser that uses tagsoup
internally. Using Pandoc might make it easy to create a traversal over the data structure. See this page for examples on operating on the Pandoc data structure.html-conduit
parses HTML in a more structured manner than tagsoup
.hxt
is the most comprehensive of all libraries here. Old, but trusted.handsomesoup
is built atop hxt
and aims at supporting CSS2 parsing.css-text
is a lightweight library that is able to handle CSS media queries. Outputs a simple tree data structure filled with Text
.The way you track down what CSS is applicable is down to you. handsomesoup
allows extracting elements based on a CSS selector, perhaps see how it’s done?