-
Notifications
You must be signed in to change notification settings - Fork 175
Description
In https://github.com/nextjournal/markdown we are generating a Markdown string -> AST -> Hiccup representation.
Markdown HTML blocks and inline tags are raw HTML and we can't represent those as raw strings in hiccup in a library-independent way. E.g.:
# Hello
<img src="foo.jpg"/>
is rendered to something like:
[:div
[:h1 "Hello"]
[??? "<img src=\"foo.jpg\"/>]
where the image is raw HTML. Preferably we don't want to directly couple the library to a specific hiccup library. Calling hiccup2/raw to represent the raw node would couple the library to this project. Clojure libraries that can communicate via data should maybe not force specific dependencies on people if it can be avoided.
Another issue is platform independence. https://github.com/nextjournal/markdown works on both the JVM and in ClojureScript. For ClojureScript we don't know if the data is going to be rendered with Reagent or some other library. So I'm going to ping a couple of alternative hiccup library authors here as well.
It would be nice to have an implementation-agnostic data-centered way to represent raw nodes.
In https://github.com/borkdude/html I had chosen the [:$ "<img src=\"...\"/>] tag for this since :$ looks as if it cringes on the unescaped HTML. @weavejester suggested on Slack to use [:= ... instead to indicate that this tag should set the literal HTML provided. I'm fine with that. Hopefully that does not clash with some template language that looks like HTML that people use as a target. Another idea would be to use something like [:div {:dangerouslySetInnerHTML "..."] (React) but I'm not sure if looking at properties when generating HTML has a significant performance penalty.
Pinging @weavejester (hiccup), @escherize (huff), @Deraen (reagent), @lilactown (Helix). Not sure if it makes sense to ping more people, if we can make this a standard between all of these libraries, I think it's a standard ;-).
For the safety aspect of this feature, see escherize/huff#5 (comment).