Created
May 4, 2021 19:27
-
-
Save takkaria/d75493e57e97483fb76ce0d57f0b9b8e to your computer and use it in GitHub Desktop.
sketch for a django template autoformatter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img src="..."> | |
<img {{ variable }}> | |
<img {{ variable }}="..."> | |
<img {% tag %}> | |
<img {% if variable %}attr="..."{% else %}attr=",,,"{% endif %}> | |
<img src="{{ variable }}"> | |
<img src="{% tag %}"> | |
<img src="{% if variable %}...{% else %}...{% endif %}"> | |
<img class="className {% if variable %}freddo{% else %}greggo{% endif %} meowMeow"> | |
type Token | |
= StartTag List[Attributes] | |
| EndTag | |
| Expression | |
| DjangoSoloTag | |
| DjangoBlockTag | |
| DjangoBlockEndTag | |
type StartTag = String, Attribute[] | |
type Attribute = (AttrName, AttrValue[]) | AttrName | |
type AttrName = String | Expression | DjangoSoloTag | DjangoBlockTag | |
type AttrValue = String | Expression | DjangoSoloTag | DjangoBlockTag | |
type DjangoBlockTag = IfBlock | Block | |
type Block = { | |
open: String, | |
end: String, | |
children: Token[] | |
} | |
type IfBlock = IfClause[] | |
type IfClause = (Expression, Token[]) | |
<img class="className {% if variable %}freddo{% elif var2 %}narco{% else %}greggo{% endif %} meowMeow"> | |
OpenTag "img" | |
AttributeName "class" | |
StartAttributeValue | |
String "className " | |
DjangoBlock "if variable" | |
String "freddo" | |
DjangoBlock "elif var2" | |
String "narco" | |
DjangoBlock "else" | |
String "greggo" | |
DjangoBlock " meowMeow" | |
EndAttributeValue | |
StartTag { | |
"img", [ | |
"class", [ | |
"className ", | |
IfBlock [ | |
("variable", "freddo"), | |
("var2", "narco"), | |
("1", "greggo") | |
], | |
" meowMeow", | |
] | |
] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment