简体   繁体   English

有没有办法从.fsx文件直接将HTML发送到FsLab日志?

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

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. 我想将一些html(从我的F#代码生成)发送到FsLab日志中,但似乎无法找到正确的咒语来实现它。

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? 如果我的代码中有一个返回html代码片段的函数,有没有办法直接将它放到页面中而不被<pre>标记包围?


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. 但输出只是html代码本身的格式,如输出。

I took a dive into the F# formatting GH pages and found the (*** raw ***) command so I also tried: 我深入研究了F#格式化GH页面并找到了(*** raw ***)命令,所以我也试过了:

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

but the output still gets surrounded by the <pre> & <code> tags. 但输出仍然被<pre><code>标签包围。

Is it possible to simply emit raw html in this way without the <pre> tag? 是否可以在没有<pre>标签的情况下以这种方式简单地发出原始html?

If you are using the latest version, then you can add custom HTML printers using fsi.AddHtmlPrinter . 如果您使用的是最新版本,则可以使用fsi.AddHtmlPrinter添加自定义HTML打印机。 We need to improve FsLab docs, but this is also used by F# Interactive Service in Atom . 我们需要改进FsLab文档,但Atom中的F#Interactive Service也使用它。

To emit raw HTML, you can include something like this in your script: 要发出原始HTML,您可以在脚本中包含以下内容:

(*** 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: 然后,您应该能够创建HTML节点:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM