Closed slotThe closed 4 weeks ago
Out of curiosity, what would the code look like if you used renderPandocItemWithTransformM
and pandocItemCompilerWithTransformM
?
Would it be simpler than implementing a Compiler (Item String)
function directly without bothering with a derived compiler like pandocItemCompilerWithTransformM
? E.g., I do something similar with my own website:
articleCompiler :: Compiler (Item String)
articleCompiler = do
let readerOptions = mathReaderWith defaultHakyllReaderOptions
writerOptions <- getTocOptionsWith $ mathWriterWith defaultHakyllWriterOptions
bibFile <- load "article/bibliography/references.bib"
cslFile <- load "article/bibliography/acm.csl"
getResourceBody
>>= readPandocWith readerOptions
>>= pure . fmap (setMeta "link-citations" True)
>>= processPandocBiblio cslFile bibFile
>>= pure . writePandocWith writerOptions
Out of curiosity, what would the code look like if you used
renderPandocItemWithTransformM
andpandocItemCompilerWithTransformM
?
The basic setup wouldn't be much more difficult, if a bit uglier in my opinion:
myPandocCompiler :: Compiler (Item String)
myPandocCompiler = do
csl <- load @CSL "bib/style.csl"
bib <- load @Biblio "bib/bibliography.bib"
getResourceBody
>>= readPandocWith defaultHakyllReaderOptions
>>= traverse ( pure . usingSideNotesHTML myWriter
<=< pygmentsHighlight
. addSectionLinks
. smallCaps
. setMeta "link-citations" True
)
>>= ((fmap . fmap) (tableiseBib . insertRefHeading) . processPandocBiblio csl bib)
<&> writePandocWith myWriter
The bigger problem is that this doesn't work with my setup, as I also have a dedicated RSS compiler that skips many of these steps, as e.g. sidenotes do not make sense without CSS. Since now the main compiler has bibliographic information baked into it, I would have to rewrite this in some clever way, and make the big traverse
block more modular; I reckon I would end up at exactly something like pandocItemCompilerWithTransformM
.
@Minoru friendly ping :)
Great, thank you!
Thanks @LaurentRDC!
Add
renderPandocItemWithTransformM
andpandocItemCompilerWithTransformM
, which work like the respective functions without the "item" infix, but the transformation function is a monadic "Item Pandoc -> Item Pandoc" instead of just a "Pandoc -> Pandoc". This allows one to more seamlessly compose functions that do require the extra information that an item provides, like bibliographic transformations.My specific use-case for this is exactly adding a nicely formatted bibliography at the end of certain pages. Here is a real world example with entirely too much code: