我有一个Happstack程序,可以使用Text.Pandoc
动态地将Markdown文档转换为HTML
import qualified Text.Pandoc as Pandoc
...
return $ toResponse $ Pandoc.writeHtml Pandoc.def contents
也就是说,Pandoc返回了一个Text.Blaze.Html.Html
值。(它有一个ToMessage
实例,这意味着它可以用作对请求的响应。)
如何在Pandoc的输出中插入自定义CSS样式表?如果我想要定制超文本标记语言,比如用一些其他元素包装<body>
内容,该怎么办?
发布于 2014-04-20 04:53:28
当Pandoc的“独立模式”选项被启用时,它使用一个模板来格式化输出。可以在WriterOptions
的writerTemplate
和writerVariables
成员中设置模板及其substitions变量。
命令行工具有一组它使用的默认模板。您可以使用例如pandoc -D html
查看格式的默认模板。
使用该库时,默认情况下使用空模板。您可以使用getDefaultTemplate
以编程方式获取默认模板。
下面是一些示例代码:
import Text.Blaze.Html.Renderer.String
import Text.Pandoc
getHtmlOpts = do
template <- either (error . show) id
`fmap` getDefaultTemplate Nothing "html"
return $ def
{ writerStandalone = True
, writerTemplate = template
, writerVariables = [
("css", "/path/to/style.css"),
("header-includes",
"<style>p { background-color: magenta; }</style>")]
}
main = do
opts <- getHtmlOpts
putStrLn $ renderHtml $ writeHtml opts $ readMarkdown def "..."
发布于 2019-01-29 12:54:15
您还可以编写自己的模板,并在从命令行调用pandoc时使用--template template.html
选项。
文档位于https://pandoc.org/MANUAL.html#templates,默认模板(用于灵感)位于https://raw.githubusercontent.com/jgm/pandoc-templates/master/default.html5。
https://stackoverflow.com/questions/17223424
复制相似问题