Permalink
Browse files

Minification: Prevent extremely long lines

  • Loading branch information...
1 parent f2bb9fd commit f6fb6f7a7ad6a1947b51e05c85734ffd7c2f0f74 @encukou encukou committed Oct 16, 2011
Showing with 15 additions and 1 deletion.
  1. +15 −1 clevercss/engine.py
View
@@ -104,7 +104,21 @@ def to_css_min(self, context=None):
u';'.join(u'%s:%s' % kv for kv in defs))))
if current_media:
parts.append('}')
- return ''.join(parts)
+ result = ''.join(parts)
+
+ # Some browsers/editors choke on extremely long lines.
+ # Output lines of 2000 characters or more, broken after a closing brace
+ lines = []
+ try:
+ while True:
+ split_index = result.index('}', 2000) + 1
+ lines.append(result[:split_index])
+ result = result[split_index:]
+ except ValueError:
+ pass
+ lines.append(result)
+
+ return '\n'.join(lines)
class TokenStream(object):
"""

0 comments on commit f6fb6f7

Please sign in to comment.