tree-sitter-htmldjango
                                
                                
                                
                                    tree-sitter-htmldjango copied to clipboard
                            
                            
                            
                        As a person who wants to translate strings, I would like support for "string | filter"
Thank you for adding django support to tree-sitter!
I was wondering if it could be possible to add support for the syntax below:
<html>
  {{ "foo" }}
  {{ 'foo'|filter }}
  {{ "foo"|filter:argument }}
</html>
My usecase is to use it for translations:
{{ 'Hello %1!' | i18n }}
                                    
                                    
                                    
                                
Thanks for the issue! The Django docs are very specific regarding variable names:
Variable names consist of any combination of alphanumeric characters and the underscore ("_") but may not start with an underscore, and may not be a number. The dot (".") also appears in variable sections, although that has a special meaning, as indicated below. Importantly, you cannot have spaces or punctuation characters in variable names.
It never occurred to me that any other characters (i.e. quotes) should be checked for, since I only considered the case of variables names (and optional filters) contained within {{ }} and not string literals like your example.
Can you find any documentation that demonstrates this syntax?
Happened to be reading the Django docs right after seeing this post and came across the example of {{ my_date|date:"Y-m-d" }} in Template Filters,
That case should work fine as is, since the string is used as an argument to the date filter.
Sorry for not following up š„ In my case, it's not a variable on the left side of the pipe. It's simple a string literal. Like "Hello " in the example below:
{{ "Hello " ~ name ~ "!" }}
I couldn't find the specification, but this sure works:
 {{ "string literatl" | filter:argument }}
                                    
                                    
                                    
                                
Since your use case is translation, should you not be using the translate template tag?
The point is not if Iām using it for translation or not. The idea is to have valid syntax highlighting for strings.
Apologies for being particular about this but sometimes when issues are opened it is because a user is using incorrect syntax, not a fault of the grammar. In this case the syntax is undocumented (at least I can't find any official reference), but does work based on my own testing as well, so it should be supported. I will work on implementing it.
Thank you š
I have implemented support for string literals inside expressions (3a64316).