【问题标题】:F# FSharp.Literate formatted code snippet does not display correctly (.css & .js?)F# FSharp.Literate 格式的代码片段无法正确显示(.css 和 .js?)
【发布时间】:2014-02-18 02:56:00
【问题描述】:

我正在尝试使用 FSharp.Literate 来生成 html 页面。我正在使用 Mono 4.5 在 Xamarin 中工作。我想将基本的*.fsx 脚本转换为 html。我正在使用简单的script example from the documentation 进行测试。我想转成html的脚本是这样的。

(**
# First-level heading
Some more documentation using `Markdown`.
*)

(*** include: final-sample ***)

(** 
## Second-level heading
With some more documentation
*)

(*** define: final-sample ***)
let helloWorld() = printfn "Hello world!"

我使用内置的 NuGet 管理器下载FSharp.Formatting。它还安装了Microsoft.AspNet.Razor 2RazorEngine

基于文档中的示例,我编写了以下脚本,将上面的示例转成html。我正在使用 github 上原始 FSharp.Formatting 中的 html 模板。

#I "bin/Debug/"

#r "FSharp.Literate.dll"
#r "FSharp.Markdown.dll"
#r "FSharp.CodeFormat.dll"

open System.IO
open FSharp.Literate

let source = __SOURCE_DIRECTORY__
let baseDir = Path.Combine(source, "html/")
let file = Path.Combine(baseDir, "demo.fsx")
let output = Path.Combine(baseDir, "demo-script.html")
let template = Path.Combine(baseDir, "template.html")

Literate.ProcessScriptFile(file, template, output)

进程运行并生成一个 html 文件。但是,F# 代码不会标记化。我得到了下面的示例,而不是格式良好的代码。我错过了一些明显的东西吗?

编辑

根据 Tomas 在下面的评论,我发现 .css 和 .js 文件存在问题。 我使用的模板有href="{root}/content/style.css" /> <script src="{root}/content/tips.js"

{root} 标签是它找不到 css 和 js 文件的原因。 将其更改为 href="content/style.css" /> <script src="content/tips.js" 解决了问题

【问题讨论】:

    标签: html f# mono xamarin literate-programming


    【解决方案1】:

    我认为该库实际上生成了正确的 HTML。正如您在文件末尾看到的那样,工具提示中应该出现的内容(有关helloWorldprintfn 的类型的信息)就在那里。

    问题可能是生成的 HTML 文件没有正确引用 tips.jsstyle.css 定义 HTML 格式和脚本以弹出工具提示。 这两个文件应该包含在 NuGet 包中(连同默认模板),或者您可以找到它们on the project GitHub

    【讨论】:

    • tips.jp 和 style.css 在项目中。我是否需要编辑 html 模板才能找到它们?
    • @AndreP。您可以修改模板,也可以将这两个文件复制到生成html 文件的目录中的content 文件夹中(模板预期的默认位置是content/tips.jscontent/style.css
    • 确实问题出在 html 上。我只是碰巧在示例中使用了template.html 文件。它包括以下 html <link type="text/css" rel="stylesheet" href="{root}/content/style.css" /> <script src="{root}/content/tips.js" type="text/javascript"></script> {root} 标签是它找不到 *.css*.js 文件的原因。当我切换到另一个模板时,一切正常
    • {root}是可以使用ProcessScriptFilereplacements参数设置的参数。见:tpetricek.github.io/FSharp.Formatting/literate.html
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-01
    • 2020-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多