Merged the comment and line-comment tokens

This commit is contained in:
Lea Verou 2012-07-31 16:17:53 +12:00
parent ed944399b8
commit e95a85c02e
8 changed files with 44 additions and 11 deletions

View File

@ -1,7 +1,6 @@
Prism.languages.javascript = {
'comment': /\/\*[\w\W]*?\*\//g,
'line-comment': {
pattern: /(^|[^\\])\/\/.*?(\r?\n|$)/g,
'comment': {
pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|\/\/.*?(\r?\n|$))/g,
lookbehind: true
},
'string': /("|')(\\?.)*?\1/g,

View File

@ -1 +1 @@
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}(?=\s*($|[\r\n,.;})]))/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}|!|=?&lt;|=?&gt;|={1,2}|(&amp;){1,2}|\|?\||\?|\*|\//g,ignore:/&(lt|gt|amp);/gi,punctuation:/[{}[\];(),.:]/g};Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{script:{pattern:/(&lt;|<)script[\w\W]*?(>|&gt;)[\w\W]*?(&lt;|<)\/script(>|&gt;)/ig,inside:{tag:{pattern:/(&lt;|<)script[\w\W]*?(>|&gt;)|(&lt;|<)\/script(>|&gt;)/ig,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.javascript}}});
Prism.languages.javascript={comment:{pattern:/(^|[^\\])(\/\*[\w\W]*?\*\/|\/\/.*?(\r?\n|$))/g,lookbehind:!0},string:/("|')(\\?.)*?\1/g,regex:{pattern:/(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/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}|!|=?&lt;|=?&gt;|={1,2}|(&amp;){1,2}|\|?\||\?|\*|\//g,ignore:/&(lt|gt|amp);/gi,punctuation:/[{}[\];(),.:]/g};Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{script:{pattern:/(&lt;|<)script[\w\W]*?(>|&gt;)[\w\W]*?(&lt;|<)\/script(>|&gt;)/ig,inside:{tag:{pattern:/(&lt;|<)script[\w\W]*?(>|&gt;)|(&lt;|<)\/script(>|&gt;)/ig,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.javascript}}});

View File

@ -42,7 +42,7 @@
<dt>lookbehind</dt>
<dd>This option mitigates JavaScripts lack of lookbehind. When set to <code>true</code>,
the first capturing group in the regex <code>pattern</code> is discarded when matching this token, so it effectively behaves
as if it was lookbehind. For an example of this, check out the JavaScript language definition, in particular the regex and line-comment tokens:
as if it was lookbehind. For an example of this, check out the JavaScript language definition, in particular the regex and comment tokens:
<pre data-src="components/prism-javascript.js"></pre></dd>
<dt>rest</dt>

38
plugins/index.html Normal file
View File

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Plugins ▲ Prism</title>
<base href=".." />
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="prism.css" data-noprefix />
<link rel="stylesheet" href="plugins/line-highlight/prism-line-highlight.css" data-noprefix />
<script src="../prefixfree/prefixfree.min.js"></script>
</head>
<body>
<header>
<div class="intro" data-src="templates/header-plugins.html" data-type="text/html"></div>
</header>
<section>
<h1>Available plugins</h1>
<ul class="plugin-list"></ul>
</section>
<section>
<h1>Contribute</h1>
<p>Writing Prism plugins is easy! Read how at the “<a href="extending.html#writing-plugins">Extending Prism</a>” section.
</section>
<footer data-src="templates/footer.html" data-type="text/html"></footer>
<script src="prism.js"></script>
<script src="plugins/line-highlight/prism-line-highlight.js"></script>
<script src="utopia.js"></script>
<script src="code.js"></script>
</body>
</html>

View File

@ -49,7 +49,6 @@ pre[class*="language-"] {
}
.token.comment,
.token.line-comment,
.token.prolog,
.token.doctype,
.token.cdata {

View File

@ -46,7 +46,6 @@ code[class*="language-"] {
}
.token.comment,
.token.line-comment,
.token.prolog,
.token.doctype,
.token.cdata {

View File

@ -44,7 +44,6 @@ pre[class*="language-"] {
}
.token.comment,
.token.line-comment,
.token.prolog,
.token.doctype,
.token.cdata {

View File

@ -386,9 +386,8 @@ if (Prism.languages.markup) {
***********************************************/
Prism.languages.javascript = {
'comment': /\/\*[\w\W]*?\*\//g,
'line-comment': {
pattern: /(^|[^\\])\/\/.*?(\r?\n|$)/g,
'comment': {
pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|\/\/.*?(\r?\n|$))/g,
lookbehind: true
},
'string': /("|')(\\?.)*?\1/g,