aboutsummaryrefslogtreecommitdiffstats
path: root/public/prism/prism-cshtml.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-cshtml.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-cshtml.min.js')
-rw-r--r--public/prism/prism-cshtml.min.js186
1 files changed, 101 insertions, 85 deletions
diff --git a/public/prism/prism-cshtml.min.js b/public/prism/prism-cshtml.min.js
index 0ca0caf..25d1059 100644
--- a/public/prism/prism-cshtml.min.js
+++ b/public/prism/prism-cshtml.min.js
@@ -8,8 +8,7 @@
.replace(/<self>/g, '[^\\s\\S]')
.replace(
/<str>/g,
- '(?:@(?!")|"(?:[^\r\n\\\\"]|\\\\.)*"|@"(?:[^\\\\"]|""|\\\\[^])*"(?!")|' +
- "'(?:(?:[^\r\n'\\\\]|\\\\.|\\\\[Uux][\\da-fA-F]{1,8})'|(?=[^\\\\](?!'))))"
+ '(?:@(?!")|"(?:[^\r\n\\\\"]|\\\\.)*"|@"(?:[^\\\\"]|""|\\\\[^])*"(?!")|\'(?:(?:[^\r\n\'\\\\]|\\\\.|\\\\[Uux][\\da-fA-F]{1,8})\'|(?=[^\\\\](?!\'))))'
)
.replace(
/<comment>/g,
@@ -17,104 +16,121 @@
);
}
var a = s('\\((?:[^()\'"@/]|<str>|<comment>|<self>)*\\)', 2),
- r = s('\\[(?:[^\\[\\]\'"@/]|<str>|<comment>|<self>)*\\]', 2),
- t = s('\\{(?:[^{}\'"@/]|<str>|<comment>|<self>)*\\}', 2),
- n = s('<(?:[^<>\'"@/]|<str>|<comment>|<self>)*>', 2),
+ t = s('\\[(?:[^\\[\\]\'"@/]|<str>|<comment>|<self>)*\\]', 1),
+ r = s('\\{(?:[^{}\'"@/]|<str>|<comment>|<self>)*\\}', 2),
+ n =
+ '@(?:await\\b\\s*)?(?:(?!await\\b)\\w+\\b|' +
+ a +
+ ')(?:[?!]?\\.\\w+\\b|(?:' +
+ s('<(?:[^<>\'"@/]|<comment>|<self>)*>', 1) +
+ ')?' +
+ a +
+ '|' +
+ t +
+ ')*(?![?!\\.(\\[]|<(?!/))',
l =
- '(?:\\s(?:\\s*[^\\s>/=]+(?:\\s*=\\s*(?:"[^"]*"|\'[^\']*\'|[^\\s\'">=]+(?=[\\s>]))|(?=[\\s/>])))+)?',
- i = '(?!\\d)[^\\s>/=$<%]+' + l + '\\s*/?>',
+ '(?:"[^"@]*"|\'[^\'@]*\'|[^\\s\'"@>=]+(?=[\\s>])|["\'][^"\'@]*(?:(?:@(?![\\w()])|' +
+ n +
+ ')[^"\'@]*)+["\'])',
+ i =
+ '(?:\\s(?:\\s*[^\\s>/=]+(?:\\s*=\\s*<tagAttrValue>|(?=[\\s/>])))+)?'.replace(
+ /<tagAttrValue>/,
+ l
+ ),
+ g = '(?!\\d)[^\\s>/=$<%]+' + i + '\\s*/?>',
o =
'\\B@?(?:<([a-zA-Z][\\w:]*)' +
- l +
- '\\s*>(?:[^<]|</?(?!\\1\\b)' +
i +
+ '\\s*>(?:[^<]|</?(?!\\1\\b)' +
+ g +
'|' +
s(
- '<\\1' + l + '\\s*>(?:[^<]|</?(?!\\1\\b)' + i + '|<self>)*</\\1\\s*>',
+ '<\\1' + i + '\\s*>(?:[^<]|</?(?!\\1\\b)' + g + '|<self>)*</\\1\\s*>',
2
) +
')*</\\1\\s*>|<' +
- i +
+ g +
')';
e.languages.cshtml = e.languages.extend('markup', {});
- var g = {
- pattern: /\S[\s\S]*/,
- alias: 'language-csharp',
- inside: e.languages.insertBefore(
- 'csharp',
- 'string',
- { html: { pattern: RegExp(o), greedy: !0, inside: e.languages.cshtml } },
- { csharp: e.languages.extend('csharp', {}) }
- ),
- };
- e.languages.insertBefore('cshtml', 'prolog', {
- 'razor-comment': {
- pattern: /@\*[\s\S]*?\*@/,
- greedy: !0,
- alias: 'comment',
- },
- block: {
- pattern: RegExp(
- '(^|[^@])@(?:' +
- [
- t,
- '(?:code|functions)\\s*' + t,
- '(?:for|foreach|lock|switch|using|while)\\s*' + a + '\\s*' + t,
- 'do\\s*' + t + '\\s*while\\s*' + a + '(?:\\s*;)?',
- 'try\\s*' +
- t +
- '\\s*catch\\s*' +
- a +
- '\\s*' +
- t +
- '\\s*finally\\s*' +
- t,
- 'if\\s*' +
- a +
- '\\s*' +
- t +
- '(?:\\s*else(?:\\s+if\\s*' +
- a +
- ')?\\s*' +
- t +
- ')*',
- ].join('|') +
- ')'
+ var c = {
+ pattern: /\S[\s\S]*/,
+ alias: 'language-csharp',
+ inside: e.languages.insertBefore(
+ 'csharp',
+ 'string',
+ {
+ html: { pattern: RegExp(o), greedy: !0, inside: e.languages.cshtml },
+ },
+ { csharp: e.languages.extend('csharp', {}) }
),
- lookbehind: !0,
- greedy: !0,
- inside: { keyword: /^@\w*/, csharp: g },
},
- directive: {
- pattern:
- /^([ \t]*)@(?:addTagHelper|attribute|implements|inherits|inject|layout|model|namespace|page|preservewhitespace|removeTagHelper|section|tagHelperPrefix|using)(?=\s).*/m,
- lookbehind: !0,
- greedy: !0,
- inside: { keyword: /^@\w+/, csharp: g },
- },
- value: {
- pattern: RegExp(
- '(^|[^@])@(?:await\\b\\s*)?(?:\\w+\\b|' +
- a +
- ')(?:[?!]?\\.\\w+\\b|' +
- a +
- '|' +
- r +
- '|' +
- n +
- a +
- ')*'
- ),
+ p = {
+ pattern: RegExp('(^|[^@])' + n),
lookbehind: !0,
greedy: !0,
alias: 'variable',
- inside: { keyword: /^@/, csharp: g },
- },
- 'delegate-operator': {
- pattern: /(^|[^@])@(?=<)/,
- lookbehind: !0,
- alias: 'operator',
- },
- }),
+ inside: { keyword: /^@/, csharp: c },
+ };
+ (e.languages.cshtml.tag.pattern = RegExp('</?' + g)),
+ (e.languages.cshtml.tag.inside['attr-value'].pattern = RegExp('=\\s*' + l)),
+ e.languages.insertBefore(
+ 'inside',
+ 'punctuation',
+ { value: p },
+ e.languages.cshtml.tag.inside['attr-value']
+ ),
+ e.languages.insertBefore('cshtml', 'prolog', {
+ 'razor-comment': {
+ pattern: /@\*[\s\S]*?\*@/,
+ greedy: !0,
+ alias: 'comment',
+ },
+ block: {
+ pattern: RegExp(
+ '(^|[^@])@(?:' +
+ [
+ r,
+ '(?:code|functions)\\s*' + r,
+ '(?:for|foreach|lock|switch|using|while)\\s*' + a + '\\s*' + r,
+ 'do\\s*' + r + '\\s*while\\s*' + a + '(?:\\s*;)?',
+ 'try\\s*' +
+ r +
+ '\\s*catch\\s*' +
+ a +
+ '\\s*' +
+ r +
+ '\\s*finally\\s*' +
+ r,
+ 'if\\s*' +
+ a +
+ '\\s*' +
+ r +
+ '(?:\\s*else(?:\\s+if\\s*' +
+ a +
+ ')?\\s*' +
+ r +
+ ')*',
+ 'helper\\s+\\w+\\s*' + a + '\\s*' + r,
+ ].join('|') +
+ ')'
+ ),
+ lookbehind: !0,
+ greedy: !0,
+ inside: { keyword: /^@\w*/, csharp: c },
+ },
+ directive: {
+ pattern:
+ /^([ \t]*)@(?:addTagHelper|attribute|implements|inherits|inject|layout|model|namespace|page|preservewhitespace|removeTagHelper|section|tagHelperPrefix|using)(?=\s).*/m,
+ lookbehind: !0,
+ greedy: !0,
+ inside: { keyword: /^@\w+/, csharp: c },
+ },
+ value: p,
+ 'delegate-operator': {
+ pattern: /(^|[^@])@(?=<)/,
+ lookbehind: !0,
+ alias: 'operator',
+ },
+ }),
(e.languages.razor = e.languages.cshtml);
})(Prism);