chiark / gitweb /
css: strip trailing comments in postprocess.py.
authorVladimír Vondruš <mosra@centrum.cz>
Sun, 3 Dec 2017 13:31:00 +0000 (14:31 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Mon, 4 Dec 2017 18:20:40 +0000 (19:20 +0100)
Could get me back under 9 kB.

css/postprocess.py

index 555076f946c9ed5e0cbc3fecca939f0a272bcd4b..9ff7810688abdda042c9b81ae1032b8ac9fd193c 100755 (executable)
@@ -129,7 +129,12 @@ def postprocess(files):
                 if in_variable_declarations:
                     out.write(":root {\n")
                     not_just_variable_declarations = True
-                out.write(line)
+
+                # Strip the trailing comment, if there, to save some bytes
+                if line.rstrip().endswith('*/'):
+                    out.write(line[:line.rindex('/*')])
+                else:
+                    out.write(line)
 
         # Now open the imported files and replace variables
         for file in imported_files + files[1:]:
@@ -163,8 +168,12 @@ def postprocess(files):
                         in_comment = True
                         continue
 
-                    # Something else, copy verbatim to the output
-                    out.write(line)
+                    # Something else, copy verbatim to the output. Strip the
+                    # trailing comment, if there, to save some bytes
+                    if line.rstrip().endswith('*/'):
+                        out.write(line[:line.rindex('/*')].rstrip() + '\n')
+                    else:
+                        out.write(line)
 
     return 0