askama icon indicating copy to clipboard operation
askama copied to clipboard

Using three-character delimiters.

Open danielfaust opened this issue 2 years ago • 5 comments

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.

danielfaust avatar Jan 15 '23 23:01 danielfaust

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 avatar Jan 16 '23 08:01 djc

@djc, the need for two character delimiters was lifted in #541. Yeah, I think its reasonable to remove the check in config.rs:167.

Kijewski avatar Jan 18 '23 03:01 Kijewski

Ah, cool, I couldn't quickly find it. @danielfaust would you be able to submit a PR to remove the restriction?

djc avatar Jan 18 '23 09:01 djc

@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.

danielfaust avatar Jan 18 '23 12:01 danielfaust

I would replace all instances of .len() != 2 with .len() < 2 and adapt the error message.

This sounds good to me!

djc avatar Jan 18 '23 12:01 djc

Resolved in #820.

Kijewski avatar Jun 06 '24 19:06 Kijewski