@@ -188,12 +188,41 @@ function removeDuplicateAttributes(attrs) {
188188 return res ;
189189}
190190
191+ /**
192+ * Processes a conditional comment
193+ * @param {String } comment
194+ * @param {Function } modify
195+ * @param {Object } options
196+ * @returns {String|undefined }
197+ */
198+ function getConditionalComment ( comment , modify , options ) {
199+ var START_IF = '^\\s*\\[if .*\\]>' ,
200+ END_IF = '<!\\[endif\\]\\s*$' ,
201+ matchedStartIF = comment . match ( new RegExp ( START_IF ) ) ,
202+ matchedEndIF = comment . match ( new RegExp ( END_IF ) ) ;
203+
204+ if ( comment . match ( new RegExp ( START_IF + '\\s*$' ) ) || comment . match ( new RegExp ( START_IF + '<!\\s*$' ) ) ||
205+ comment . match ( new RegExp ( '^' + END_IF ) ) ) {
206+ return comment . trim ( ) ;
207+ }
208+
209+ if ( matchedStartIF && matchedEndIF ) {
210+ var start = matchedStartIF [ 0 ] ,
211+ end = matchedEndIF [ 0 ] ,
212+ modified = modify ( comment . substring ( start . length , matchedEndIF . index ) , options ) ;
213+
214+ return ( start + modified + end ) . trim ( ) ;
215+ }
216+ }
217+
191218module . exports = {
192219 sortAttrs : sortAttrs ,
193220 sortCssClasses : sortCssClasses ,
194221 sortAttrsValues : sortAttrsValues ,
195222
196223 removeAttrsValues : removeAttrsValues ,
197224 removeWhitespaces : removeWhitespaces ,
198- removeDuplicateAttributes : removeDuplicateAttributes
225+ removeDuplicateAttributes : removeDuplicateAttributes ,
226+
227+ getConditionalComment : getConditionalComment
199228} ;
0 commit comments