Skip to content

Commit

Permalink
Made prism-core a little more editor friendly (#1776)
Browse files Browse the repository at this point in the history
This makes the structure of prism-core easier to understand for editors.
  • Loading branch information
RunDevelopment committed Mar 2, 2019
1 parent 3b396ef commit bac09f0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
24 changes: 13 additions & 11 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ var _self = (typeof window !== 'undefined')
* @author Lea Verou http://lea.verou.me
*/

var Prism = (function(){
var Prism = (function (_self){

// Private helper vars
var lang = /\blang(?:uage)?-([\w-]+)\b/i;
var uniqueId = 0;

var _ = _self.Prism = {
var _ = {
manual: _self.Prism && _self.Prism.manual,
disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
util: {
Expand Down Expand Up @@ -278,8 +278,6 @@ var _ = _self.Prism = {
},

matchGrammar: function (text, strarr, grammar, index, startPos, oneshot, target) {
var Token = _.Token;

for (var token in grammar) {
if(!grammar.hasOwnProperty(token) || !grammar[token]) {
continue;
Expand Down Expand Up @@ -445,17 +443,21 @@ var _ = _self.Prism = {
callback(env);
}
}
}
},

Token: Token
};

var Token = _.Token = function(type, content, alias, matchedStr, greedy) {
_self.Prism = _;

function Token(type, content, alias, matchedStr, greedy) {
this.type = type;
this.content = content;
this.alias = alias;
// Copy of the full string this token was created from
this.length = (matchedStr || "").length|0;
this.greedy = !!greedy;
};
}

Token.stringify = function(o, language, parent) {
if (typeof o == 'string') {
Expand Down Expand Up @@ -496,7 +498,7 @@ Token.stringify = function(o, language, parent) {
if (!_self.document) {
if (!_self.addEventListener) {
// in Node.js
return _self.Prism;
return _;
}

if (!_.disableWorkerMessageHandler) {
Expand All @@ -514,7 +516,7 @@ if (!_self.document) {
}, false);
}

return _self.Prism;
return _;
}

//Get current script and highlight
Expand All @@ -537,9 +539,9 @@ if (script) {
}
}

return _self.Prism;
return _;

})();
})(_self);

if (typeof module !== 'undefined' && module.exports) {
module.exports = Prism;
Expand Down
2 changes: 1 addition & 1 deletion components/prism-core.min.js

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

2 changes: 1 addition & 1 deletion components/prism-sas.min.js

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

24 changes: 13 additions & 11 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ var _self = (typeof window !== 'undefined')
* @author Lea Verou http://lea.verou.me
*/

var Prism = (function(){
var Prism = (function (_self){

// Private helper vars
var lang = /\blang(?:uage)?-([\w-]+)\b/i;
var uniqueId = 0;

var _ = _self.Prism = {
var _ = {
manual: _self.Prism && _self.Prism.manual,
disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
util: {
Expand Down Expand Up @@ -283,8 +283,6 @@ var _ = _self.Prism = {
},

matchGrammar: function (text, strarr, grammar, index, startPos, oneshot, target) {
var Token = _.Token;

for (var token in grammar) {
if(!grammar.hasOwnProperty(token) || !grammar[token]) {
continue;
Expand Down Expand Up @@ -450,17 +448,21 @@ var _ = _self.Prism = {
callback(env);
}
}
}
},

Token: Token
};

var Token = _.Token = function(type, content, alias, matchedStr, greedy) {
_self.Prism = _;

function Token(type, content, alias, matchedStr, greedy) {
this.type = type;
this.content = content;
this.alias = alias;
// Copy of the full string this token was created from
this.length = (matchedStr || "").length|0;
this.greedy = !!greedy;
};
}

Token.stringify = function(o, language, parent) {
if (typeof o == 'string') {
Expand Down Expand Up @@ -501,7 +503,7 @@ Token.stringify = function(o, language, parent) {
if (!_self.document) {
if (!_self.addEventListener) {
// in Node.js
return _self.Prism;
return _;
}

if (!_.disableWorkerMessageHandler) {
Expand All @@ -519,7 +521,7 @@ if (!_self.document) {
}, false);
}

return _self.Prism;
return _;
}

//Get current script and highlight
Expand All @@ -542,9 +544,9 @@ if (script) {
}
}

return _self.Prism;
return _;

})();
})(_self);

if (typeof module !== 'undefined' && module.exports) {
module.exports = Prism;
Expand Down

0 comments on commit bac09f0

Please sign in to comment.