繁体   English   中英

如何在 Hakyll 中使用 pandoc-crossref

[英]How to use pandoc-crossref with Hakyll

我正在为一个以学术和数学为主的 static 网站试用Hakyll 我想使用pandoc-crossref来交叉引用方程式。

pandoc-crossref包含到编译器链中的最简单方法是什么?

到目前为止,我能够像这样将参考书目集成到编译器中

pandocComplilerWithBibAndOptions :: Compiler (Item String)
pandocComplilerWithBibAndOptions = do
    csl <- load $ fromFilePath "apa.csl"
    bib <- load $ fromFilePath "bibliography.bib"
    fmap write (getResourceString >>= read csl bib)
    where
        read = readPandocBiblio readerOptions
        write = writePandocWith writerOptions
        readerOptions = defaultHakyllReaderOptions {
            readerExtensions = newExtentions <> pandocExtensions
        }
        writerOptions = defaultHakyllWriterOptions {
            writerExtensions = newExtentions <> pandocExtensions,
            writerHTMLMathMethod = MathJax ""
        }
        newExtentions = extensionsFromList  [Ext_tex_math_double_backslash,
                                             Ext_citations,
                                             Ext_latex_macros]

main :: IO ()
main = hakyll $ do
    ...

    match "posts/*" $ do
        route $ setExtension "html"
        compile $ pandocComplilerWithBibAndOptions
            >>= loadAndApplyTemplate "templates/post.html"    postCtx
            >>= loadAndApplyTemplate "templates/default.html" postCtx
            >>= relativizeUrls

    match "*.bib" $ compile biblioCompiler
    match "*.csl" $ compile cslCompiler

   ...

虽然这很好用,但我对如何集成交叉引用一无所知。 我最好的选择是将其表达为某种转换并使用pandocCompileWithTransformM ,但我不知道如何整合参考书目。

使用Text.Pandoc.CrossRef API

import Text.Pandoc.CrossRef
import Text.Pandoc.Definition (Pandoc) -- pandoc-types

crossRef :: Pandoc -> Pandoc
crossRef = runCrossRef meta Nothing defaultCrossRefAction
  where
    meta = defaultMeta  -- Settings for crossref rendering

尝试在readwrite之间插入这个:

    fmap (write . fmap crossRef) (getResourceString >>= read csl bib)

使用pandoc-crossref可执行文件

pandoc-crossref提供了一个过滤器作为可执行文件。

pandoc 库有一个 function applyFilters ,它允许您通过提供可执行文件的路径来运行此类过滤器。

applyFilters :: ... -> Pandoc -> m Pandoc

您可以在readwrite之间插入。

-- 
filterCrossRef :: Pandoc -> PandocIO Pandoc
filterCrossRef = applyFilters env ["pandoc-crossref"] []

将其嵌入到 hakyll Compiler monad 中需要一些额外的步骤(可能是 hakyll 中的recompilingUnsafeCompiler和 pandoc 中从PandocIOIO的东西)。

暂无
暂无

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

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