jaspervdj / hakyll

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

Pandoc template syntax is not completely supported #1038

Open omentic opened 3 months ago

omentic commented 3 months 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 3 months 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 3 months ago

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

Minoru commented 3 months 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.

LaurentRDC commented 3 weeks ago

Recall that using pandoc with Hakyll is completely optional. You can compile pages using non-pandoc machinery. Hence, templating must be implemented in Hakyll.

It could be nice to support the pandoc template syntax -- I am happy to review pull requests -- but Hakyll's internal template machinery is here to stay