comments in minifier

This commit is contained in:
Mikayla Fischler 2024-06-29 15:41:04 -04:00
parent f83eecf2e2
commit b025958173

View File

@ -39,7 +39,8 @@ def minify(path: str):
# '\' allows for multiline strings, which would require reverting to processing syntax line by line to support them # '\' allows for multiline strings, which would require reverting to processing syntax line by line to support them
raise Exception(f"no escaping newlines! (offending file: {path})") raise Exception(f"no escaping newlines! (offending file: {path})")
# drop the comments # drop the comments, unless the line has quotes, because quotes are scary
# (quotes are scary since we could actually be inside a string: "-- ..." shouldn't get deleted)
# -> whitespace before '--' and anything after that, which includes '---' comments # -> whitespace before '--' and anything after that, which includes '---' comments
minified = re.sub(r'\s*--+(?!.*[\'"]).*', '', contents) minified = re.sub(r'\s*--+(?!.*[\'"]).*', '', contents)