When using SML/NJ library's HTML4 library, how do I convert the Standard ML representation of HTML4 into a string?
For example, if I have the HTML representation below, what function can I use to get a string similar to <html><head><title>Example</title></head><body><h1>Hello!</h1></body></html>?
(* CM.make "$/html4-lib.cm"; *)
open HTML4;
val myHTML = HTML {
version=NONE,
head=[Head_TITLE ([], [PCDATA "Example"])],
content=BodyOrFrameset_BODY (BODY ([], [
BlockOrScript_BLOCK (H1 ([], [CDATA [PCDATA "Hello!"]]))]))
};
(SML/NJ version: 110.99.2)
According to the SML/NJ bug tracker, the following function can be used to convert
HTML4.htmlto a string:To be able to use
HTML4Print.prHTMLin the SML/NJ REPL, the REPL should be started usingsml '$/html4-lib.cm'. Alternatively, enterCM.make "$/html4-lib.cm";after starting the REPL.The function has signature
val toString = fn : HTML4.html -> CharBuffer.vector.CharBufferis an extension to the Basis Library (reference: 2018 001 Addition of monomorphic buffers).CharBuffer.vectoris the same type asCharVector.vector, which is the same type asString.string, which is the same type asstring.