1010var indent = ( function ( root ) {
1111 var rulesCache = { } ;
1212
13+ function map ( array , predicate ) {
14+ var i , results = [ ] ;
15+ for ( i = 0 ; i < array . length ; i ++ ) {
16+ results . push ( predicate ( array [ i ] , i , array ) ) ;
17+ }
18+ return results ;
19+ }
20+
21+ function some ( array , predicate ) {
22+ var i , result ;
23+ for ( i = 0 ; i < array . length ; i ++ ) {
24+ result = predicate ( array [ i ] , i , array ) ;
25+ if ( result ) {
26+ return result ;
27+ }
28+ }
29+ return false ;
30+ }
31+
1332 function filterRules ( language , rules , excludes ) {
1433 if ( rulesCache [ language ] )
1534 return rulesCache [ language ] ;
@@ -32,6 +51,7 @@ var indent = (function (root) {
3251 }
3352
3453 var NEW_LINE_REGEX = / \r * \n / ;
54+ var HTML_TAG_RULES = [ "tag" , "void-tags" , "html-tag" ] ;
3555
3656 /**
3757 * Soft dedent: this type of dedent has the opposite effect and will actually indent every line
@@ -48,6 +68,7 @@ var indent = (function (root) {
4868 * $matchBeginning - match at beginning of line only
4969 * $languages - used to filter by language later
5070 * $lineOffset - added to the line field when rule is applied
71+ * $excludeIf - used to exclude rule matching if any of these rules are active
5172 * $lastRule - used to continue a previous rule
5273 * $newScope - used to determine if rule creates a new scope, used for lastRule
5374 *
@@ -57,7 +78,7 @@ var indent = (function (root) {
5778 */
5879 var MASTER_RULES = [
5980 {
60- $languages : "html" ,
81+ $languages : "js html" ,
6182 $name : "comment" ,
6283 $startPatterns : [ / \< \! \- \- / ] ,
6384 $endPatterns : [ / \- \- \> / ] ,
@@ -73,7 +94,7 @@ var indent = (function (root) {
7394 $consumeEndMatch : true
7495 } ,
7596 {
76- $languages : "html" ,
97+ $languages : "js html" ,
7798 $name : "void-tags" ,
7899 $startPatterns : [
79100 / \< ( a r e a | b a s e | b r | c o l | c o m m a n d | e m b e d | h r | i m g | i n p u t | k e y g e n | l i n k | m e n u i t e m | m e t a | p a r a m | s o u r c e | t r a c k | w b r ) / i] ,
@@ -135,10 +156,10 @@ var indent = (function (root) {
135156 $consumeEndMatch : true
136157 } ,
137158 {
138- $languages : "html" ,
159+ $languages : "js html" ,
139160 $name : "tag" ,
140161 $startPatterns : [ function ( string , rule , state ) {
141- var re = / < ( [ A - Z a - z 0 - 9 \- ] + ) / ;
162+ var re = / < ( [ A - Z a - z ] [ A - Z a - z 0 - 9 \- \. ] * ) / ;
142163 var match = string . match ( re ) ;
143164 if ( match ) {
144165 state . openingTag = match [ 1 ] ;
@@ -151,7 +172,7 @@ var indent = (function (root) {
151172 }
152173 } ] ,
153174 $endPatterns : [ function ( string , rule , state ) {
154- var re = new RegExp ( "</" + state . openingTag + ">" , "i" ) ;
175+ var re = new RegExp ( "<\ /" + state . openingTag + ">|\\s\/ >" , "i" ) ;
155176 var match = string . match ( re ) ;
156177 if ( match ) {
157178 return {
@@ -228,16 +249,18 @@ var indent = (function (root) {
228249 $consumeEndMatch : true
229250 } ,
230251 {
231- $languages : "html" ,
252+ $languages : "js html" ,
232253 $name : "quotes" ,
254+ $excludeIf : HTML_TAG_RULES ,
233255 $startPatterns : [ / " / ] ,
234256 $endPatterns : [ / " / , NEW_LINE_REGEX ] ,
235257 $ignoreRules : true ,
236258 $consumeEndMatch : true
237259 } ,
238260 {
239- $languages : "html" ,
261+ $languages : "js html" ,
240262 $name : "quotes" ,
263+ $excludeIf : HTML_TAG_RULES ,
241264 $startPatterns : [ / ' / ] ,
242265 $endPatterns : [ / ' / , NEW_LINE_REGEX ] ,
243266 $ignoreRules : true ,
@@ -381,6 +404,7 @@ var indent = (function (root) {
381404 {
382405 $languages : "js" ,
383406 $name : "=" ,
407+ $excludeIf : HTML_TAG_RULES ,
384408 $startPatterns : [ / = / ] ,
385409 $endPatterns : [ / [ , ; \) \] } ] / , NEW_LINE_REGEX ]
386410 } ,
@@ -598,10 +622,16 @@ var indent = (function (root) {
598622
599623 var lastMatch = lastMatches [ lastMatches . length - 1 ] ;
600624 var lastRuleInScope = lastMatch ? lastMatch . rule . $name : '' ;
625+ var activeRules = map ( activeMatches , function ( match ) {
626+ return match . rule . $name ;
627+ } ) . join ( '\n' ) ; // Use \n as a special delimiter for rule names
601628
602629 for ( var rule , r = 0 ; r < rules . length ; r ++ ) {
603630 rule = rules [ r ] ;
604- if ( ! rule . $lastRule ||
631+ if ( rule . $excludeIf && some ( rule . $excludeIf , function ( excludeRule ) {
632+ return activeRules . indexOf ( excludeRule ) != - 1 ;
633+ } ) ) {
634+ } else if ( ! rule . $lastRule ||
605635 ( lastRuleInScope && rule . $lastRule . indexOf ( lastRuleInScope ) !== - 1 )
606636 ) {
607637 match = searchAny ( string , rule . $startPatterns , rule ) ;
0 commit comments