Skip to content

Commit

Permalink
Merge branch 'gh-pages' into plugin/toolbar-and-copy-to-clipboard
Browse files Browse the repository at this point in the history
* gh-pages: (22 commits)
  Remove direction-property from themes
  Add tests for new greedy-pattern feature and fix bug in Kotlin
  Fix double HTML-encoding bug in Groovy language
  Add comments to better document the greedy-pattern feature
  Partial solution for the "Comment-like substrings"-problem
  Add property 'aliasTitles' to components.js
  [unescaped markup] Fix small issues @zeitgeist87 pointed out
  [unescaped markup] Fixed bug with escaped </script>
  Added unescaped markup plugin (hidden)
  Implemented @zeitgeist87’s suggestion in PrismJS#890 re: env.elements
  Changed weight in the header, as we’re now 2KB minified & gzipped. Also way overdue :)
  Changed the text in the header. Way overdue, as Prism’s popularity has way surpassed that of Dabblet
  Add before-highlightall hook
  Fix catastrophic backtracking regex issues
  Add missing prism.js to the documentation of normalize-whitespace
  Cleanup normalize-whitespace and improve keep-markup integration
  Preserve Markup in Normalize-Whitespace plugin
  Update CHANGELOG and run gulp
  Removed firstWhiteSpaces code
  Add support for automatic line breaks
  ...

# Conflicts:
#	components.js
  • Loading branch information
mAAdhaTTah committed Feb 25, 2016
2 parents 0bdbe06 + 954c90a commit 1d06b61
Show file tree
Hide file tree
Showing 44 changed files with 750 additions and 111 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Prism Changelog

## Unreleased

### Updated components

* __Keep Markup__:
* Fix Keep Markup plugin incorrect highlighting ([#880](https://github.com/PrismJS/prism/pull/880)) [[`24841ef`](https://github.com/PrismJS/prism/commit/24841ef)]

### New plugins

* __Normalize Whitespace__ ([#847](https://github.com/PrismJS/prism/pull/847)) [[`e86ec01`](https://github.com/PrismJS/prism/commit/e86ec01)]

## 1.4.1 (2016-02-03)

### Other changes
Expand Down
6 changes: 6 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var components = {
},
"markup": {
"title": "Markup",
"aliasTitles": { "html": "HTML", "xml": "XML", "svg": "SVG", "mathml": "MathML" },
"option": "default"
},
"css": {
Expand Down Expand Up @@ -611,6 +612,11 @@ var components = {
"title": "Command Line",
"owner": "chriswells0"
},
"normalize-whitespace": {
"title": "Normalize Whitespace",
"owner": "zeitgeist87",
"noCSS": true
},
"toolbar": {
"title": "Toolbar",
"owner": "mAAdhaTTah"
Expand Down
2 changes: 1 addition & 1 deletion components/prism-bash.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
inside: insideString
},
{
pattern: /("|')(?:\\?[\s\S])*?\1/g,
pattern: /(["'])(?:\\\\|\\?[^\\])*?\1/g,
inside: insideString
}
],
Expand Down
2 changes: 1 addition & 1 deletion components/prism-bash.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion components/prism-clike.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ Prism.languages.clike = {
lookbehind: true
}
],
'string': /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
'string': {
pattern: /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
greedy: true
},
'class-name': {
pattern: /((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
lookbehind: true,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-clike.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 75 additions & 28 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ var _ = _self.Prism = {
insertBefore: function (inside, before, insert, root) {
root = root || _.languages;
var grammar = root[inside];

if (arguments.length == 2) {
insert = arguments[1];

for (var newToken in insert) {
if (insert.hasOwnProperty(newToken)) {
grammar[newToken] = insert[newToken];
}
}

return grammar;
}

var ret = {};

for (var token in grammar) {
Expand All @@ -121,7 +121,7 @@ var _ = _self.Prism = {
ret[token] = grammar[token];
}
}

// Update references in other language definitions
_.languages.DFS(_.languages, function(key, value) {
if (value === root[inside] && key != inside) {
Expand Down Expand Up @@ -152,12 +152,19 @@ var _ = _self.Prism = {
}
},
plugins: {},

highlightAll: function(async, callback) {
var elements = document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code');
var env = {
callback: callback,
selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
};

_.hooks.run("before-highlightall", env);

var elements = env.elements || document.querySelectorAll(env.selector);

for (var i=0, element; element = elements[i++];) {
_.highlightElement(element, async === true, callback);
_.highlightElement(element, async === true, env.callback);
}
},

Expand Down Expand Up @@ -267,6 +274,7 @@ var _ = _self.Prism = {
var pattern = patterns[j],
inside = pattern.inside,
lookbehind = !!pattern.lookbehind,
greedy = !!pattern.greedy,
lookbehindLength = 0,
alias = pattern.alias;

Expand All @@ -287,36 +295,73 @@ var _ = _self.Prism = {

pattern.lastIndex = 0;

var match = pattern.exec(str);
var match = pattern.exec(str),
delNum = 1;

if (match) {
if(lookbehind) {
lookbehindLength = match[1].length;
// Greedy patterns can override/remove up to two previously matched tokens
if (!match && greedy && i != strarr.length - 1) {
// Reconstruct the original text using the next two tokens
var nextToken = strarr[i + 1].matchedStr || strarr[i + 1],
combStr = str + nextToken;

if (i < strarr.length - 2) {
combStr += strarr[i + 2].matchedStr || strarr[i + 2];
}

var from = match.index - 1 + lookbehindLength,
match = match[0].slice(lookbehindLength),
len = match.length,
to = from + len,
before = str.slice(0, from + 1),
after = str.slice(to + 1);
// Try the pattern again on the reconstructed text
pattern.lastIndex = 0;
match = pattern.exec(combStr);
if (!match) {
continue;
}

var args = [i, 1];
var from = match.index + (lookbehind ? match[1].length : 0);
// To be a valid candidate, the new match has to start inside of str
if (from >= str.length) {
continue;
}
var to = match.index + match[0].length,
len = str.length + nextToken.length;

if (before) {
args.push(before);
// Number of tokens to delete and replace with the new match
delNum = 3;

if (to <= len) {
delNum = 2;
combStr = combStr.slice(0, len);
}
str = combStr;
}

var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias);
if (!match) {
continue;
}

args.push(wrapped);
if(lookbehind) {
lookbehindLength = match[1].length;
}

if (after) {
args.push(after);
}
var from = match.index + lookbehindLength,
match = match[0].slice(lookbehindLength),
to = from + match.length,
before = str.slice(0, from),
after = str.slice(to);

Array.prototype.splice.apply(strarr, args);
var args = [i, delNum];

if (before) {
args.push(before);
}

var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias, match);

args.push(wrapped);

if (after) {
args.push(after);
}

Array.prototype.splice.apply(strarr, args);
}
}
}
Expand Down Expand Up @@ -349,10 +394,12 @@ var _ = _self.Prism = {
}
};

var Token = _.Token = function(type, content, alias) {
var Token = _.Token = function(type, content, alias, matchedStr) {
this.type = type;
this.content = content;
this.alias = alias;
// Copy of the full string this token was created from
this.matchedStr = matchedStr || null;
};

Token.stringify = function(o, language, parent) {
Expand Down
Loading

0 comments on commit 1d06b61

Please sign in to comment.