我正在尝试 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
APIimport 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
提供过滤器作为可执行文件。
applyFilters
,可让您通过提供可执行文件的路径来运行此类过滤器。
applyFilters :: ... -> Pandoc -> m Pandoc
您可以在
read
和 write
之间插入。
--
filterCrossRef :: Pandoc -> PandocIO Pandoc
filterCrossRef = applyFilters env ["pandoc-crossref"] []
需要一些额外的步骤才能将其嵌入到 hakyll
Compiler
monad 中(hakyll 中可能是 recompilingUnsafeCompiler
,pandoc 中可能是从 PandocIO
到 IO
)。
为了更好的可见性(我在谷歌搜索类似问题时找到了这个答案),这是我为
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"]
[]