I’ve been trying out js_of_ocaml, and it’s been going pretty well so far, but I have run into an issue that I can’t seem to get around.
I want to convert a string (obtained dynamically from a
Yojson json response) to a HTML element and insert it into a
Tyxml structure. Unfortunately, no matter what I try, the HTML tags end up being encoded - i.e the final output text would be:
Some text... <a href="http://www.fsf.org">fsf</a>
Which means that the browser doesn’t render the link correctly, and instead displays the tags explicitly.
To generate the node, I was initially using:
div [txt text]
text is the extracted text from the JSON response.
Seeing as this didn’t work, I then tried using the
Unsafe.data operation which is documented as inserting a raw string:
div [Unsafe.data text]
but the issue persists.
I’ve also tried using
Js.unescape to preprocess the string I extract from the JSON (in case the issue arises from JSON encoding), but this doesn’t help.
Rather annoyingly when I try and print the text to console it seems to auto-hide the escape sequences, meaning that I can’t actually work out if the error is due to Tyxml or due to the JSON text itself.
Is there something I’m doing wrong? or is this operation not supported by Tyxml?