Skip to content

Commit

Permalink
Merge pull request #91 from rtts/css-urls
Browse files Browse the repository at this point in the history
Don't treat `//` inside URL as comment
  • Loading branch information
JaapJoris authored Mar 9, 2023
2 parents 5505a1a + 541247c commit 04edbe9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion djhtml/modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,15 @@ class DjCSS(DjTXT):
"""

RAW_TOKENS = DjTXT.RAW_TOKENS + [
r"</style>",
r"://",
r"//.*",
r"[{()}]",
r"/\*",
r'"(?:\\.|[^\\"])*"', # "string"
r"'(?:\\.|[^\\'])*'", # 'string'
r"[\w-]+: ",
r";",
r"</style>",
]

def create_token(self, raw_token, src, line):
Expand Down
1 change: 1 addition & 0 deletions tests/suite/css.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
div {
foo: bar; // comment: ignore
font-weight: bold;
background: url(http://not.a.comment);
}
</style>

Expand Down
1 change: 1 addition & 0 deletions tests/suite/css.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ Line([Text('<', mode=DjHTML), Text('style', mode=InsideHTMLTag, absolute=7), Ope
Line([Text(' div ', mode=DjCSS), Open('{', mode=DjCSS, level=1)], level=1)
Line([Text(' ', mode=DjCSS), Text('foo: ', mode=DjCSS), Text('bar', mode=DjCSS, absolute=5), Text(';', mode=DjCSS), Text(' ', mode=DjCSS), Text('// comment: ignore', mode=DjCSS, ignore=True)], level=2)
Line([Text(' ', mode=DjCSS), Text('font-weight: ', mode=DjCSS), Text('bold', mode=DjCSS, absolute=13), Text(';', mode=DjCSS)], level=2)
Line([Text(' ', mode=DjCSS), Text('background: ', mode=DjCSS), Text('url', mode=DjCSS, absolute=12), Open('(', mode=DjCSS, level=2), Text('http', mode=DjCSS), Text('://', mode=DjCSS), Text('not.a.comment', mode=DjCSS), Close(')', mode=DjCSS), Text(';', mode=DjCSS)], level=2)
Line([Text(' ', mode=DjCSS), Close('}', mode=DjCSS)], level=1)
Line([Close('</style>', mode=DjHTML)])
Line([])
Expand Down

0 comments on commit 04edbe9

Please sign in to comment.