如何将 pandoc-crossref 与 Hakyll 一起使用

问题描述 投票:0回答:2

我正在尝试 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
,但那样我就不知道如何整合参考书目。

haskell pandoc hakyll
2个回答
3
投票

使用
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

尝试将其插入到

read
write
之间:

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

使用
pandoc-crossref
可执行文件

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

pandoc 库有一个函数

applyFilters
,可让您通过提供可执行文件的路径来运行此类过滤器。

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

您可以在

read
write
之间插入。

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

需要一些额外的步骤才能将其嵌入到 hakyll

Compiler
monad 中(hakyll 中可能是
recompilingUnsafeCompiler
,pandoc 中可能是从
PandocIO
IO
)。


0
投票

为了更好的可见性(我在谷歌搜索类似问题时找到了这个答案),这是我为

pandocCompiler
用户提供的解决方案:

对于

pandocCompiler
用户,这是为我解决问题的代码:

pandocCompilerWithTransformM defaultHakyllReaderOptions defaultHakyllWriterOptions plantumlFilter
  where
    plantumlFilter = recompilingUnsafeCompiler
      . runIOorExplode
      . applyFilters noEngine def
          [JSONFilter "/usr/local/lib/python3.9/site-packages/pandoc_plantuml_filter.py"]
          []
© www.soinside.com 2019 - 2024. All rights reserved.