Commit 8f746360e23e3bbacee134d07bde23037efed70b

Rob Brackett 2013-05-23T11:53:04

Use separate vars to track whether lookbehind is being used and the length of the lookbehind. Fixes #109.

diff --git a/components/prism-core.js b/components/prism-core.js
index 2f491c5..4822901 100644
--- a/components/prism-core.js
+++ b/components/prism-core.js
@@ -197,7 +197,8 @@ var _ = self.Prism = {
 			
 			var pattern = grammar[token], 
 				inside = pattern.inside,
-				lookbehind = !!pattern.lookbehind || 0;
+				lookbehind = !!pattern.lookbehind,
+				lookbehindLength = 0;
 			
 			pattern = pattern.pattern || pattern;
 			
@@ -220,11 +221,11 @@ var _ = self.Prism = {
 				
 				if (match) {
 					if(lookbehind) {
-						lookbehind = match[1].length;
+						lookbehindLength = match[1].length;
 					}
 
-					var from = match.index - 1 + lookbehind,
-					    match = match[0].slice(lookbehind),
+					var from = match.index - 1 + lookbehindLength,
+					    match = match[0].slice(lookbehindLength),
 					    len = match.length,
 					    to = from + len,
 						before = str.slice(0, from + 1),
diff --git a/prism.js b/prism.js
index 48e21c7..2a7cc77 100644
--- a/prism.js
+++ b/prism.js
@@ -203,7 +203,8 @@ var _ = self.Prism = {
 			
 			var pattern = grammar[token], 
 				inside = pattern.inside,
-				lookbehind = !!pattern.lookbehind || 0;
+				lookbehind = !!pattern.lookbehind,
+				lookbehindLength = 0;
 			
 			pattern = pattern.pattern || pattern;
 			
@@ -226,11 +227,11 @@ var _ = self.Prism = {
 				
 				if (match) {
 					if(lookbehind) {
-						lookbehind = match[1].length;
+						lookbehindLength = match[1].length;
 					}
 
-					var from = match.index - 1 + lookbehind,
-					    match = match[0].slice(lookbehind),
+					var from = match.index - 1 + lookbehindLength,
+					    match = match[0].slice(lookbehindLength),
 					    len = match.length,
 					    to = from + len,
 						before = str.slice(0, from + 1),