jaspervdj / hakyll

A static website compiler library in Haskell
jaspervdj.be/hakyll
Other
2.68k stars 409 forks source link

Pandoc template syntax is not completely supported #1038

Open omentic opened 1 month ago

omentic commented 1 month ago

Hakyll recognizes content within the $...$ deliminators in templates as pandoc template syntax, and supports insertation of variables and usage of pandoc control structures within them.

But Pandoc has an alternative syntax that Hakyll does not seem to recognize: ${...}. I was a little surprised by this when first getting Hakyll set up.

[ERROR] _templates/post.html: Cannot parse template "_templates/post.html" (line 14, column 2):
    unexpected "{"
    expecting "-", "if(", "for(", "partial(", "\"" or letter

Could this syntax be supported? It is not at all an important request, but it would be nice for Hakyll to behave more similarly to Pandoc here.

Minoru commented 1 month ago

Yeah, Hakyll has its own implementation of templates, that's why there's a disparity in syntax. I think it'd be easy enough to fix: the Parsec parser for templates is defined in lib/Hakyll/Web/Template/Internal/Element.hs. Opening and closing dollar signs are parsed by trimOpen and trimClose. I think these will have to be replaced by some sort of a "bracketing" function, which should then be enhanced to support the curly-bracket syntax.

omentic commented 1 month ago

Why does Hakyll have its own implementation of templates, out of curiosity?

Minoru commented 1 month ago

I checked Git and it seems that Pandoc added its templates a couple years before Hakyll did, so now I'm curious myself! @jaspervdj can answer authoritatively.