Hello. I’m finalizing the implementation of an HTML generation library, HypertextLiteral.jl based upon @mbostock’s Hypertext Literal (HTM). The goal of this is to provide server-side HTML generation, using Julia interpolation syntax. I’m wondering if I should be abusing the MIME type mechanism for style, onclick and other attributes.
Let’s start with some background. This library successfully uses showable("text/html", obj) to see if a user defined object can be serialized directly as HTML. If so, then I can directly call show(io, MIME("text/html"), obj). Else, I’m throwing an error asking that applications either: expressly convert the object to a string, or provide their own implementation of show for the text/html mimetype. I think this is a clean way to enable extensions… for not just this HTML generation library, but any other tool that needs a text/html representation of an object. This would, for example, let HTML objects be transparently treated without any dependencies.
Along these lines of thinking, for the <script> tag, which has its own (lack of) escaping, I think I’m going to follow the same approach, only using MIME("application/javascript"). Similarly, for the <style> tag, I could ask the user object to serialize to MIME("text/css"). I’m assuming any String value provided works… this is for custom objects that are not already converted to string values.
Now for my question. What do I do for references to objects that occur within a style attribute? I was thinking about using style = MIME{Tuple{Symbol("text/html"), Symbol("@style")}}. This convention would decouple the show dispatch from our code. Then, I could use showable(style, obj) and show(io, style, obj) to ask third party libraries to provide a customized adequate serialization to the “style” attribute. Thoughts?