@convertkit/editor-html
Advanced tools
Comparing version 0.1.6 to 0.1.7
1512
es/index.js
@@ -50,255 +50,293 @@ import React, { Component } from 'react'; | ||
function _extends$1() { | ||
_extends$1 = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends$1.apply(this, arguments); | ||
} | ||
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
return module = { | ||
exports: {} | ||
}, fn(module, module.exports), module.exports; | ||
} | ||
var prism = createCommonjsModule(function (module) { | ||
/* ********************************************** | ||
Begin prism-core.js | ||
********************************************** */ | ||
var _self = typeof window !== 'undefined' ? window // if in browser | ||
: typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope ? self // if in worker | ||
: {} // if in node js | ||
; | ||
/** | ||
* Prism: Lightweight, robust, elegant syntax highlighting | ||
* MIT license http://www.opensource.org/licenses/mit-license.php/ | ||
* @author Lea Verou http://lea.verou.me | ||
*/ | ||
/* ********************************************** | ||
Begin prism-core.js | ||
********************************************** */ | ||
var _self = typeof window !== 'undefined' ? window // if in browser | ||
: typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope ? self // if in worker | ||
: {} // if in node js | ||
; | ||
/** | ||
* Prism: Lightweight, robust, elegant syntax highlighting | ||
* MIT license http://www.opensource.org/licenses/mit-license.php/ | ||
* @author Lea Verou http://lea.verou.me | ||
*/ | ||
var Prism = function () { | ||
// Private helper vars | ||
var lang = /\blang(?:uage)?-([\w-]+)\b/i; | ||
var uniqueId = 0; | ||
var Prism = function () { | ||
// Private helper vars | ||
var lang = /\blang(?:uage)?-([\w-]+)\b/i; | ||
var uniqueId = 0; | ||
var _ = _self.Prism = { | ||
manual: _self.Prism && _self.Prism.manual, | ||
disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler, | ||
util: { | ||
encode: function encode(tokens) { | ||
if (tokens instanceof Token) { | ||
return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias); | ||
} else if (_.util.type(tokens) === 'Array') { | ||
return tokens.map(_.util.encode); | ||
} else { | ||
return tokens.replace(/&/g, '&').replace(/</g, '<').replace(/\u00a0/g, ' '); | ||
} | ||
}, | ||
type: function type(o) { | ||
return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1]; | ||
}, | ||
objId: function objId(obj) { | ||
if (!obj['__id']) { | ||
Object.defineProperty(obj, '__id', { | ||
value: ++uniqueId | ||
}); | ||
} | ||
var _ = _self.Prism = { | ||
manual: _self.Prism && _self.Prism.manual, | ||
disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler, | ||
util: { | ||
encode: function encode(tokens) { | ||
if (tokens instanceof Token) { | ||
return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias); | ||
} else if (_.util.type(tokens) === 'Array') { | ||
return tokens.map(_.util.encode); | ||
} else { | ||
return tokens.replace(/&/g, '&').replace(/</g, '<').replace(/\u00a0/g, ' '); | ||
} | ||
}, | ||
type: function type(o) { | ||
return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1]; | ||
}, | ||
objId: function objId(obj) { | ||
if (!obj['__id']) { | ||
Object.defineProperty(obj, '__id', { | ||
value: ++uniqueId | ||
}); | ||
} | ||
return obj['__id']; | ||
}, | ||
// Deep clone a language definition (e.g. to extend it) | ||
clone: function clone(o, visited) { | ||
var type = _.util.type(o); | ||
return obj['__id']; | ||
}, | ||
// Deep clone a language definition (e.g. to extend it) | ||
clone: function clone(o, visited) { | ||
var type = _.util.type(o); | ||
visited = visited || {}; | ||
visited = visited || {}; | ||
switch (type) { | ||
case 'Object': | ||
if (visited[_.util.objId(o)]) { | ||
return visited[_.util.objId(o)]; | ||
} | ||
switch (type) { | ||
case 'Object': | ||
if (visited[_.util.objId(o)]) { | ||
return visited[_.util.objId(o)]; | ||
} | ||
var clone = {}; | ||
visited[_.util.objId(o)] = clone; | ||
var clone = {}; | ||
visited[_.util.objId(o)] = clone; | ||
for (var key in o) { | ||
if (o.hasOwnProperty(key)) { | ||
clone[key] = _.util.clone(o[key], visited); | ||
for (var key in o) { | ||
if (o.hasOwnProperty(key)) { | ||
clone[key] = _.util.clone(o[key], visited); | ||
} | ||
} | ||
} | ||
return clone; | ||
return clone; | ||
case 'Array': | ||
if (visited[_.util.objId(o)]) { | ||
return visited[_.util.objId(o)]; | ||
} | ||
case 'Array': | ||
if (visited[_.util.objId(o)]) { | ||
return visited[_.util.objId(o)]; | ||
} | ||
var clone = []; | ||
visited[_.util.objId(o)] = clone; | ||
o.forEach(function (v, i) { | ||
clone[i] = _.util.clone(v, visited); | ||
}); | ||
return clone; | ||
var clone = []; | ||
visited[_.util.objId(o)] = clone; | ||
o.forEach(function (v, i) { | ||
clone[i] = _.util.clone(v, visited); | ||
}); | ||
return clone; | ||
} | ||
return o; | ||
} | ||
}, | ||
languages: { | ||
extend: function extend(id, redef) { | ||
var lang = _.util.clone(_.languages[id]); | ||
return o; | ||
} | ||
}, | ||
languages: { | ||
extend: function extend(id, redef) { | ||
var lang = _.util.clone(_.languages[id]); | ||
for (var key in redef) { | ||
lang[key] = redef[key]; | ||
} | ||
for (var key in redef) { | ||
lang[key] = redef[key]; | ||
} | ||
return lang; | ||
}, | ||
return lang; | ||
}, | ||
/** | ||
* Insert a token before another token in a language literal | ||
* As this needs to recreate the object (we cannot actually insert before keys in object literals), | ||
* we cannot just provide an object, we need anobject and a key. | ||
* @param inside The key (or language id) of the parent | ||
* @param before The key to insert before. If not provided, the function appends instead. | ||
* @param insert Object with the key/value pairs to insert | ||
* @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted. | ||
*/ | ||
insertBefore: function insertBefore(inside, before, insert, root) { | ||
root = root || _.languages; | ||
var grammar = root[inside]; | ||
/** | ||
* Insert a token before another token in a language literal | ||
* As this needs to recreate the object (we cannot actually insert before keys in object literals), | ||
* we cannot just provide an object, we need anobject and a key. | ||
* @param inside The key (or language id) of the parent | ||
* @param before The key to insert before. If not provided, the function appends instead. | ||
* @param insert Object with the key/value pairs to insert | ||
* @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted. | ||
*/ | ||
insertBefore: function insertBefore(inside, before, insert, root) { | ||
root = root || _.languages; | ||
var grammar = root[inside]; | ||
if (arguments.length == 2) { | ||
insert = arguments[1]; | ||
if (arguments.length == 2) { | ||
insert = arguments[1]; | ||
for (var newToken in insert) { | ||
if (insert.hasOwnProperty(newToken)) { | ||
grammar[newToken] = insert[newToken]; | ||
} | ||
} | ||
for (var newToken in insert) { | ||
if (insert.hasOwnProperty(newToken)) { | ||
grammar[newToken] = insert[newToken]; | ||
} | ||
return grammar; | ||
} | ||
return grammar; | ||
} | ||
var ret = {}; | ||
var ret = {}; | ||
for (var token in grammar) { | ||
if (grammar.hasOwnProperty(token)) { | ||
if (token == before) { | ||
for (var newToken in insert) { | ||
if (insert.hasOwnProperty(newToken)) { | ||
ret[newToken] = insert[newToken]; | ||
for (var token in grammar) { | ||
if (grammar.hasOwnProperty(token)) { | ||
if (token == before) { | ||
for (var newToken in insert) { | ||
if (insert.hasOwnProperty(newToken)) { | ||
ret[newToken] = insert[newToken]; | ||
} | ||
} | ||
} | ||
ret[token] = grammar[token]; | ||
} | ||
} // Update references in other language definitions | ||
ret[token] = grammar[token]; | ||
} | ||
} // Update references in other language definitions | ||
_.languages.DFS(_.languages, function (key, value) { | ||
if (value === root[inside] && key != inside) { | ||
this[key] = ret; | ||
} | ||
}); | ||
_.languages.DFS(_.languages, function (key, value) { | ||
if (value === root[inside] && key != inside) { | ||
this[key] = ret; | ||
} | ||
}); | ||
return root[inside] = ret; | ||
}, | ||
// Traverse a language definition with Depth First Search | ||
DFS: function DFS(o, callback, type, visited) { | ||
visited = visited || {}; | ||
return root[inside] = ret; | ||
}, | ||
// Traverse a language definition with Depth First Search | ||
DFS: function DFS(o, callback, type, visited) { | ||
visited = visited || {}; | ||
for (var i in o) { | ||
if (o.hasOwnProperty(i)) { | ||
callback.call(o, i, o[i], type || i); | ||
for (var i in o) { | ||
if (o.hasOwnProperty(i)) { | ||
callback.call(o, i, o[i], type || i); | ||
if (_.util.type(o[i]) === 'Object' && !visited[_.util.objId(o[i])]) { | ||
visited[_.util.objId(o[i])] = true; | ||
if (_.util.type(o[i]) === 'Object' && !visited[_.util.objId(o[i])]) { | ||
visited[_.util.objId(o[i])] = true; | ||
_.languages.DFS(o[i], callback, null, visited); | ||
} else if (_.util.type(o[i]) === 'Array' && !visited[_.util.objId(o[i])]) { | ||
visited[_.util.objId(o[i])] = true; | ||
_.languages.DFS(o[i], callback, null, visited); | ||
} else if (_.util.type(o[i]) === 'Array' && !visited[_.util.objId(o[i])]) { | ||
visited[_.util.objId(o[i])] = true; | ||
_.languages.DFS(o[i], callback, i, visited); | ||
_.languages.DFS(o[i], callback, i, visited); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
plugins: {}, | ||
highlightAll: function highlightAll(async, callback) { | ||
_.highlightAllUnder(document, async, callback); | ||
}, | ||
highlightAllUnder: function highlightAllUnder(container, async, callback) { | ||
var env = { | ||
callback: callback, | ||
selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code' | ||
}; | ||
}, | ||
plugins: {}, | ||
highlightAll: function highlightAll(async, callback) { | ||
_.highlightAllUnder(document, async, callback); | ||
}, | ||
highlightAllUnder: function highlightAllUnder(container, async, callback) { | ||
var env = { | ||
callback: callback, | ||
selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code' | ||
}; | ||
_.hooks.run("before-highlightall", env); | ||
_.hooks.run("before-highlightall", env); | ||
var elements = env.elements || container.querySelectorAll(env.selector); | ||
var elements = env.elements || container.querySelectorAll(env.selector); | ||
for (var i = 0, element; element = elements[i++];) { | ||
_.highlightElement(element, async === true, env.callback); | ||
} | ||
}, | ||
highlightElement: function highlightElement(element, async, callback) { | ||
// Find language | ||
var language, | ||
grammar, | ||
parent = element; | ||
for (var i = 0, element; element = elements[i++];) { | ||
_.highlightElement(element, async === true, env.callback); | ||
} | ||
}, | ||
highlightElement: function highlightElement(element, async, callback) { | ||
// Find language | ||
var language, | ||
grammar, | ||
parent = element; | ||
while (parent && !lang.test(parent.className)) { | ||
parent = parent.parentNode; | ||
} | ||
while (parent && !lang.test(parent.className)) { | ||
parent = parent.parentNode; | ||
} | ||
if (parent) { | ||
language = (parent.className.match(lang) || [, ''])[1].toLowerCase(); | ||
grammar = _.languages[language]; | ||
} // Set language on the element, if not present | ||
if (parent) { | ||
language = (parent.className.match(lang) || [, ''])[1].toLowerCase(); | ||
grammar = _.languages[language]; | ||
} // Set language on the element, if not present | ||
element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language; | ||
element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language; | ||
if (element.parentNode) { | ||
// Set language on the parent, for styling | ||
parent = element.parentNode; | ||
if (element.parentNode) { | ||
// Set language on the parent, for styling | ||
parent = element.parentNode; | ||
if (/pre/i.test(parent.nodeName)) { | ||
parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language; | ||
if (/pre/i.test(parent.nodeName)) { | ||
parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language; | ||
} | ||
} | ||
} | ||
var code = element.textContent; | ||
var env = { | ||
element: element, | ||
language: language, | ||
grammar: grammar, | ||
code: code | ||
}; | ||
var code = element.textContent; | ||
var env = { | ||
element: element, | ||
language: language, | ||
grammar: grammar, | ||
code: code | ||
}; | ||
_.hooks.run('before-sanity-check', env); | ||
_.hooks.run('before-sanity-check', env); | ||
if (!env.code || !env.grammar) { | ||
if (env.code) { | ||
_.hooks.run('before-highlight', env); | ||
if (!env.code || !env.grammar) { | ||
if (env.code) { | ||
_.hooks.run('before-highlight', env); | ||
env.element.textContent = env.code; | ||
env.element.textContent = env.code; | ||
_.hooks.run('after-highlight', env); | ||
_.hooks.run('after-highlight', env); | ||
} | ||
_.hooks.run('complete', env); | ||
return; | ||
} | ||
_.hooks.run('complete', env); | ||
_.hooks.run('before-highlight', env); | ||
return; | ||
} | ||
if (async && _self.Worker) { | ||
var worker = new Worker(_.filename); | ||
_.hooks.run('before-highlight', env); | ||
worker.onmessage = function (evt) { | ||
env.highlightedCode = evt.data; | ||
if (async && _self.Worker) { | ||
var worker = new Worker(_.filename); | ||
_.hooks.run('before-insert', env); | ||
worker.onmessage = function (evt) { | ||
env.highlightedCode = evt.data; | ||
env.element.innerHTML = env.highlightedCode; | ||
callback && callback.call(env.element); | ||
_.hooks.run('after-highlight', env); | ||
_.hooks.run('complete', env); | ||
}; | ||
worker.postMessage(JSON.stringify({ | ||
language: env.language, | ||
code: env.code, | ||
immediateClose: true | ||
})); | ||
} else { | ||
env.highlightedCode = _.highlight(env.code, env.grammar, env.language); | ||
_.hooks.run('before-insert', env); | ||
env.element.innerHTML = env.highlightedCode; | ||
callback && callback.call(env.element); | ||
callback && callback.call(element); | ||
@@ -308,572 +346,554 @@ _.hooks.run('after-highlight', env); | ||
_.hooks.run('complete', env); | ||
} | ||
}, | ||
highlight: function highlight(text, grammar, language) { | ||
var env = { | ||
code: text, | ||
grammar: grammar, | ||
language: language | ||
}; | ||
worker.postMessage(JSON.stringify({ | ||
language: env.language, | ||
code: env.code, | ||
immediateClose: true | ||
})); | ||
} else { | ||
env.highlightedCode = _.highlight(env.code, env.grammar, env.language); | ||
_.hooks.run('before-tokenize', env); | ||
_.hooks.run('before-insert', env); | ||
env.tokens = _.tokenize(env.code, env.grammar); | ||
env.element.innerHTML = env.highlightedCode; | ||
callback && callback.call(element); | ||
_.hooks.run('after-tokenize', env); | ||
_.hooks.run('after-highlight', env); | ||
return Token.stringify(_.util.encode(env.tokens), env.language); | ||
}, | ||
matchGrammar: function matchGrammar(text, strarr, grammar, index, startPos, oneshot, target) { | ||
var Token = _.Token; | ||
_.hooks.run('complete', env); | ||
} | ||
}, | ||
highlight: function highlight(text, grammar, language) { | ||
var env = { | ||
code: text, | ||
grammar: grammar, | ||
language: language | ||
}; | ||
for (var token in grammar) { | ||
if (!grammar.hasOwnProperty(token) || !grammar[token]) { | ||
continue; | ||
} | ||
_.hooks.run('before-tokenize', env); | ||
if (token == target) { | ||
return; | ||
} | ||
env.tokens = _.tokenize(env.code, env.grammar); | ||
var patterns = grammar[token]; | ||
patterns = _.util.type(patterns) === "Array" ? patterns : [patterns]; | ||
_.hooks.run('after-tokenize', env); | ||
for (var j = 0; j < patterns.length; ++j) { | ||
var pattern = patterns[j], | ||
inside = pattern.inside, | ||
lookbehind = !!pattern.lookbehind, | ||
greedy = !!pattern.greedy, | ||
lookbehindLength = 0, | ||
alias = pattern.alias; | ||
return Token.stringify(_.util.encode(env.tokens), env.language); | ||
}, | ||
matchGrammar: function matchGrammar(text, strarr, grammar, index, startPos, oneshot, target) { | ||
var Token = _.Token; | ||
if (greedy && !pattern.pattern.global) { | ||
// Without the global flag, lastIndex won't work | ||
var flags = pattern.pattern.toString().match(/[imuy]*$/)[0]; | ||
pattern.pattern = RegExp(pattern.pattern.source, flags + "g"); | ||
} | ||
for (var token in grammar) { | ||
if (!grammar.hasOwnProperty(token) || !grammar[token]) { | ||
continue; | ||
} | ||
pattern = pattern.pattern || pattern; // Don’t cache length as it changes during the loop | ||
if (token == target) { | ||
return; | ||
} | ||
for (var i = index, pos = startPos; i < strarr.length; pos += strarr[i].length, ++i) { | ||
var str = strarr[i]; | ||
var patterns = grammar[token]; | ||
patterns = _.util.type(patterns) === "Array" ? patterns : [patterns]; | ||
if (strarr.length > text.length) { | ||
// Something went terribly wrong, ABORT, ABORT! | ||
return; | ||
} | ||
for (var j = 0; j < patterns.length; ++j) { | ||
var pattern = patterns[j], | ||
inside = pattern.inside, | ||
lookbehind = !!pattern.lookbehind, | ||
greedy = !!pattern.greedy, | ||
lookbehindLength = 0, | ||
alias = pattern.alias; | ||
if (str instanceof Token) { | ||
continue; | ||
} | ||
if (greedy && !pattern.pattern.global) { | ||
// Without the global flag, lastIndex won't work | ||
var flags = pattern.pattern.toString().match(/[imuy]*$/)[0]; | ||
pattern.pattern = RegExp(pattern.pattern.source, flags + "g"); | ||
} | ||
if (greedy && i != strarr.length - 1) { | ||
pattern.lastIndex = pos; | ||
var match = pattern.exec(text); | ||
pattern = pattern.pattern || pattern; // Don’t cache length as it changes during the loop | ||
if (!match) { | ||
break; | ||
} | ||
for (var i = index, pos = startPos; i < strarr.length; pos += strarr[i].length, ++i) { | ||
var str = strarr[i]; | ||
var from = match.index + (lookbehind ? match[1].length : 0), | ||
to = match.index + match[0].length, | ||
k = i, | ||
p = pos; | ||
if (strarr.length > text.length) { | ||
// Something went terribly wrong, ABORT, ABORT! | ||
return; | ||
} | ||
for (var len = strarr.length; k < len && (p < to || !strarr[k].type && !strarr[k - 1].greedy); ++k) { | ||
p += strarr[k].length; // Move the index i to the element in strarr that is closest to from | ||
if (str instanceof Token) { | ||
continue; | ||
} | ||
if (from >= p) { | ||
++i; | ||
pos = p; | ||
} | ||
} // If strarr[i] is a Token, then the match starts inside another Token, which is invalid | ||
if (greedy && i != strarr.length - 1) { | ||
pattern.lastIndex = pos; | ||
var match = pattern.exec(text); | ||
if (!match) { | ||
break; | ||
} | ||
if (strarr[i] instanceof Token) { | ||
continue; | ||
} // Number of tokens to delete and replace with the new match | ||
var from = match.index + (lookbehind ? match[1].length : 0), | ||
to = match.index + match[0].length, | ||
k = i, | ||
p = pos; | ||
for (var len = strarr.length; k < len && (p < to || !strarr[k].type && !strarr[k - 1].greedy); ++k) { | ||
p += strarr[k].length; // Move the index i to the element in strarr that is closest to from | ||
delNum = k - i; | ||
str = text.slice(pos, p); | ||
match.index -= pos; | ||
} else { | ||
pattern.lastIndex = 0; | ||
var match = pattern.exec(str), | ||
delNum = 1; | ||
} | ||
if (from >= p) { | ||
++i; | ||
pos = p; | ||
if (!match) { | ||
if (oneshot) { | ||
break; | ||
} | ||
} // If strarr[i] is a Token, then the match starts inside another Token, which is invalid | ||
if (strarr[i] instanceof Token) { | ||
continue; | ||
} // Number of tokens to delete and replace with the new match | ||
} | ||
if (lookbehind) { | ||
lookbehindLength = match[1] ? match[1].length : 0; | ||
} | ||
delNum = k - i; | ||
str = text.slice(pos, p); | ||
match.index -= pos; | ||
} else { | ||
pattern.lastIndex = 0; | ||
var match = pattern.exec(str), | ||
delNum = 1; | ||
} | ||
var from = match.index + lookbehindLength, | ||
match = match[0].slice(lookbehindLength), | ||
to = from + match.length, | ||
before = str.slice(0, from), | ||
after = str.slice(to); | ||
var args = [i, delNum]; | ||
if (!match) { | ||
if (oneshot) { | ||
break; | ||
if (before) { | ||
++i; | ||
pos += before.length; | ||
args.push(before); | ||
} | ||
continue; | ||
} | ||
var wrapped = new Token(token, inside ? _.tokenize(match, inside) : match, alias, match, greedy); | ||
args.push(wrapped); | ||
if (lookbehind) { | ||
lookbehindLength = match[1] ? match[1].length : 0; | ||
} | ||
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); | ||
var args = [i, delNum]; | ||
if (before) { | ||
++i; | ||
pos += before.length; | ||
args.push(before); | ||
Array.prototype.splice.apply(strarr, args); | ||
if (delNum != 1) _.matchGrammar(text, strarr, grammar, i, pos, true, token); | ||
if (oneshot) break; | ||
} | ||
var wrapped = new Token(token, inside ? _.tokenize(match, inside) : match, alias, match, greedy); | ||
args.push(wrapped); | ||
if (after) { | ||
args.push(after); | ||
} | ||
Array.prototype.splice.apply(strarr, args); | ||
if (delNum != 1) _.matchGrammar(text, strarr, grammar, i, pos, true, token); | ||
if (oneshot) break; | ||
} | ||
} | ||
} | ||
}, | ||
tokenize: function tokenize(text, grammar, language) { | ||
var strarr = [text]; | ||
var rest = grammar.rest; | ||
}, | ||
tokenize: function tokenize(text, grammar, language) { | ||
var strarr = [text]; | ||
var rest = grammar.rest; | ||
if (rest) { | ||
for (var token in rest) { | ||
grammar[token] = rest[token]; | ||
if (rest) { | ||
for (var token in rest) { | ||
grammar[token] = rest[token]; | ||
} | ||
delete grammar.rest; | ||
} | ||
delete grammar.rest; | ||
} | ||
_.matchGrammar(text, strarr, grammar, 0, 0, false); | ||
_.matchGrammar(text, strarr, grammar, 0, 0, false); | ||
return strarr; | ||
}, | ||
hooks: { | ||
all: {}, | ||
add: function add(name, callback) { | ||
var hooks = _.hooks.all; | ||
hooks[name] = hooks[name] || []; | ||
hooks[name].push(callback); | ||
return strarr; | ||
}, | ||
run: function run(name, env) { | ||
var callbacks = _.hooks.all[name]; | ||
hooks: { | ||
all: {}, | ||
add: function add(name, callback) { | ||
var hooks = _.hooks.all; | ||
hooks[name] = hooks[name] || []; | ||
hooks[name].push(callback); | ||
}, | ||
run: function run(name, env) { | ||
var callbacks = _.hooks.all[name]; | ||
if (!callbacks || !callbacks.length) { | ||
return; | ||
} | ||
if (!callbacks || !callbacks.length) { | ||
return; | ||
} | ||
for (var i = 0, callback; callback = callbacks[i++];) { | ||
callback(env); | ||
for (var i = 0, callback; callback = callbacks[i++];) { | ||
callback(env); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
var Token = _.Token = function (type, content, alias, matchedStr, greedy) { | ||
this.type = type; | ||
this.content = content; | ||
this.alias = alias; // Copy of the full string this token was created from | ||
var Token = _.Token = function (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; | ||
}; | ||
this.length = (matchedStr || "").length | 0; | ||
this.greedy = !!greedy; | ||
}; | ||
Token.stringify = function (o, language, parent) { | ||
if (typeof o == 'string') { | ||
return o; | ||
} | ||
Token.stringify = function (o, language, parent) { | ||
if (typeof o == 'string') { | ||
return o; | ||
} | ||
if (_.util.type(o) === 'Array') { | ||
return o.map(function (element) { | ||
return Token.stringify(element, language, o); | ||
}).join(''); | ||
} | ||
if (_.util.type(o) === 'Array') { | ||
return o.map(function (element) { | ||
return Token.stringify(element, language, o); | ||
}).join(''); | ||
} | ||
var env = { | ||
type: o.type, | ||
content: Token.stringify(o.content, language, parent), | ||
tag: 'span', | ||
classes: ['token', o.type], | ||
attributes: {}, | ||
language: language, | ||
parent: parent | ||
}; | ||
var env = { | ||
type: o.type, | ||
content: Token.stringify(o.content, language, parent), | ||
tag: 'span', | ||
classes: ['token', o.type], | ||
attributes: {}, | ||
language: language, | ||
parent: parent | ||
}; | ||
if (o.alias) { | ||
var aliases = _.util.type(o.alias) === 'Array' ? o.alias : [o.alias]; | ||
Array.prototype.push.apply(env.classes, aliases); | ||
} | ||
if (o.alias) { | ||
var aliases = _.util.type(o.alias) === 'Array' ? o.alias : [o.alias]; | ||
Array.prototype.push.apply(env.classes, aliases); | ||
} | ||
_.hooks.run('wrap', env); | ||
_.hooks.run('wrap', env); | ||
var attributes = Object.keys(env.attributes).map(function (name) { | ||
return name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"'; | ||
}).join(' '); | ||
return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + '</' + env.tag + '>'; | ||
}; | ||
var attributes = Object.keys(env.attributes).map(function (name) { | ||
return name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"'; | ||
}).join(' '); | ||
return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + '</' + env.tag + '>'; | ||
}; | ||
if (!_self.document) { | ||
if (!_self.addEventListener) { | ||
// in Node.js | ||
return _self.Prism; | ||
} | ||
if (!_self.document) { | ||
if (!_self.addEventListener) { | ||
// in Node.js | ||
return _self.Prism; | ||
} | ||
if (!_.disableWorkerMessageHandler) { | ||
// In worker | ||
_self.addEventListener('message', function (evt) { | ||
var message = JSON.parse(evt.data), | ||
lang = message.language, | ||
code = message.code, | ||
immediateClose = message.immediateClose; | ||
if (!_.disableWorkerMessageHandler) { | ||
// In worker | ||
_self.addEventListener('message', function (evt) { | ||
var message = JSON.parse(evt.data), | ||
lang = message.language, | ||
code = message.code, | ||
immediateClose = message.immediateClose; | ||
_self.postMessage(_.highlight(code, _.languages[lang], lang)); | ||
_self.postMessage(_.highlight(code, _.languages[lang], lang)); | ||
if (immediateClose) { | ||
_self.close(); | ||
} | ||
}, false); | ||
} | ||
if (immediateClose) { | ||
_self.close(); | ||
} | ||
}, false); | ||
} | ||
return _self.Prism; | ||
} //Get current script and highlight | ||
return _self.Prism; | ||
} //Get current script and highlight | ||
var script = document.currentScript || [].slice.call(document.getElementsByTagName("script")).pop(); | ||
var script = document.currentScript || [].slice.call(document.getElementsByTagName("script")).pop(); | ||
if (script) { | ||
_.filename = script.src; | ||
if (script) { | ||
_.filename = script.src; | ||
if (!_.manual && !script.hasAttribute('data-manual')) { | ||
if (document.readyState !== "loading") { | ||
if (window.requestAnimationFrame) { | ||
window.requestAnimationFrame(_.highlightAll); | ||
if (!_.manual && !script.hasAttribute('data-manual')) { | ||
if (document.readyState !== "loading") { | ||
if (window.requestAnimationFrame) { | ||
window.requestAnimationFrame(_.highlightAll); | ||
} else { | ||
window.setTimeout(_.highlightAll, 16); | ||
} | ||
} else { | ||
window.setTimeout(_.highlightAll, 16); | ||
document.addEventListener('DOMContentLoaded', _.highlightAll); | ||
} | ||
} else { | ||
document.addEventListener('DOMContentLoaded', _.highlightAll); | ||
} | ||
} | ||
} | ||
return _self.Prism; | ||
}(); | ||
return _self.Prism; | ||
}(); | ||
if (module.exports) { | ||
module.exports = Prism; | ||
} // hack for components to work correctly in node.js | ||
if (module.exports) { | ||
module.exports = Prism; | ||
} // hack for components to work correctly in node.js | ||
if (typeof commonjsGlobal !== 'undefined') { | ||
commonjsGlobal.Prism = Prism; | ||
} | ||
/* ********************************************** | ||
Begin prism-markup.js | ||
********************************************** */ | ||
Prism.languages.markup = { | ||
'comment': /<!--[\s\S]*?-->/, | ||
'prolog': /<\?[\s\S]+?\?>/, | ||
'doctype': /<!DOCTYPE[\s\S]+?>/i, | ||
'cdata': /<!\[CDATA\[[\s\S]*?]]>/i, | ||
'tag': { | ||
pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+))?)*\s*\/?>/i, | ||
greedy: true, | ||
inside: { | ||
'tag': { | ||
pattern: /^<\/?[^\s>\/]+/i, | ||
inside: { | ||
'punctuation': /^<\/?/, | ||
'namespace': /^[^\s>\/:]+:/ | ||
} | ||
}, | ||
'attr-value': { | ||
pattern: /=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+)/i, | ||
inside: { | ||
'punctuation': [/^=/, { | ||
pattern: /(^|[^\\])["']/, | ||
lookbehind: true | ||
}] | ||
} | ||
}, | ||
'punctuation': /\/?>/, | ||
'attr-name': { | ||
pattern: /[^\s>\/]+/, | ||
inside: { | ||
'namespace': /^[^\s>\/:]+:/ | ||
} | ||
} | ||
} | ||
}, | ||
'entity': /&#?[\da-z]{1,8};/i | ||
}; | ||
Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] = Prism.languages.markup['entity']; // Plugin to make entity title show the real entity, idea by Roman Komarov | ||
Prism.hooks.add('wrap', function (env) { | ||
if (env.type === 'entity') { | ||
env.attributes['title'] = env.content.replace(/&/, '&'); | ||
if (typeof commonjsGlobal !== 'undefined') { | ||
commonjsGlobal.Prism = Prism; | ||
} | ||
}); | ||
Prism.languages.xml = Prism.languages.markup; | ||
Prism.languages.html = Prism.languages.markup; | ||
Prism.languages.mathml = Prism.languages.markup; | ||
Prism.languages.svg = Prism.languages.markup; | ||
/* ********************************************** | ||
Begin prism-css.js | ||
********************************************** */ | ||
/* ********************************************** | ||
Begin prism-markup.js | ||
********************************************** */ | ||
Prism.languages.css = { | ||
'comment': /\/\*[\s\S]*?\*\//, | ||
'atrule': { | ||
pattern: /@[\w-]+?.*?(?:;|(?=\s*\{))/i, | ||
inside: { | ||
'rule': /@[\w-]+/ // See rest below | ||
} | ||
}, | ||
'url': /url\((?:(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1|.*?)\)/i, | ||
'selector': /[^{}\s][^{};]*?(?=\s*\{)/, | ||
'string': { | ||
pattern: /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/, | ||
greedy: true | ||
}, | ||
'property': /[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i, | ||
'important': /\B!important\b/i, | ||
'function': /[-a-z0-9]+(?=\()/i, | ||
'punctuation': /[(){};:]/ | ||
}; | ||
Prism.languages.css['atrule'].inside.rest = Prism.languages.css; | ||
if (Prism.languages.markup) { | ||
Prism.languages.insertBefore('markup', 'tag', { | ||
'style': { | ||
pattern: /(<style[\s\S]*?>)[\s\S]*?(?=<\/style>)/i, | ||
lookbehind: true, | ||
inside: Prism.languages.css, | ||
alias: 'language-css', | ||
greedy: true | ||
} | ||
}); | ||
Prism.languages.insertBefore('inside', 'attr-value', { | ||
'style-attr': { | ||
pattern: /\s*style=("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/i, | ||
Prism.languages.markup = { | ||
'comment': /<!--[\s\S]*?-->/, | ||
'prolog': /<\?[\s\S]+?\?>/, | ||
'doctype': /<!DOCTYPE[\s\S]+?>/i, | ||
'cdata': /<!\[CDATA\[[\s\S]*?]]>/i, | ||
'tag': { | ||
pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+))?)*\s*\/?>/i, | ||
greedy: true, | ||
inside: { | ||
'attr-name': { | ||
pattern: /^\s*style/i, | ||
inside: Prism.languages.markup.tag.inside | ||
'tag': { | ||
pattern: /^<\/?[^\s>\/]+/i, | ||
inside: { | ||
'punctuation': /^<\/?/, | ||
'namespace': /^[^\s>\/:]+:/ | ||
} | ||
}, | ||
'punctuation': /^\s*=\s*['"]|['"]\s*$/, | ||
'attr-value': { | ||
pattern: /.+/i, | ||
inside: Prism.languages.css | ||
pattern: /=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+)/i, | ||
inside: { | ||
'punctuation': [/^=/, { | ||
pattern: /(^|[^\\])["']/, | ||
lookbehind: true | ||
}] | ||
} | ||
}, | ||
'punctuation': /\/?>/, | ||
'attr-name': { | ||
pattern: /[^\s>\/]+/, | ||
inside: { | ||
'namespace': /^[^\s>\/:]+:/ | ||
} | ||
} | ||
}, | ||
alias: 'language-css' | ||
} | ||
}, | ||
'entity': /&#?[\da-z]{1,8};/i | ||
}; | ||
Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] = Prism.languages.markup['entity']; // Plugin to make entity title show the real entity, idea by Roman Komarov | ||
Prism.hooks.add('wrap', function (env) { | ||
if (env.type === 'entity') { | ||
env.attributes['title'] = env.content.replace(/&/, '&'); | ||
} | ||
}, Prism.languages.markup.tag); | ||
} | ||
/* ********************************************** | ||
Begin prism-clike.js | ||
********************************************** */ | ||
}); | ||
Prism.languages.xml = Prism.languages.markup; | ||
Prism.languages.html = Prism.languages.markup; | ||
Prism.languages.mathml = Prism.languages.markup; | ||
Prism.languages.svg = Prism.languages.markup; | ||
/* ********************************************** | ||
Begin prism-css.js | ||
********************************************** */ | ||
Prism.languages.css = { | ||
'comment': /\/\*[\s\S]*?\*\//, | ||
'atrule': { | ||
pattern: /@[\w-]+?.*?(?:;|(?=\s*\{))/i, | ||
inside: { | ||
'rule': /@[\w-]+/ // See rest below | ||
Prism.languages.clike = { | ||
'comment': [{ | ||
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/, | ||
lookbehind: true | ||
}, { | ||
pattern: /(^|[^\\:])\/\/.*/, | ||
lookbehind: true, | ||
greedy: true | ||
}], | ||
'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+\())[\w.\\]+/i, | ||
lookbehind: true, | ||
inside: { | ||
punctuation: /[.\\]/ | ||
} | ||
}, | ||
'keyword': /\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/, | ||
'boolean': /\b(?:true|false)\b/, | ||
'function': /[a-z0-9_]+(?=\()/i, | ||
'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?/i, | ||
'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/, | ||
'punctuation': /[{}[\];(),.:]/ | ||
}; | ||
/* ********************************************** | ||
Begin prism-javascript.js | ||
********************************************** */ | ||
} | ||
}, | ||
'url': /url\((?:(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1|.*?)\)/i, | ||
'selector': /[^{}\s][^{};]*?(?=\s*\{)/, | ||
'string': { | ||
pattern: /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/, | ||
greedy: true | ||
}, | ||
'property': /[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i, | ||
'important': /\B!important\b/i, | ||
'function': /[-a-z0-9]+(?=\()/i, | ||
'punctuation': /[(){};:]/ | ||
}; | ||
Prism.languages.css['atrule'].inside.rest = Prism.languages.css; | ||
Prism.languages.javascript = Prism.languages.extend('clike', { | ||
'keyword': /\b(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield)\b/, | ||
'number': /\b(?:0[xX][\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+|NaN|Infinity)\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][+-]?\d+)?/, | ||
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444) | ||
'function': /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*\()/i, | ||
'operator': /-[-=]?|\+[+=]?|!=?=?|<<?=?|>>?>?=?|=(?:==?|>)?|&[&=]?|\|[|=]?|\*\*?=?|\/=?|~|\^=?|%=?|\?|\.{3}/ | ||
}); | ||
Prism.languages.insertBefore('javascript', 'keyword', { | ||
'regex': { | ||
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s])\s*)\/(\[[^\]\r\n]+]|\\.|[^/\\\[\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})\]]))/, | ||
lookbehind: true, | ||
greedy: true | ||
}, | ||
// This must be declared before keyword because we use "function" inside the look-forward | ||
'function-variable': { | ||
pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=\s*(?:function\b|(?:\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/i, | ||
alias: 'function' | ||
}, | ||
'constant': /\b[A-Z][A-Z\d_]*\b/ | ||
}); | ||
Prism.languages.insertBefore('javascript', 'string', { | ||
'template-string': { | ||
pattern: /`(?:\\[\s\S]|\${[^}]+}|[^\\`])*`/, | ||
greedy: true, | ||
inside: { | ||
'interpolation': { | ||
pattern: /\${[^}]+}/, | ||
if (Prism.languages.markup) { | ||
Prism.languages.insertBefore('markup', 'tag', { | ||
'style': { | ||
pattern: /(<style[\s\S]*?>)[\s\S]*?(?=<\/style>)/i, | ||
lookbehind: true, | ||
inside: Prism.languages.css, | ||
alias: 'language-css', | ||
greedy: true | ||
} | ||
}); | ||
Prism.languages.insertBefore('inside', 'attr-value', { | ||
'style-attr': { | ||
pattern: /\s*style=("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/i, | ||
inside: { | ||
'interpolation-punctuation': { | ||
pattern: /^\${|}$/, | ||
alias: 'punctuation' | ||
'attr-name': { | ||
pattern: /^\s*style/i, | ||
inside: Prism.languages.markup.tag.inside | ||
}, | ||
rest: null // See below | ||
} | ||
}, | ||
'string': /[\s\S]+/ | ||
} | ||
'punctuation': /^\s*=\s*['"]|['"]\s*$/, | ||
'attr-value': { | ||
pattern: /.+/i, | ||
inside: Prism.languages.css | ||
} | ||
}, | ||
alias: 'language-css' | ||
} | ||
}, Prism.languages.markup.tag); | ||
} | ||
}); | ||
Prism.languages.javascript['template-string'].inside['interpolation'].inside.rest = Prism.languages.javascript; | ||
/* ********************************************** | ||
Begin prism-clike.js | ||
********************************************** */ | ||
if (Prism.languages.markup) { | ||
Prism.languages.insertBefore('markup', 'tag', { | ||
'script': { | ||
pattern: /(<script[\s\S]*?>)[\s\S]*?(?=<\/script>)/i, | ||
Prism.languages.clike = { | ||
'comment': [{ | ||
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/, | ||
lookbehind: true | ||
}, { | ||
pattern: /(^|[^\\:])\/\/.*/, | ||
lookbehind: true, | ||
inside: Prism.languages.javascript, | ||
alias: 'language-javascript', | ||
greedy: true | ||
}], | ||
'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+\())[\w.\\]+/i, | ||
lookbehind: true, | ||
inside: { | ||
punctuation: /[.\\]/ | ||
} | ||
}, | ||
'keyword': /\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/, | ||
'boolean': /\b(?:true|false)\b/, | ||
'function': /[a-z0-9_]+(?=\()/i, | ||
'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?/i, | ||
'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/, | ||
'punctuation': /[{}[\];(),.:]/ | ||
}; | ||
/* ********************************************** | ||
Begin prism-javascript.js | ||
********************************************** */ | ||
Prism.languages.javascript = Prism.languages.extend('clike', { | ||
'keyword': /\b(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield)\b/, | ||
'number': /\b(?:0[xX][\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+|NaN|Infinity)\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][+-]?\d+)?/, | ||
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444) | ||
'function': /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*\()/i, | ||
'operator': /-[-=]?|\+[+=]?|!=?=?|<<?=?|>>?>?=?|=(?:==?|>)?|&[&=]?|\|[|=]?|\*\*?=?|\/=?|~|\^=?|%=?|\?|\.{3}/ | ||
}); | ||
Prism.languages.insertBefore('javascript', 'keyword', { | ||
'regex': { | ||
pattern: /((?:^|[^$\w\xA0-\uFFFF."'\])\s])\s*)\/(\[[^\]\r\n]+]|\\.|[^/\\\[\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})\]]))/, | ||
lookbehind: true, | ||
greedy: true | ||
}, | ||
// This must be declared before keyword because we use "function" inside the look-forward | ||
'function-variable': { | ||
pattern: /[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*=\s*(?:function\b|(?:\([^()]*\)|[_$a-z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)\s*=>))/i, | ||
alias: 'function' | ||
}, | ||
'constant': /\b[A-Z][A-Z\d_]*\b/ | ||
}); | ||
Prism.languages.insertBefore('javascript', 'string', { | ||
'template-string': { | ||
pattern: /`(?:\\[\s\S]|\${[^}]+}|[^\\`])*`/, | ||
greedy: true, | ||
inside: { | ||
'interpolation': { | ||
pattern: /\${[^}]+}/, | ||
inside: { | ||
'interpolation-punctuation': { | ||
pattern: /^\${|}$/, | ||
alias: 'punctuation' | ||
}, | ||
rest: null // See below | ||
} | ||
}, | ||
'string': /[\s\S]+/ | ||
} | ||
} | ||
}); | ||
} | ||
Prism.languages.javascript['template-string'].inside['interpolation'].inside.rest = Prism.languages.javascript; | ||
Prism.languages.js = Prism.languages.javascript; | ||
/* ********************************************** | ||
Begin prism-file-highlight.js | ||
********************************************** */ | ||
(function () { | ||
if (typeof self === 'undefined' || !self.Prism || !self.document || !document.querySelector) { | ||
return; | ||
if (Prism.languages.markup) { | ||
Prism.languages.insertBefore('markup', 'tag', { | ||
'script': { | ||
pattern: /(<script[\s\S]*?>)[\s\S]*?(?=<\/script>)/i, | ||
lookbehind: true, | ||
inside: Prism.languages.javascript, | ||
alias: 'language-javascript', | ||
greedy: true | ||
} | ||
}); | ||
} | ||
self.Prism.fileHighlight = function () { | ||
var Extensions = { | ||
'js': 'javascript', | ||
'py': 'python', | ||
'rb': 'ruby', | ||
'ps1': 'powershell', | ||
'psm1': 'powershell', | ||
'sh': 'bash', | ||
'bat': 'batch', | ||
'h': 'c', | ||
'tex': 'latex' | ||
}; | ||
Array.prototype.slice.call(document.querySelectorAll('pre[data-src]')).forEach(function (pre) { | ||
var src = pre.getAttribute('data-src'); | ||
var language, | ||
parent = pre; | ||
var lang = /\blang(?:uage)?-([\w-]+)\b/i; | ||
Prism.languages.js = Prism.languages.javascript; | ||
/* ********************************************** | ||
Begin prism-file-highlight.js | ||
********************************************** */ | ||
while (parent && !lang.test(parent.className)) { | ||
parent = parent.parentNode; | ||
} | ||
(function () { | ||
if (typeof self === 'undefined' || !self.Prism || !self.document || !document.querySelector) { | ||
return; | ||
} | ||
if (parent) { | ||
language = (pre.className.match(lang) || [, ''])[1]; | ||
} | ||
self.Prism.fileHighlight = function () { | ||
var Extensions = { | ||
'js': 'javascript', | ||
'py': 'python', | ||
'rb': 'ruby', | ||
'ps1': 'powershell', | ||
'psm1': 'powershell', | ||
'sh': 'bash', | ||
'bat': 'batch', | ||
'h': 'c', | ||
'tex': 'latex' | ||
}; | ||
Array.prototype.slice.call(document.querySelectorAll('pre[data-src]')).forEach(function (pre) { | ||
var src = pre.getAttribute('data-src'); | ||
var language, | ||
parent = pre; | ||
var lang = /\blang(?:uage)?-([\w-]+)\b/i; | ||
if (!language) { | ||
var extension = (src.match(/\.(\w+)$/) || [, ''])[1]; | ||
language = Extensions[extension] || extension; | ||
} | ||
while (parent && !lang.test(parent.className)) { | ||
parent = parent.parentNode; | ||
} | ||
var code = document.createElement('code'); | ||
code.className = 'language-' + language; | ||
pre.textContent = ''; | ||
code.textContent = 'Loading…'; | ||
pre.appendChild(code); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('GET', src, true); | ||
if (parent) { | ||
language = (pre.className.match(lang) || [, ''])[1]; | ||
} | ||
xhr.onreadystatechange = function () { | ||
if (xhr.readyState == 4) { | ||
if (xhr.status < 400 && xhr.responseText) { | ||
code.textContent = xhr.responseText; | ||
Prism.highlightElement(code); | ||
} else if (xhr.status >= 400) { | ||
code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText; | ||
} else { | ||
code.textContent = '✖ Error: File does not exist or is empty'; | ||
} | ||
if (!language) { | ||
var extension = (src.match(/\.(\w+)$/) || [, ''])[1]; | ||
language = Extensions[extension] || extension; | ||
} | ||
}; | ||
xhr.send(null); | ||
}); | ||
var code = document.createElement('code'); | ||
code.className = 'language-' + language; | ||
pre.textContent = ''; | ||
code.textContent = 'Loading…'; | ||
pre.appendChild(code); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('GET', src, true); | ||
if (Prism.plugins.toolbar) { | ||
Prism.plugins.toolbar.registerButton('download-file', function (env) { | ||
var pre = env.element.parentNode; | ||
xhr.onreadystatechange = function () { | ||
if (xhr.readyState == 4) { | ||
if (xhr.status < 400 && xhr.responseText) { | ||
code.textContent = xhr.responseText; | ||
Prism.highlightElement(code); | ||
} else if (xhr.status >= 400) { | ||
code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText; | ||
} else { | ||
code.textContent = '✖ Error: File does not exist or is empty'; | ||
} | ||
} | ||
}; | ||
if (!pre || !/pre/i.test(pre.nodeName) || !pre.hasAttribute('data-src') || !pre.hasAttribute('data-download-link')) { | ||
return; | ||
} | ||
var src = pre.getAttribute('data-src'); | ||
var a = document.createElement('a'); | ||
a.textContent = pre.getAttribute('data-download-link-label') || 'Download'; | ||
a.setAttribute('download', ''); | ||
a.href = src; | ||
return a; | ||
xhr.send(null); | ||
}); | ||
} | ||
}; | ||
document.addEventListener('DOMContentLoaded', self.Prism.fileHighlight); | ||
})(); | ||
if (Prism.plugins.toolbar) { | ||
Prism.plugins.toolbar.registerButton('download-file', function (env) { | ||
var pre = env.element.parentNode; | ||
if (!pre || !/pre/i.test(pre.nodeName) || !pre.hasAttribute('data-src') || !pre.hasAttribute('data-download-link')) { | ||
return; | ||
} | ||
var src = pre.getAttribute('data-src'); | ||
var a = document.createElement('a'); | ||
a.textContent = pre.getAttribute('data-download-link-label') || 'Download'; | ||
a.setAttribute('download', ''); | ||
a.href = src; | ||
return a; | ||
}); | ||
} | ||
}; | ||
document.addEventListener('DOMContentLoaded', self.Prism.fileHighlight); | ||
})(); | ||
}); | ||
@@ -926,3 +946,3 @@ | ||
var SyntaxHighlight = (function () { | ||
var SyntaxHighlight = function SyntaxHighlight() { | ||
return { | ||
@@ -936,3 +956,3 @@ renderMark: function renderMark(props, editor, next) { | ||
case "comment": | ||
return React.createElement("span", _extends({}, attributes, { | ||
return React.createElement("span", _extends$1({}, attributes, { | ||
"data-type": "comment", | ||
@@ -945,3 +965,3 @@ style: { | ||
case "keyword": | ||
return React.createElement("span", _extends({}, attributes, { | ||
return React.createElement("span", _extends$1({}, attributes, { | ||
"data-type": "keyword", | ||
@@ -954,3 +974,3 @@ style: { | ||
case "tag": | ||
return React.createElement("span", _extends({}, attributes, { | ||
return React.createElement("span", _extends$1({}, attributes, { | ||
"data-type": "tag", | ||
@@ -963,3 +983,3 @@ style: { | ||
case "punctuation": | ||
return React.createElement("span", _extends({}, attributes, { | ||
return React.createElement("span", _extends$1({}, attributes, { | ||
"data-type": "punctuation", | ||
@@ -977,3 +997,3 @@ style: { | ||
var others = next() || []; | ||
if (node.type != "html") return others; | ||
if (node.type != "code") return others; | ||
var texts = node.getTexts().toArray(); | ||
@@ -1044,6 +1064,6 @@ var string = texts.map(function (t) { | ||
}; | ||
}); | ||
}; | ||
function _extends$1() { | ||
_extends$1 = Object.assign || function (target) { | ||
function _extends$1$1() { | ||
_extends$1$1 = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
@@ -1062,3 +1082,3 @@ var source = arguments[i]; | ||
return _extends$1.apply(this, arguments); | ||
return _extends$1$1.apply(this, arguments); | ||
} | ||
@@ -1327,3 +1347,3 @@ | ||
var KeyMap = function KeyMap(shortcuts, options) { | ||
var config = _extends$1({ | ||
var config = _extends$1$1({ | ||
if: function _if() { | ||
@@ -1361,2 +1381,106 @@ return true; | ||
var isCodeLine = function isCodeLine(editor) { | ||
return editor.value.startBlock.type == "code-line"; | ||
}; | ||
var onEnter = function onEnter(event, editor, next) { | ||
event.preventDefault(); | ||
editor.splitBlock().setBlocks("code-line"); | ||
}; | ||
var onTab = function onTab(event, editor, next) { | ||
event.preventDefault(); | ||
editor.insertText(" "); | ||
}; | ||
var onSelectAll = function onSelectAll(event, editor, next) { | ||
event.preventDefault(); | ||
var startBlock = editor.value.startBlock; | ||
var document = editor.value.document; | ||
var parent = document.getParent(startBlock.key); | ||
editor.moveToRangeOfNode(parent); | ||
}; | ||
var schema = { | ||
blocks: { | ||
code: { | ||
nodes: [{ | ||
match: { | ||
type: "code-line" | ||
} | ||
}] | ||
}, | ||
code_line: { | ||
nodes: [{ | ||
match: { | ||
object: "text" | ||
} | ||
}] | ||
} | ||
} | ||
}; | ||
var index = function index(options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var config = _extends$1({ | ||
highlight: true | ||
}, options); | ||
var classNames = _extends$1({ | ||
code: "editor-code", | ||
"code-line": "editor-code-line" | ||
}, config.classNames); | ||
return [{ | ||
commands: { | ||
insertCode: function insertCode(editor, _ref) { | ||
var code = _ref.code; | ||
editor.insertBlock({ | ||
object: "block", | ||
type: "code", | ||
nodes: [{ | ||
object: "block", | ||
type: "code-line", | ||
nodes: [{ | ||
object: "text", | ||
leaves: [code] | ||
}] | ||
}] | ||
}); | ||
} | ||
}, | ||
renderNode: function renderNode(props, editor, next) { | ||
var node = props.node; | ||
var className = classNames[node.type]; | ||
switch (node.type) { | ||
case "code": | ||
return React.createElement("div", _extends$1({ | ||
className: className | ||
}, props.attributes), props.children); | ||
case "code-line": | ||
{ | ||
return React.createElement("div", _extends$1({ | ||
className: className | ||
}, props.attributes), props.children); | ||
} | ||
default: | ||
return next(); | ||
} | ||
}, | ||
schema: schema | ||
}].concat(config.highlight ? [SyntaxHighlight()] : [], [KeyMap({ | ||
"mod+a": onSelectAll, | ||
tab: onTab, | ||
enter: onEnter | ||
}, { | ||
if: isCodeLine | ||
})]); | ||
}; | ||
var HTMLNode = | ||
@@ -1437,25 +1561,3 @@ /*#__PURE__*/ | ||
var isCodeLine = function isCodeLine(editor) { | ||
return editor.value.startBlock.type == "code-line"; | ||
}; | ||
var onEnter = function onEnter(event, editor, next) { | ||
event.preventDefault(); | ||
editor.splitBlock().setBlocks("code-line"); | ||
}; | ||
var onTab = function onTab(event, editor, next) { | ||
event.preventDefault(); | ||
editor.insertText(" "); | ||
}; | ||
var onSelectAll = function onSelectAll(event, editor, next) { | ||
event.preventDefault(); | ||
var startBlock = editor.value.startBlock; | ||
var document = editor.value.document; | ||
var parent = document.getParent(startBlock.key); | ||
editor.moveToRangeOfNode(parent); | ||
}; | ||
var schema = { | ||
var schema$1 = { | ||
blocks: { | ||
@@ -1468,20 +1570,6 @@ html: { | ||
}] | ||
}, | ||
code: { | ||
nodes: [{ | ||
match: { | ||
type: "code-line" | ||
} | ||
}] | ||
}, | ||
code_line: { | ||
nodes: [{ | ||
match: { | ||
object: "text" | ||
} | ||
}] | ||
} | ||
} | ||
}; | ||
var index = (function () { | ||
var index$1 = (function () { | ||
return [{ | ||
@@ -1519,10 +1607,2 @@ commands: { | ||
case "code": | ||
return React.createElement("div", props.attributes, props.children); | ||
case "code-line": | ||
{ | ||
return React.createElement("div", props.attributes, props.children); | ||
} | ||
default: | ||
@@ -1532,12 +1612,6 @@ return next(); | ||
}, | ||
schema: schema | ||
}, SyntaxHighlight(), KeyMap({ | ||
"mod+a": onSelectAll, | ||
tab: onTab, | ||
enter: onEnter | ||
}, { | ||
if: isCodeLine | ||
})]; | ||
schema: schema$1 | ||
}, index()]; | ||
}); | ||
export default index; | ||
export default index$1; |
{ | ||
"name": "@convertkit/editor-html", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "A plugin for handling HTML in the ConvertKit Editor", | ||
@@ -29,7 +29,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"@convertkit/slate-keymap": "^0.0.2", | ||
"is-hotkey": "^0.1.4", | ||
"prismjs": "^1.15.0" | ||
"@convertkit/editor-code": "^0.0.2" | ||
}, | ||
"gitHead": "04a1235d5f31fe0cff335dc8c25907e65b80af27" | ||
"gitHead": "acefa480d3a0d5b14d23bd96f51b0c53b5f94fdf" | ||
} |
import React, { Component } from "react"; | ||
import SyntaxHighlight from "./plugins/syntax-highlight"; | ||
import KeyMap from "@convertkit/slate-keymap"; | ||
import Code from "@convertkit/editor-code"; | ||
import HTMLNode from "./html-node"; | ||
import "./index.css"; | ||
const isCodeLine = editor => editor.value.startBlock.type == "code-line"; | ||
const onEnter = (event, editor, next) => { | ||
event.preventDefault(); | ||
editor.splitBlock().setBlocks("code-line"); | ||
}; | ||
const onTab = (event, editor, next) => { | ||
event.preventDefault(); | ||
editor.insertText(" "); | ||
}; | ||
const onSelectAll = (event, editor, next) => { | ||
event.preventDefault(); | ||
const startBlock = editor.value.startBlock; | ||
const document = editor.value.document; | ||
const parent = document.getParent(startBlock.key); | ||
editor.moveToRangeOfNode(parent); | ||
}; | ||
const schema = { | ||
@@ -36,16 +14,2 @@ blocks: { | ||
] | ||
}, | ||
code: { | ||
nodes: [ | ||
{ | ||
match: { type: "code-line" } | ||
} | ||
] | ||
}, | ||
code_line: { | ||
nodes: [ | ||
{ | ||
match: { object: "text" } | ||
} | ||
] | ||
} | ||
@@ -83,7 +47,3 @@ } | ||
} | ||
case "code": | ||
return <div {...props.attributes}>{props.children}</div>; | ||
case "code-line": { | ||
return <div {...props.attributes}>{props.children}</div>; | ||
} | ||
default: | ||
@@ -95,11 +55,3 @@ return next(); | ||
}, | ||
SyntaxHighlight(), | ||
KeyMap( | ||
{ | ||
"mod+a": onSelectAll, | ||
tab: onTab, | ||
enter: onEnter | ||
}, | ||
{ if: isCodeLine } | ||
) | ||
Code() | ||
]; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6
49199
6
1556
+ Added@convertkit/editor-code@0.0.2(transitive)
- Removed@convertkit/slate-keymap@^0.0.2
- Removedis-hotkey@^0.1.4
- Removedprismjs@^1.15.0