I need to incorporate user submitted content in my website. For this I’d like to accept markdown, but still while disallowing parts of the spec, like images, for example. So, something like:
It’s a bit tricky to implement I think. Right now the markdown filter uses the same code as for pages/sections, including shortcodes/internal links.
I’m guessing you don’t want those either so you would need a different rendering pipeline. But then, do you want syntax highlighting etc?
What should happen with the disallowed tags (I’d prefer allow rather than disallow)? Silently dropped? An error?
Yeah, that makes sense regarding the pipeline and how that might make things difficult to change. I haven’t looked at the zola code in a while either.
I’m guessing you don’t want those either
I actually am perfectly fine with the default Zola markdown → HTML pipeline for pages and sections as is now. For more context, I’m accepting comments on a website of mine, and each comment is saved as a toml table in .toml file, collated with my pages. I use the markdown filter from within a macro to build the comment listings. So in my case, just adding the feature to the filter is enough.
What should happen with the disallowed tags (I’d prefer allow rather than disallow)? Silently dropped? An error?
I was thinking they’d just have their HTML tags stripped and the plaintext form of the markdown is what would be shown. That way, it’s still readable, and it doesn’t lead to broken builds.
So I was able to achieve this actually with tera filters, although the code is a little crazy, since the string processing in tera is very limited. Just a macro with a lot of split and join, and some slicing.
Anyways, one of the oddities that I encountered is that
{# this renders as an html string #}
{{ util::filter_md(md=txt, disallow=["img"]) | safe }}
Would behave differently from storing it as a variable, and putting that in an expression
{# this renders as actual html #}
{% set temp = util::filter_md(md=txt, disallow=["img"] %}
{{ temp | safe }}
I’m just curious if this is expected behavior? It seems like they should be the same, but they’re not.