Skip to content

Commit

Permalink
fix prism for real (preactjs#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
developit authored Nov 14, 2020
1 parent f850c27 commit 70b2efc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion size-plugin-browser.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"timestamp":1594661804180,"files":[{"filename":"sw-esm.js","previous":8448,"size":8448,"diff":0},{"filename":"sw.js","previous":8445,"size":8445,"diff":0},{"filename":"bundle.*****.esm.js","previous":27160,"size":26963,"diff":-197},{"filename":"editor.chunk.b63ca.css","previous":2121,"size":0,"diff":-2121},{"filename":"editor.chunk.*****.esm.js","previous":66879,"size":66878,"diff":-1},{"filename":"emoji.chunk.*****.esm.js","previous":8859,"size":8860,"diff":1},{"filename":"polyfills.*****.esm.js","previous":2136,"size":2136,"diff":0},{"filename":"runner.chunk.*****.esm.js","previous":7999,"size":7998,"diff":-1},{"filename":"5.chunk.*****.esm.js","previous":3379,"size":3395,"diff":16},{"filename":"prism.e9154.worker.js","previous":7324,"size":0,"diff":-7324},{"filename":"markdown.9e3c3.worker.js","previous":10002,"size":10002,"diff":0},{"filename":"repl.5aaa2.worker.js","previous":71764,"size":0,"diff":-71764},{"filename":"prism.4a4e2.worker.js","previous":7323,"size":0,"diff":-7323},{"filename":"markdown.262b2.worker.js","previous":10257,"size":10257,"diff":0},{"filename":"repl.39c06.worker.js","previous":73425,"size":0,"diff":-73425},{"filename":"editor.chunk.17c2c.js","previous":66910,"size":0,"diff":-66910},{"filename":"emoji.chunk.62c4f.js","previous":8849,"size":0,"diff":-8849},{"filename":"polyfills.510ca.js","previous":2134,"size":2134,"diff":0},{"filename":"runner.chunk.327f8.js","previous":8038,"size":0,"diff":-8038},{"filename":"bundle.b37af.css","previous":9837,"size":0,"diff":-9837},{"filename":"5.chunk.18ffb.css","previous":1435,"size":0,"diff":-1435},{"filename":"bundle.4c49b.js","previous":27442,"size":0,"diff":-27442},{"filename":"5.chunk.25509.js","previous":3496,"size":0,"diff":-3496},{"filename":"prism.24b11.worker.js","previous":0,"size":7323,"diff":7323},{"filename":"repl.93bfc.worker.js","previous":0,"size":71964,"diff":71964},{"filename":"bundle.0b323.css","previous":0,"size":9837,"diff":9837},{"filename":"editor.chunk.e40fb.css","previous":0,"size":2121,"diff":2121},{"filename":"5.chunk.9b2fb.css","previous":0,"size":1435,"diff":1435},{"filename":"prism.7e10e.worker.js","previous":0,"size":7322,"diff":7322},{"filename":"repl.434c0.worker.js","previous":0,"size":73654,"diff":73654},{"filename":"bundle.472ec.js","previous":0,"size":27251,"diff":27251},{"filename":"editor.chunk.0b4bd.js","previous":0,"size":66910,"diff":66910},{"filename":"emoji.chunk.a6ba4.js","previous":0,"size":8848,"diff":8848},{"filename":"runner.chunk.c259a.js","previous":0,"size":8037,"diff":8037},{"filename":"5.chunk.9d09e.js","previous":0,"size":3508,"diff":3508}]},{"timestamp":1593808916710,"files":[{"filename":"sw-esm.js","previous":8448,"size":8448,"diff":0},{"filename":"sw.js","previous":8445,"size":8445,"diff":0},{"filename":"bundle.*****.esm.js","previous":27206,"size":27160,"diff":-46},{"filename":"editor.chunk.b63ca.css","previous":2121,"size":2121,"diff":0},{"filename":"editor.chunk.*****.esm.js","previous":66879,"size":66879,"diff":0},{"filename":"emoji.chunk.*****.esm.js","previous":8859,"size":8859,"diff":0},{"filename":"polyfills.*****.esm.js","previous":2136,"size":2136,"diff":0},{"filename":"runner.chunk.*****.esm.js","previous":7999,"size":7999,"diff":0},{"filename":"5.chunk.b8f8a.css","previous":1476,"size":0,"diff":-1476},{"filename":"5.chunk.*****.esm.js","previous":3413,"size":3379,"diff":-34},{"filename":"bundle.51329.css","previous":9930,"size":0,"diff":-9930},{"filename":"prism.e9154.worker.js","previous":7324,"size":7324,"diff":0},{"filename":"markdown.9e3c3.worker.js","previous":10002,"size":10002,"diff":0},{"filename":"repl.5aaa2.worker.js","previous":71764,"size":71764,"diff":0},{"filename":"prism.4a4e2.worker.js","previous":7323,"size":7323,"diff":0},{"filename":"markdown.262b2.worker.js","previous":10257,"size":10257,"diff":0},{"filename":"repl.39c06.worker.js","previous":73425,"size":73425,"diff":0},{"filename":"editor.chunk.17c2c.js","previous":66910,"size":66910,"diff":0},{"filename":"emoji.chunk.62c4f.js","previous":8849,"size":8849,"diff":0},{"filename":"polyfills.510ca.js","previous":2134,"size":2134,"diff":0},{"filename":"runner.chunk.327f8.js","previous":8038,"size":8038,"diff":0},{"filename":"bundle.bb138.js","previous":27494,"size":0,"diff":-27494},{"filename":"5.chunk.cab52.js","previous":3526,"size":0,"diff":-3526},{"filename":"bundle.b37af.css","previous":0,"size":9837,"diff":9837},{"filename":"5.chunk.18ffb.css","previous":0,"size":1435,"diff":1435},{"filename":"bundle.4c49b.js","previous":0,"size":27442,"diff":27442},{"filename":"5.chunk.25509.js","previous":0,"size":3496,"diff":3496}]}]
[{"timestamp":1605325955917,"files":[{"filename":"sw.js","previous":8445,"size":8445,"diff":0},{"filename":"markdown.262b2.worker.js","previous":10257,"size":10257,"diff":0},{"filename":"prism.52ee2.worker.js","previous":7135,"size":0,"diff":-7135},{"filename":"repl.39c06.worker.js","previous":73425,"size":73425,"diff":0},{"filename":"bundle.1b531.css","previous":9970,"size":9970,"diff":0},{"filename":"bundle.*****.js","previous":28139,"size":28139,"diff":0},{"filename":"editor.chunk.dab30.css","previous":2131,"size":2131,"diff":0},{"filename":"editor.chunk.*****.js","previous":66911,"size":66911,"diff":0},{"filename":"emoji.chunk.*****.js","previous":8849,"size":8849,"diff":0},{"filename":"polyfills.*****.js","previous":2134,"size":2134,"diff":0},{"filename":"runner.chunk.*****.js","previous":8450,"size":8450,"diff":0},{"filename":"5.chunk.e19e8.css","previous":1448,"size":1448,"diff":0},{"filename":"5.chunk.*****.js","previous":3496,"size":3496,"diff":0},{"filename":"prism.cdc62.worker.js","previous":0,"size":7157,"diff":7157}]},{"timestamp":1605325684673,"files":[{"filename":"sw-esm.js","previous":8448,"size":0,"diff":-8448},{"filename":"sw.js","previous":8445,"size":8445,"diff":0},{"filename":"bundle.*****.esm.js","previous":26963,"size":0,"diff":-26963},{"filename":"editor.chunk.*****.esm.js","previous":66878,"size":0,"diff":-66878},{"filename":"emoji.chunk.*****.esm.js","previous":8860,"size":0,"diff":-8860},{"filename":"polyfills.*****.esm.js","previous":2136,"size":0,"diff":-2136},{"filename":"runner.chunk.*****.esm.js","previous":7998,"size":0,"diff":-7998},{"filename":"5.chunk.*****.esm.js","previous":3395,"size":0,"diff":-3395},{"filename":"markdown.9e3c3.worker.js","previous":10002,"size":0,"diff":-10002},{"filename":"markdown.262b2.worker.js","previous":10257,"size":10257,"diff":0},{"filename":"polyfills.510ca.js","previous":2134,"size":0,"diff":-2134},{"filename":"prism.24b11.worker.js","previous":7323,"size":0,"diff":-7323},{"filename":"repl.93bfc.worker.js","previous":71964,"size":0,"diff":-71964},{"filename":"bundle.0b323.css","previous":9837,"size":0,"diff":-9837},{"filename":"editor.chunk.e40fb.css","previous":2121,"size":0,"diff":-2121},{"filename":"5.chunk.9b2fb.css","previous":1435,"size":0,"diff":-1435},{"filename":"prism.7e10e.worker.js","previous":7322,"size":0,"diff":-7322},{"filename":"repl.434c0.worker.js","previous":73654,"size":0,"diff":-73654},{"filename":"bundle.472ec.js","previous":27251,"size":0,"diff":-27251},{"filename":"editor.chunk.0b4bd.js","previous":66910,"size":0,"diff":-66910},{"filename":"emoji.chunk.a6ba4.js","previous":8848,"size":0,"diff":-8848},{"filename":"runner.chunk.c259a.js","previous":8037,"size":0,"diff":-8037},{"filename":"5.chunk.9d09e.js","previous":3508,"size":0,"diff":-3508},{"filename":"prism.52ee2.worker.js","previous":0,"size":7135,"diff":7135},{"filename":"repl.39c06.worker.js","previous":0,"size":73425,"diff":73425},{"filename":"bundle.1b531.css","previous":0,"size":9970,"diff":9970},{"filename":"bundle.*****.js","previous":0,"size":28139,"diff":28139},{"filename":"editor.chunk.dab30.css","previous":0,"size":2131,"diff":2131},{"filename":"editor.chunk.*****.js","previous":0,"size":66911,"diff":66911},{"filename":"emoji.chunk.*****.js","previous":0,"size":8849,"diff":8849},{"filename":"polyfills.*****.js","previous":0,"size":2134,"diff":2134},{"filename":"runner.chunk.*****.js","previous":0,"size":8450,"diff":8450},{"filename":"5.chunk.e19e8.css","previous":0,"size":1448,"diff":1448},{"filename":"5.chunk.*****.js","previous":0,"size":3496,"diff":3496}]},{"timestamp":1594661804180,"files":[{"filename":"sw-esm.js","previous":8448,"size":8448,"diff":0},{"filename":"sw.js","previous":8445,"size":8445,"diff":0},{"filename":"bundle.*****.esm.js","previous":27160,"size":26963,"diff":-197},{"filename":"editor.chunk.b63ca.css","previous":2121,"size":0,"diff":-2121},{"filename":"editor.chunk.*****.esm.js","previous":66879,"size":66878,"diff":-1},{"filename":"emoji.chunk.*****.esm.js","previous":8859,"size":8860,"diff":1},{"filename":"polyfills.*****.esm.js","previous":2136,"size":2136,"diff":0},{"filename":"runner.chunk.*****.esm.js","previous":7999,"size":7998,"diff":-1},{"filename":"5.chunk.*****.esm.js","previous":3379,"size":3395,"diff":16},{"filename":"prism.e9154.worker.js","previous":7324,"size":0,"diff":-7324},{"filename":"markdown.9e3c3.worker.js","previous":10002,"size":10002,"diff":0},{"filename":"repl.5aaa2.worker.js","previous":71764,"size":0,"diff":-71764},{"filename":"prism.4a4e2.worker.js","previous":7323,"size":0,"diff":-7323},{"filename":"markdown.262b2.worker.js","previous":10257,"size":10257,"diff":0},{"filename":"repl.39c06.worker.js","previous":73425,"size":0,"diff":-73425},{"filename":"editor.chunk.17c2c.js","previous":66910,"size":0,"diff":-66910},{"filename":"emoji.chunk.62c4f.js","previous":8849,"size":0,"diff":-8849},{"filename":"polyfills.510ca.js","previous":2134,"size":2134,"diff":0},{"filename":"runner.chunk.327f8.js","previous":8038,"size":0,"diff":-8038},{"filename":"bundle.b37af.css","previous":9837,"size":0,"diff":-9837},{"filename":"5.chunk.18ffb.css","previous":1435,"size":0,"diff":-1435},{"filename":"bundle.4c49b.js","previous":27442,"size":0,"diff":-27442},{"filename":"5.chunk.25509.js","previous":3496,"size":0,"diff":-3496},{"filename":"prism.24b11.worker.js","previous":0,"size":7323,"diff":7323},{"filename":"repl.93bfc.worker.js","previous":0,"size":71964,"diff":71964},{"filename":"bundle.0b323.css","previous":0,"size":9837,"diff":9837},{"filename":"editor.chunk.e40fb.css","previous":0,"size":2121,"diff":2121},{"filename":"5.chunk.9b2fb.css","previous":0,"size":1435,"diff":1435},{"filename":"prism.7e10e.worker.js","previous":0,"size":7322,"diff":7322},{"filename":"repl.434c0.worker.js","previous":0,"size":73654,"diff":73654},{"filename":"bundle.472ec.js","previous":0,"size":27251,"diff":27251},{"filename":"editor.chunk.0b4bd.js","previous":0,"size":66910,"diff":66910},{"filename":"emoji.chunk.a6ba4.js","previous":0,"size":8848,"diff":8848},{"filename":"runner.chunk.c259a.js","previous":0,"size":8037,"diff":8037},{"filename":"5.chunk.9d09e.js","previous":0,"size":3508,"diff":3508}]},{"timestamp":1593808916710,"files":[{"filename":"sw-esm.js","previous":8448,"size":8448,"diff":0},{"filename":"sw.js","previous":8445,"size":8445,"diff":0},{"filename":"bundle.*****.esm.js","previous":27206,"size":27160,"diff":-46},{"filename":"editor.chunk.b63ca.css","previous":2121,"size":2121,"diff":0},{"filename":"editor.chunk.*****.esm.js","previous":66879,"size":66879,"diff":0},{"filename":"emoji.chunk.*****.esm.js","previous":8859,"size":8859,"diff":0},{"filename":"polyfills.*****.esm.js","previous":2136,"size":2136,"diff":0},{"filename":"runner.chunk.*****.esm.js","previous":7999,"size":7999,"diff":0},{"filename":"5.chunk.b8f8a.css","previous":1476,"size":0,"diff":-1476},{"filename":"5.chunk.*****.esm.js","previous":3413,"size":3379,"diff":-34},{"filename":"bundle.51329.css","previous":9930,"size":0,"diff":-9930},{"filename":"prism.e9154.worker.js","previous":7324,"size":7324,"diff":0},{"filename":"markdown.9e3c3.worker.js","previous":10002,"size":10002,"diff":0},{"filename":"repl.5aaa2.worker.js","previous":71764,"size":71764,"diff":0},{"filename":"prism.4a4e2.worker.js","previous":7323,"size":7323,"diff":0},{"filename":"markdown.262b2.worker.js","previous":10257,"size":10257,"diff":0},{"filename":"repl.39c06.worker.js","previous":73425,"size":73425,"diff":0},{"filename":"editor.chunk.17c2c.js","previous":66910,"size":66910,"diff":0},{"filename":"emoji.chunk.62c4f.js","previous":8849,"size":8849,"diff":0},{"filename":"polyfills.510ca.js","previous":2134,"size":2134,"diff":0},{"filename":"runner.chunk.327f8.js","previous":8038,"size":8038,"diff":0},{"filename":"bundle.bb138.js","previous":27494,"size":0,"diff":-27494},{"filename":"5.chunk.cab52.js","previous":3526,"size":0,"diff":-3526},{"filename":"bundle.b37af.css","previous":0,"size":9837,"diff":9837},{"filename":"5.chunk.18ffb.css","previous":0,"size":1435,"diff":1435},{"filename":"bundle.4c49b.js","previous":0,"size":27442,"diff":27442},{"filename":"5.chunk.25509.js","previous":0,"size":3496,"diff":3496}]}]
27 changes: 14 additions & 13 deletions src/lib/prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ https://prismjs.com/download.html#themes=prism-tomorrow&languages=markup+css+cli
*/

