@@ -42,7 +42,7 @@ def __repr__(self):
4242indent_char = [%s]
4343separate_selectors_newline = [%s]
4444end_with_newline = [%s]
45- """ % (self .indent_size , self .indent_char ,
45+ """ % (self .indent_size , self .indent_char ,
4646 self .separate_selectors , self .end_with_newline )
4747
4848
@@ -91,7 +91,7 @@ def __init__(self, indent_char, indent_size, default_indent=""):
9191
9292 def __lastCharWhitespace (self ):
9393 return WHITE_RE .search (self .output [len (self .output ) - 1 ]) is not None
94-
94+
9595 def indent (self ):
9696 self .indentString += self .singleIndent
9797
@@ -129,7 +129,7 @@ def newLine(self, keepWhitespace=False):
129129
130130 if len (self .output ) > 0 :
131131 self .output .append ("\n " )
132-
132+
133133 if len (self .indentString ) > 0 :
134134 self .output .append (self .indentString )
135135
@@ -189,19 +189,28 @@ def skipWhitespace(self):
189189 pass
190190 return self .pos != start + 1
191191
192- def eatComment (self ):
192+ def eatComment (self , singleLine ):
193193 start = self .pos
194194 self .next ()
195195 while self .next ():
196196 if self .ch == "*" and self .peek () == "/" :
197197 self .pos = self .pos + 1
198198 break
199+ elif singleLine and self .ch == "\n " :
200+ break
199201 return self .source_text [start :self .pos + 1 ]
200202
201203 def lookBack (self , string ):
202204 past = self .source_text [self .pos - len (string ):self .pos ]
203205 return past .lower () == string
204206
207+ def isCommentOnLine (self ):
208+ endOfLine = self .source_text .find ('\n ' , self .pos )
209+ if endOfLine == - 1 :
210+ return False ;
211+ restOfLine = self .source_text [self .pos :endOfLine ]
212+ return restOfLine .find ('//' ) != - 1
213+
205214 def beautify (self ):
206215 m = re .search ("^[\r \n ]*[\t ]*" , self .source_text )
207216 indentString = m .group (0 )
@@ -214,11 +223,14 @@ def beautify(self):
214223 if not self .ch :
215224 break
216225 elif self .ch == '/' and self .peek () == '*' :
217- comment = self .eatComment ()
226+ comment = self .eatComment (False )
218227 printer .comment (comment )
219228 header = self .lookBack ("" )
220229 if header :
221230 printer .push ("\n \n " )
231+ elif self .ch == '/' and self .peek () == '/' :
232+ printer .comment (self .eatComment (True )[0 :- 1 ])
233+ printer .newLine ()
222234 elif self .ch == '{' :
223235 self .eatWhitespace ()
224236 if self .peek () == '}' :
@@ -238,7 +250,14 @@ def beautify(self):
238250 elif self .ch == '"' or self .ch == '\' ' :
239251 printer .push (self .eatString (self .ch ))
240252 elif self .ch == ';' :
241- printer .semicolon ()
253+ if self .isCommentOnLine ():
254+ beforeComment = self .eatString ('/' )
255+ comment = self .eatComment (True )
256+ printer .push (beforeComment )
257+ printer .push (comment [1 :- 1 ])
258+ printer .newLine ()
259+ else :
260+ printer .semicolon ()
242261 elif self .ch == '(' :
243262 # may be a url
244263 if self .lookBack ("url" ):
0 commit comments