-
-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quoted strings as tag arguments have their quotes escaped and preserved #235
Comments
I took a look at the built-in In other words, I don't think it's currently possible to write a
=>
Removing the literal quotes formats the output as desired, but—of course—treats the strings as four separate arguments:
=>
My desired output (in this specific example) is:
Is there any tag syntax workaround to achieve that? Note that this behavior also applies to I definitely could add a |
Yeah, the best option at the moment is to do replace in the custom tag. I'd be open to adding support for handling quoted strings, but I probably won't be able to get around to it in the near future. If you'd be ok doing a PR for this, I could certainly help with that. |
Alright, I'll see if I have time to learn how to approach this! But for now will do the Would you prefer that this change the default behavior (quotes always get removed, but that technically would break backward compatibility), or be a new setting on the parser, like Also would need to figure out how it could support quotes if they are desired in output strings. Probably via a double-escaping like |
I think it would be best to avoid breaking changes to make upgrading smoother, so escaping would be preferable. |
the render function could preserve the old behavior via and options field, or add the behavior via options. |
Yeah, adding flags to hint behavior would be a reasonable approach here. |
Obviously I didn't get to this—sorry! Still eager to try, but I'm very very new to Clojure so would take me a while and I may need help. Feel free to take it on someone else before I do! |
Definitely no rush, and if you do get around to it then I'm happy to help with a review. |
We rely on this behavior explicitly at work, with a custom tag we've added that takes arguments generated by a (JS) preprocessor. We check in the tag if the argument starts and ends with Which is a long-winded way of saying "please don't change the default behavior but make this possible via some option to the render functions". |
PR: #304 adds |
And new release 1.12.59 is up on Clojars with the feature. |
Is it possible to have a quoted string as an argument to a tag, without the surrounding quotes being preserved in the output?
Selmer, as expected, does treat the quoted string as a single argument, but passes the string to the tag function with its quotes, escaped, as part of the string.
Or perhaps there's another notation which allows a string with spaces to be treated as a single argument?
Using
render-file
removes the need to escape the quotes in the template file, but still introduces them in the output:file.txt:
The
{% safe %}
tag has no discernible effect:file.txt:
The text was updated successfully, but these errors were encountered: