aboutsummaryrefslogtreecommitdiffstats
path: root/public/prism/prism-js-templates.min.js
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-10-13 19:32:56 +0200
committerArmand Philippot <git@armandphilippot.com>2023-11-11 18:14:41 +0100
commit006b15b467a5cd835a6eab1b49023100bdc8f2e6 (patch)
tree949c7295c2e206f42357f135bab4696ddf6576ec /public/prism/prism-js-templates.min.js
parent00f147a7a687d5772bcc538bc606cfff972178cd (diff)
refactor(components): rewrite Code component and usePrism hook
* move Prism styles to Sass placeholders to avoid repeats * let usePrism consumer define its plugins (remove default ones) * remove `plugins` prop from Code component * add new props to Code component to let consumer configure plugins (and handle plugin list from the given options) However there are some problems with Prism plugins: line-highlight and treeview does not seems to be loaded. I don't want to use Babel instead of SWC so I have no solution for now.
Diffstat (limited to 'public/prism/prism-js-templates.min.js')
-rw-r--r--public/prism/prism-js-templates.min.js183
1 files changed, 89 insertions, 94 deletions
diff --git a/public/prism/prism-js-templates.min.js b/public/prism/prism-js-templates.min.js
index c3171c1..0a4a47f 100644
--- a/public/prism/prism-js-templates.min.js
+++ b/public/prism/prism-js-templates.min.js
@@ -1,146 +1,141 @@
-!(function (u) {
- var e = u.languages.javascript['template-string'],
- n = e.pattern.source,
- a = e.inside.interpolation,
- i = a.inside['interpolation-punctuation'],
- r = a.pattern.source;
- function t(e, t) {
- if (u.languages[e])
+!(function (e) {
+ var t = e.languages.javascript['template-string'],
+ n = t.pattern.source,
+ r = t.inside.interpolation,
+ a = r.inside['interpolation-punctuation'],
+ i = r.pattern.source;
+ function o(t, r) {
+ if (e.languages[t])
return {
- pattern: RegExp('((?:' + t + ')\\s*)' + n),
+ pattern: RegExp('((?:' + r + ')\\s*)' + n),
lookbehind: !0,
greedy: !0,
inside: {
'template-punctuation': { pattern: /^`|`$/, alias: 'string' },
- 'embedded-code': { pattern: /[\s\S]+/, alias: e },
+ 'embedded-code': { pattern: /[\s\S]+/, alias: t },
},
};
}
- function s(e, t, n) {
- var r = { code: e, grammar: t, language: n };
+ function s(e, t) {
+ return '___' + t.toUpperCase() + '_' + e + '___';
+ }
+ function p(t, n, r) {
+ var a = { code: t, grammar: n, language: r };
return (
- u.hooks.run('before-tokenize', r),
- (r.tokens = u.tokenize(r.code, r.grammar)),
- u.hooks.run('after-tokenize', r),
- r.tokens
+ e.hooks.run('before-tokenize', a),
+ (a.tokens = e.tokenize(a.code, a.grammar)),
+ e.hooks.run('after-tokenize', a),
+ a.tokens
);
}
- function d(e) {
- var t = {};
- t['interpolation-punctuation'] = i;
- var n = u.tokenize(e, t);
- if (3 === n.length) {
- var r = [1, 1];
- r.push.apply(r, s(n[1], u.languages.javascript, 'javascript')),
- n.splice.apply(n, r);
+ function l(t) {
+ var n = {};
+ n['interpolation-punctuation'] = a;
+ var i = e.tokenize(t, n);
+ if (3 === i.length) {
+ var o = [1, 1];
+ o.push.apply(o, p(i[1], e.languages.javascript, 'javascript')),
+ i.splice.apply(i, o);
}
- return new u.Token('interpolation', n, a.alias, e);
+ return new e.Token('interpolation', i, r.alias, t);
}
- function c(a, e, i) {
- var t = u.tokenize(a, {
- interpolation: { pattern: RegExp(r), lookbehind: !0 },
+ function g(t, n, r) {
+ var a = e.tokenize(t, {
+ interpolation: { pattern: RegExp(i), lookbehind: !0 },
}),
- f = 0,
- y = {},
- n = s(
- t
+ o = 0,
+ g = {},
+ u = p(
+ a
.map(function (e) {
if ('string' == typeof e) return e;
- for (
- var t, n = e.content;
- -1 !==
- a.indexOf(
- ((r = f++), (t = '___' + i.toUpperCase() + '_' + r + '___'))
- );
-
- );
- return (y[t] = n), t;
- var r;
+ for (var n, a = e.content; -1 !== t.indexOf((n = s(o++, r))); );
+ return (g[n] = a), n;
})
.join(''),
- e,
- i
+ n,
+ r
),
- v = Object.keys(y);
+ c = Object.keys(g);
return (
- (f = 0),
+ (o = 0),
(function e(t) {
for (var n = 0; n < t.length; n++) {
- if (f >= v.length) return;
+ if (o >= c.length) return;
var r = t[n];
if ('string' == typeof r || 'string' == typeof r.content) {
- var a = v[f],
+ var a = c[o],
i = 'string' == typeof r ? r : r.content,
s = i.indexOf(a);
if (-1 !== s) {
- ++f;
- var o = i.substring(0, s),
- p = d(y[a]),
- l = i.substring(s + a.length),
- g = [];
- if ((o && g.push(o), g.push(p), l)) {
- var u = [l];
- e(u), g.push.apply(g, u);
+ ++o;
+ var p = i.substring(0, s),
+ u = l(g[a]),
+ f = i.substring(s + a.length),
+ y = [];
+ if ((p && y.push(p), y.push(u), f)) {
+ var v = [f];
+ e(v), y.push.apply(y, v);
}
'string' == typeof r
- ? (t.splice.apply(t, [n, 1].concat(g)), (n += g.length - 1))
- : (r.content = g);
+ ? (t.splice.apply(t, [n, 1].concat(y)), (n += y.length - 1))
+ : (r.content = y);
}
} else {
- var c = r.content;
- Array.isArray(c) ? e(c) : e([c]);
+ var d = r.content;
+ Array.isArray(d) ? e(d) : e([d]);
}
}
- })(n),
- new u.Token(i, n, 'language-' + i, a)
+ })(u),
+ new e.Token(r, u, 'language-' + r, t)
);
}
- u.languages.javascript['template-string'] = [
- t(
+ e.languages.javascript['template-string'] = [
+ o(
'css',
'\\b(?:styled(?:\\([^)]*\\))?(?:\\s*\\.\\s*\\w+(?:\\([^)]*\\))*)*|css(?:\\s*\\.\\s*(?:global|resolve))?|createGlobalStyle|keyframes)'
),
- t('html', '\\bhtml|\\.\\s*(?:inner|outer)HTML\\s*\\+?='),
- t('svg', '\\bsvg'),
- t('markdown', '\\b(?:markdown|md)'),
- t('graphql', '\\b(?:gql|graphql(?:\\s*\\.\\s*experimental)?)'),
- t('sql', '\\bsql'),
- e,
+ o('html', '\\bhtml|\\.\\s*(?:inner|outer)HTML\\s*\\+?='),
+ o('svg', '\\bsvg'),
+ o('markdown', '\\b(?:markdown|md)'),
+ o('graphql', '\\b(?:gql|graphql(?:\\s*\\.\\s*experimental)?)'),
+ o('sql', '\\bsql'),
+ t,
].filter(Boolean);
- var o = { javascript: !0, js: !0, typescript: !0, ts: !0, jsx: !0, tsx: !0 };
- function f(e) {
+ var u = { javascript: !0, js: !0, typescript: !0, ts: !0, jsx: !0, tsx: !0 };
+ function c(e) {
return 'string' == typeof e
? e
: Array.isArray(e)
- ? e.map(f).join('')
- : f(e.content);
+ ? e.map(c).join('')
+ : c(e.content);
}
- u.hooks.add('after-tokenize', function (e) {
- e.language in o &&
- !(function e(t) {
- for (var n = 0, r = t.length; n < r; n++) {
- var a = t[n];
- if ('string' != typeof a) {
- var i = a.content;
- if (Array.isArray(i))
- if ('template-string' === a.type) {
- var s = i[1];
+ e.hooks.add('after-tokenize', function (t) {
+ t.language in u &&
+ (function t(n) {
+ for (var r = 0, a = n.length; r < a; r++) {
+ var i = n[r];
+ if ('string' != typeof i) {
+ var o = i.content;
+ if (Array.isArray(o))
+ if ('template-string' === i.type) {
+ var s = o[1];
if (
- 3 === i.length &&
+ 3 === o.length &&
'string' != typeof s &&
'embedded-code' === s.type
) {
- var o = f(s),
- p = s.alias,
- l = Array.isArray(p) ? p[0] : p,
- g = u.languages[l];
- if (!g) continue;
- i[1] = c(o, g, l);
+ var p = c(s),
+ l = s.alias,
+ u = Array.isArray(l) ? l[0] : l,
+ f = e.languages[u];
+ if (!f) continue;
+ o[1] = g(p, f, u);
}
- } else e(i);
- else 'string' != typeof i && e([i]);
+ } else t(o);
+ else 'string' != typeof o && t([o]);
}
}
- })(e.tokens);
+ })(t.tokens);
});
})(Prism);