@@ -39,10 +39,7 @@ module Proxy {
3939 constructor ( text : string ) {
4040 this . _rootNodes = [ ] ;
4141 this . _text = text ;
42- }
4342
44- /** Returns an array containing ICssRuleset and ICssMediaQuery objects */
45- public parseCss ( ) : any [ ] {
4643 // Statement control
4744 this . _inComment = false ;
4845 this . _currentQuotationMark = "" ;
@@ -56,7 +53,32 @@ module Proxy {
5653 this . _currentRuleset = null ;
5754 this . _currentDeclaration = null ;
5855 this . _currentMediaQuery = null ;
56+ }
57+
58+ /** Returns an array containing ICssRuleset and ICssMediaQuery objects */
59+ public parseCss ( ) : any [ ] {
60+ this . parseText ( ) ;
61+
62+ // Put any text that wasn't valid CSS into it's own node at the end of the file
63+ this . handleIncompleteBlocks ( ) ;
64+ return this . _rootNodes ;
65+ }
66+
67+ /** Returns an array containing a single rule, ICssRuleset and ICssMediaQuery objects */
68+ public parseInlineCss ( ) : ICssRuleset {
69+ // inline CSS is just a list of properties. Set up the parser state to read them correctly.
70+ this . _currentRuleset = { originalOffset : this . _lastCheckpoint , selector : "DoesNotMatter" , declarations : [ ] } ;
71+ this . _state = CssToken . Property ;
72+
73+ this . parseText ( ) ;
74+
75+ Assert . isTrue ( this . _currentRuleset && this . _rootNodes . length === 0 , "Text was not valid inline CSS" ) ;
76+ this . _currentRuleset . endOffset = this . _text . length ;
77+
78+ return this . _currentRuleset ;
79+ }
5980
81+ private parseText ( ) : void {
6082 for ( this . _index = 0 ; this . _index < this . _text . length ; this . _index ++ ) {
6183 if ( this . handleQuoteCharacter ( ) ) {
6284 } else if ( this . handleCommentCharacter ( ) ) {
@@ -70,11 +92,6 @@ module Proxy {
7092 } else if ( this . handleSelectorCloseBracket ( ) ) {
7193 }
7294 }
73-
74- // Put any text that wasn't valid CSS into it's own node at the end of the file
75- this . handleIncompleteBlocks ( ) ;
76-
77- return this . _rootNodes ;
7895 }
7996
8097 private handleMediaQueryStart ( ) : boolean {
@@ -218,7 +235,7 @@ module Proxy {
218235 }
219236
220237 if ( this . _lastCheckpoint < this . _text . length - 1 ) {
221- var textNode : ICssRuleset = { selector : this . _text . substr ( this . _lastCheckpoint ) , originalOffset : this . _lastCheckpoint , declarations : null , endOffset : this . _index + 1 } ;
238+ var textNode : ICssRuleset = { selector : this . _text . substr ( this . _lastCheckpoint ) , originalOffset : this . _lastCheckpoint , declarations : null , endOffset : this . _index + 1 } ;
222239 this . _rootNodes . push ( textNode ) ;
223240 }
224241 }
0 commit comments