Fixed serious highlighting bug, reduced known failures from 3 to 1
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
diff --git a/components/prism-javascript.js b/components/prism-javascript.js
index ce66820..1cd0d84 100644
--- a/components/prism-javascript.js
+++ b/components/prism-javascript.js
@@ -1,11 +1,14 @@
Prism.languages.javascript = {
'comment': /\/\*[\w\W]*?\*\//g,
+ 'line-comment': {
+ pattern: /(^|[^\\])\/\/.*?(\r?\n|$)/g,
+ lookbehind: true
+ },
+ 'string': /("|')(\\?.)*?\1/g,
'regex': {
pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}/g,
lookbehind: true
},
- 'line-comment': /\/\/.*?(\r?\n|$)/g,
- 'string': /("|')(\\?.)*?\1/g,
'keyword': /\b(var|let|if|else|while|do|for|return|in|instanceof|function|new|with|typeof|try|catch|finally|null|break|continue)\b/g,
'boolean': /\b(true|false)\b/g,
'number': /\b-?(0x)?\d*\.?\d+\b/g,
diff --git a/components/prism-javascript.min.js b/components/prism-javascript.min.js
index fb169ad..1a0d247 100644
--- a/components/prism-javascript.min.js
+++ b/components/prism-javascript.min.js
@@ -1 +1 @@
-Prism.languages.javascript={comment:/\/\*[\w\W]*?\*\//g,regex:{pattern:/(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}/g,lookbehind:!0},"line-comment":/\/\/.*?(\r?\n|$)/g,string:/("|')(\\?.)*?\1/g,keyword:/\b(var|let|if|else|while|do|for|return|in|instanceof|function|new|with|typeof|try|catch|finally|null|break|continue)\b/g,"boolean":/\b(true|false)\b/g,number:/\b-?(0x)?\d*\.?\d+\b/g,operator:/[-+]{1,2}|!|=?<|=?>|={1,2}|(&){1,2}|\|?\||\?|\*|\//g,ignore:/&(lt|gt|amp);/gi,punctuation:/[{}[\];(),.:]/g};
\ No newline at end of file
+Prism.languages.javascript={comment:/\/\*[\w\W]*?\*\//g,"line-comment":{pattern:/(^|[^\\])\/\/.*?(\r?\n|$)/g,lookbehind:!0},string:/("|')(\\?.)*?\1/g,regex:{pattern:/(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}/g,lookbehind:!0},keyword:/\b(var|let|if|else|while|do|for|return|in|instanceof|function|new|with|typeof|try|catch|finally|null|break|continue)\b/g,"boolean":/\b(true|false)\b/g,number:/\b-?(0x)?\d*\.?\d+\b/g,operator:/[-+]{1,2}|!|=?<|=?>|={1,2}|(&){1,2}|\|?\||\?|\*|\//g,ignore:/&(lt|gt|amp);/gi,punctuation:/[{}[\];(),.:]/g};
\ No newline at end of file
diff --git a/examples.html b/examples.html
index ca7aa65..309d13c 100644
--- a/examples.html
+++ b/examples.html
@@ -163,6 +163,10 @@ var comment = /\/\*[\w\W]*?\*\//g;</code></pre>
<h2>Strings with slashes</h2>
<pre><code>env.content + '</' + env.tag + '>'</code></pre>
+ <pre><code>var foo = "/" + "/";</code></pre>
+
+ <h2>Regex inside single line comment</h2>
+ <pre><code>// hey, /this doesn’t fail!/ :D</code></pre>
</section>
<section id="failures" class="language-javascript">
@@ -173,14 +177,8 @@ var comment = /\/\*[\w\W]*?\*\//g;</code></pre>
If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
</p>
- <h2>Two strings with slashes on the same line</h2>
- <pre><code>var foo = "/" + "/";</code></pre>
-
<h2>Comment-like strings</h2>
<pre><code>"foo /* bar */ baz"; "foo // bar";</code></pre>
-
- <h2>Regex inside single line comment</h2>
- <pre><code>// hey, /this fails/ :(</code></pre>
</section>
<footer data-src="templates/footer.html" data-type="text/html"></footer>
diff --git a/prism.js b/prism.js
index d082ec6..512c55c 100644
--- a/prism.js
+++ b/prism.js
@@ -300,12 +300,15 @@ Prism.languages.css = {
Prism.languages.javascript = {
'comment': /\/\*[\w\W]*?\*\//g,
+ 'line-comment': {
+ pattern: /(^|[^\\])\/\/.*?(\r?\n|$)/g,
+ lookbehind: true
+ },
+ 'string': /("|')(\\?.)*?\1/g,
'regex': {
pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}/g,
lookbehind: true
},
- 'line-comment': /\/\/.*?(\r?\n|$)/g,
- 'string': /("|')(\\?.)*?\1/g,
'keyword': /\b(var|let|if|else|while|do|for|return|in|instanceof|function|new|with|typeof|try|catch|finally|null|break|continue)\b/g,
'boolean': /\b(true|false)\b/g,
'number': /\b-?(0x)?\d*\.?\d+\b/g,