Use separate vars to track whether lookbehind is being used and the length of the lookbehind. Fixes #109.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
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),