askama
askama copied to clipboard
Using three-character delimiters.
I have an issue with trying to use the following in askama.toml
[[syntax]]
name = "python"
expr_start = "{@@"
expr_end = "@@}"
where I then get the compile error
error: length of delimiters must be two
This is due to the constraint set in config.rs.
I just started with Rust and coming from Python I've used Jinja2 extensively, where I always used the following configuration
aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader('html'), variable_start_string='{@@', variable_end_string='@@}')
I started with this three-character delimiter very early on and have years of templates using this format because this would ensure that it would never collide with JavaScript frameworks.
Is there a chance of allowing longer delimiters or is there a special reasoning for imposing this limitation?
Thank you a lot for putting your time into creating askama.
I think the parser was originally optimized for two-character delimiters, but looking at the code now I no longer see code where this would be an issue. So maybe we can lift that restriction? @Kijewski do you remember this?
@djc, the need for two character delimiters was lifted in #541. Yeah, I think its reasonable to remove the check in config.rs:167.
Ah, cool, I couldn't quickly find it. @danielfaust would you be able to submit a PR to remove the restriction?
@djc, sure, I will do it. I will first review it a bit, but have one question to make it easier for me: Is it only the length of the corresponding block of code which needs to be adjusted? I would replace all instances of .len() != 2 with .len() < 2 and adapt the error message.
I would replace all instances of
.len() != 2with.len() < 2and adapt the error message.
This sounds good to me!
Resolved in #820.