Is there a way to emit HTML directly into an FsLab journal from the .fsx file?

123 Views Asked by At

I'd like to emit some html (generated from my F# code) into a FsLab journal but cannot seem to find the correct incantation to make it happen.

If I have a function in my code that returns an html snippet is there a way to get this directly into the page without being surrounded by a <pre> tag?


I have tried, for example:

let f () = 
    """Some <b>bold</b> sample"""
let htmlContent = f ()

then

(*** include-value:htmlContent ***)

but the output is just the html code itself formatted like output.

I took a dive into the F# formatting GH pages and found the (*** raw ***) command so I also tried:

(*** include-value:htmlContent, raw ***)

but the output still gets surrounded by the <pre> & <code> tags.

Is it possible to simply emit raw html in this way without the <pre> tag?

1

There are 1 best solutions below

3
Tomas Petricek On BEST ANSWER

If you are using the latest version, then you can add custom HTML printers using fsi.AddHtmlPrinter. We need to improve FsLab docs, but this is also used by F# Interactive Service in Atom.

To emit raw HTML, you can include something like this in your script:

(*** hide ***)
type Html = Html of string
#if HAS_FSI_ADDHTMLPRINTER
fsi.AddHtmlPrinter(fun (Html h) ->
  seq [], h)
#endif

Then, you should be able to create HTML nodes with:

let b = Html("""Some <b>bold</b> sample""")
(*** include-value:b ***)

Related Questions in F#