1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
!(function (o) {
var t = o.util.clone(o.languages.javascript),
e = '(?:\\{<S>*\\.{3}(?:[^{}]|<BRACES>)*\\})';
function n(t, n) {
return (
(t = t
.replace(/<S>/g, function () {
return '(?:\\s|//.*(?!.)|/\\*(?:[^*]|\\*(?!/))\\*/)';
})
.replace(/<BRACES>/g, function () {
return '(?:\\{(?:\\{(?:\\{[^{}]*\\}|[^{}])*\\}|[^{}])*\\})';
})
.replace(/<SPREAD>/g, function () {
return e;
})),
RegExp(t, n)
);
}
(e = n(e).source),
(o.languages.jsx = o.languages.extend('markup', t)),
(o.languages.jsx.tag.pattern = n(
'</?(?:[\\w.:-]+(?:<S>+(?:[\\w.:$-]+(?:=(?:"(?:\\\\[^]|[^\\\\"])*"|\'(?:\\\\[^]|[^\\\\\'])*\'|[^\\s{\'"/>=]+|<BRACES>))?|<SPREAD>))*<S>*/?)?>'
)),
(o.languages.jsx.tag.inside.tag.pattern = /^<\/?[^\s>\/]*/),
(o.languages.jsx.tag.inside['attr-value'].pattern =
/=(?!\{)(?:"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*'|[^\s'">]+)/),
(o.languages.jsx.tag.inside.tag.inside['class-name'] =
/^[A-Z]\w*(?:\.[A-Z]\w*)*$/),
(o.languages.jsx.tag.inside.comment = t.comment),
o.languages.insertBefore(
'inside',
'attr-name',
{ spread: { pattern: n('<SPREAD>'), inside: o.languages.jsx } },
o.languages.jsx.tag
),
o.languages.insertBefore(
'inside',
'special-attr',
{
script: {
pattern: n('=<BRACES>'),
alias: 'language-javascript',
inside: {
'script-punctuation': { pattern: /^=(?=\{)/, alias: 'punctuation' },
rest: o.languages.jsx,
},
},
},
o.languages.jsx.tag
);
var i = function (t) {
return t
? 'string' == typeof t
? t
: 'string' == typeof t.content
? t.content
: t.content.map(i).join('')
: '';
},
r = function (t) {
for (var n = [], e = 0; e < t.length; e++) {
var a = t[e],
s = !1;
if (
('string' != typeof a &&
('tag' === a.type && a.content[0] && 'tag' === a.content[0].type
? '</' === a.content[0].content[0].content
? 0 < n.length &&
n[n.length - 1].tagName === i(a.content[0].content[1]) &&
n.pop()
: '/>' === a.content[a.content.length - 1].content ||
n.push({
tagName: i(a.content[0].content[1]),
openedBraces: 0,
})
: 0 < n.length && 'punctuation' === a.type && '{' === a.content
? n[n.length - 1].openedBraces++
: 0 < n.length &&
0 < n[n.length - 1].openedBraces &&
'punctuation' === a.type &&
'}' === a.content
? n[n.length - 1].openedBraces--
: (s = !0)),
(s || 'string' == typeof a) &&
0 < n.length &&
0 === n[n.length - 1].openedBraces)
) {
var g = i(a);
e < t.length - 1 &&
('string' == typeof t[e + 1] || 'plain-text' === t[e + 1].type) &&
((g += i(t[e + 1])), t.splice(e + 1, 1)),
0 < e &&
('string' == typeof t[e - 1] || 'plain-text' === t[e - 1].type) &&
((g = i(t[e - 1]) + g), t.splice(e - 1, 1), e--),
(t[e] = new o.Token('plain-text', g, null, g));
}
a.content && 'string' != typeof a.content && r(a.content);
}
};
o.hooks.add('after-tokenize', function (t) {
('jsx' !== t.language && 'tsx' !== t.language) || r(t.tokens);
});
})(Prism);
|