var _self = typeof self!=='undefined' ? self : {};
var Prism = function(e) {
var t = /\blang(?:uage)?-([\w-]+)\b/i, n = 0, a = {

var Prism = module.exports = function(e) {
var n = 0, a = {
util: {
encode: function e(t) {
return t instanceof r ? new r(t.type, e(t.content), t.alias) : Array.isArray(t) ? t.map(e) : t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/\u00a0/g, " ");
Expand Down Expand Up @@ -63,7 +64,7 @@ var Prism = function(e) {
for (var l in t) if (t.hasOwnProperty(l)) {
n.call(t, l, t[l], r || l);
var o = t[l], u = a.util.type(o);
"Object" !== u || i[s(o)] ? "Array" !== u || i[s(o)] || (i[s(o)] = !0, e(o, n, l, i)) : (i[s(o)] = !0,
"Object" !== u || i[s(o)] ? "Array" !== u || i[s(o)] || (i[s(o)] = !0, e(o, n, l, i)) : (i[s(o)] = !0,
e(o, n, null, i));
}
}
Expand All @@ -75,7 +76,7 @@ var Prism = function(e) {
grammar: t,
language: n
};
return a.hooks.run("before-tokenize", i), i.tokens = a.tokenize(i.code, i.grammar),
return a.hooks.run("before-tokenize", i), i.tokens = a.tokenize(i.code, i.grammar),
a.hooks.run("after-tokenize", i), r.stringify(a.util.encode(i.tokens), i.language);
},
tokenize: function(e, t) {
Expand Down Expand Up @@ -118,7 +119,7 @@ var Prism = function(e) {
var F = f.pattern.toString().match(/[imsuy]*$/)[0];
f.pattern = RegExp(f.pattern.source, F + "g");
}
for (var x = f.pattern || f, k = s.next, w = u; k !== t.tail && !(c && w >= c.reach); w += k.value.length,
for (var x = f.pattern || f, k = s.next, w = u; k !== t.tail && !(c && w >= c.reach); w += k.value.length,
k = k.next) {
var A = k.value;
if (t.length > e.length) return;
Expand All @@ -129,7 +130,7 @@ var Prism = function(e) {
var $ = E.index + (h && E[1] ? E[1].length : 0), S = E.index + E[0].length, j = w;
for (j += k.value.length; $ >= j; ) j += (k = k.next).value.length;
if (w = j -= k.value.length, k.value instanceof r) continue;
for (var _ = k; _ !== t.tail && (j < S || "string" == typeof _.value); _ = _.next) P++,
for (var _ = k; _ !== t.tail && (j < S || "string" == typeof _.value); _ = _.next) P++,
j += _.value.length;
P--, A = e.slice(w, j), E.index -= w;
} else {
Expand All @@ -142,7 +143,7 @@ var Prism = function(e) {
var N = E[0].slice(v), z = (S = $ + N.length, A.slice(0, $)), C = A.slice(S), B = w + A.length;
c && B > c.reach && (c.reach = B);
var T = k.prev;
z && (T = l(t, T, z), w += z.length), o(t, T, P), k = l(t, T, new r(g, m ? a.tokenize(N, m) : N, b, N)),
z && (T = l(t, T, z), w += z.length), o(t, T, P), k = l(t, T, new r(g, m ? a.tokenize(N, m) : N, b, N)),
C && l(t, k, C), P > 1 && i(e, t, n, k.prev, w, {
cause: g + "," + p,
reach: B
Expand Down Expand Up @@ -194,7 +195,7 @@ var Prism = function(e) {
attributes: {},
language: n
}, s = t.alias;
s && (Array.isArray(s) ? Array.prototype.push.apply(i.classes, s) : i.classes.push(s)),
s && (Array.isArray(s) ? Array.prototype.push.apply(i.classes, s) : i.classes.push(s)),
a.hooks.run("wrap", i);
var l = "";
for (var o in i.attributes) l += " " + o + '="' + (i.attributes[o] || "").replace(/"/g, "&quot;") + '"';
Expand Down Expand Up @@ -300,7 +301,7 @@ Object.defineProperty(Prism.languages.markup.tag, "addInlined", {

Prism.languages.html = Prism.languages.markup,
Prism.languages.svg = Prism.languages.markup,
Prism.languages.xml = Prism.languages.extend("markup", {}),
Prism.languages.xml = Prism.languages.extend("markup", {}),

(function(e) {
var t = /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;
Expand Down Expand Up @@ -512,7 +513,7 @@ Prism.languages.json = {
(function(e) {
var t = e.util.clone(e.languages.javascript);
e.languages.jsx = e.languages.extend("markup", t);
e.languages.jsx.tag.pattern = /<\/?(?:[\w.:-]+\s*(?:\s+(?:[\w.:$-]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s{'">=]+|\{(?:\{(?:\{[^{}]*\}|[^{}])*\}|[^{}])+\}))?|\{\s*\.{3}\s*[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*\s*\}))*\s*\/?)?>/i,
e.languages.jsx.tag.pattern = /<\/?(?:[\w.:-]+\s*(?:\s+(?:[\w.:$-]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s{'">=]+|\{(?:\{(?:\{[^{}]*\}|[^{}])*\}|[^{}])+\}))?|\{\s*\.{3}\s*[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*\s*\}))*\s*\/?)?>/i,
e.languages.jsx.tag.inside.tag.pattern = /^<\/?[^\s>\/]*/i;
e.languages.jsx.tag.inside["attr-value"].pattern = /=(?!\{)(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">]+)/i;
e.languages.jsx.tag.inside.tag.inside["class-name"] = /^[A-Z]\w*(?:\.[A-Z]\w*)*$/;
Expand Down Expand Up @@ -546,11 +547,11 @@ Prism.languages.json = {
if ("string" != typeof s && ("tag" === s.type && s.content[0] && "tag" === s.content[0].type ? "</" === s.content[0].content[0].content ? r.length > 0 && r[r.length - 1].tagName === n(s.content[0].content[1]) && r.pop() : "/>" === s.content[s.content.length - 1].content || r.push({
tagName: n(s.content[0].content[1]),
openedBraces: 0
}) : r.length > 0 && "punctuation" === s.type && "{" === s.content ? r[r.length - 1].openedBraces++ : r.length > 0 && r[r.length - 1].openedBraces > 0 && "punctuation" === s.type && "}" === s.content ? r[r.length - 1].openedBraces-- : l = !0),
}) : r.length > 0 && "punctuation" === s.type && "{" === s.content ? r[r.length - 1].openedBraces++ : r.length > 0 && r[r.length - 1].openedBraces > 0 && "punctuation" === s.type && "}" === s.content ? r[r.length - 1].openedBraces-- : l = !0),
(l || "string" == typeof s) && r.length > 0 && 0 === r[r.length - 1].openedBraces) {
var o = n(s);
i < t.length - 1 && ("string" == typeof t[i + 1] || "plain-text" === t[i + 1].type) && (o += n(t[i + 1]),
t.splice(i + 1, 1)), i > 0 && ("string" == typeof t[i - 1] || "plain-text" === t[i - 1].type) && (o = n(t[i - 1]) + o,
i < t.length - 1 && ("string" == typeof t[i + 1] || "plain-text" === t[i + 1].type) && (o += n(t[i + 1]),
t.splice(i + 1, 1)), i > 0 && ("string" == typeof t[i - 1] || "plain-text" === t[i - 1].type) && (o = n(t[i - 1]) + o,
t.splice(i - 1, 1), i--), t[i] = new e.Token("plain-text", o, null, o);
}
s.content && "string" != typeof s.content && a(s.content);
Expand Down

0 comments on commit 70b2efc

Please sign in to comment.