prism-code-editor
Version:
Lightweight, extensible code editor component for the web using Prism
71 lines (70 loc) • 3.23 kB
JavaScript
import { a as languages } from "../../core-8vQkh0Rd.js";
import { r as insertBefore, t as clone } from "../../language-D-vtM55V.js";
import { r as replace, t as nested } from "../../shared-BPLAFNn7.js";
import "./markup.js";
import "./csharp.js";
//#region src/prism/languages/cshtml.js
var commentLike = "/(?![/*])|//.*\n|/\\*[^*]*(?:\\*(?!/)[^*]*)*\\*/";
var stringLike = `@(?!")|"(?:[^\\\\\n"]|\\\\.)*"|@"(?:\\\\[^]|[^\\\\"]|"")*"(?!")|'(?:(?:[^\\\\\n']|\\\\.|\\\\[Uux][\a-fA-F\d]{1,8})'|(?=[^\\\\](?!')))`;
var round = nested(replace("\\((?:[^()\"'@/]|<0>|<1>|<self>)*\\)", [stringLike, commentLike]), 2);
var square = nested(replace("\\[(?:[^[\\]\"'@/]|<0>|<1>|<self>)*\\]", [stringLike, commentLike]), 1);
var curly = nested(replace("\\{(?:[^{}\"'@/]|<0>|<1>|<self>)*\\}", [stringLike, commentLike]), 2);
var inlineCs = `@(?:await\\b\\s*)?(?:(?!await\\b)\\w+\\b|${round})(?:[?!]?\\.\\w+\\b|(?:${nested(replace("<(?:[^<>\"'@/]|<0>|<self>)*>", [commentLike]), 1)})?${round}|${square})*(?![?!\\.(\\[]|<(?!\\/))`;
var tagAttrValue = `(?:"[^"@]*"|'[^'@]*'|[^\\s"'@=>]+(?=[\\s>])|["'][^"'@]*(?:(?:${"@(?![()\\w])|" + inlineCs})[^"\'@]*)+["\'])`;
var tagAttrs = `(?:\\s(?:\\s*[^\\s/=>]+(?:\\s*=\\s*${tagAttrValue}|(?=[\\s/>])))+)?`;
var tagContent = `(?!\\d)[^\\s/=>$<%]+${tagAttrs}\\s*\\/?>`;
var tagRegion = `\\B@?(?:<([a-zA-Z][\\w:]*)${tagAttrs}\\s*>(?:[^<]|<\\/?(?!\\1\\b)${tagContent}|${nested(`<\\1${tagAttrs}\\s*>(?:[^<]|<\\/?(?!\\1\\b)${tagContent}|<self>)*<\\/\\1\\s*>`, 2)})*<\\/\\1\\s*>|<${tagContent})`;
var cshtml = languages.razor = languages.cshtml = clone(languages.html);
var csharpWithHtml = clone(languages.cs);
var cs = {
pattern: /\S[^]*/,
alias: "language-csharp",
inside: csharpWithHtml
};
var inlineValue = {
pattern: RegExp("(^|[^@])" + inlineCs, "g"),
lookbehind: true,
alias: "variable",
inside: {
"keyword": /^@/,
"csharp": cs
}
};
var attrValue = cshtml.tag.inside["attr-value"][2];
cshtml.tag.pattern = RegExp("</?" + tagContent, "g");
attrValue.pattern = RegExp("(=\\s*)" + tagAttrValue, "g");
insertBefore(csharpWithHtml, "string", { "html": {
pattern: RegExp(tagRegion, "g"),
inside: cshtml
} });
insertBefore(attrValue.inside, "punctuation", { "value": inlineValue });
insertBefore(cshtml, "prolog", {
"razor-comment": {
pattern: /@\*[^]*?\*@/g,
alias: "comment"
},
"block": {
pattern: RegExp(`(^|[^@])@(?:${curly}|(?:code|functions)\\s*${curly}|(?:for|foreach|lock|switch|using|while)\\s*${round}\\s*${curly}|do\\s*${curly}\\s*while\\s*${round}(?:\\s*;)?|try\\s*${curly}\\s*catch\\s*${round}\\s*${curly}\\s*finally\\s*${curly}|if\\s*${round}\\s*${curly}(?:\\s*else(?:\\s+if\\s*${round})?\\s*${curly})*|helper\\s+\\w+\\s*${round}\\s*${curly})`, "g"),
lookbehind: true,
inside: {
"keyword": /^@\w*/,
"csharp": cs
}
},
"directive": {
pattern: /^([ ]*)@(?:addTagHelper|attribute|implements|inherits|inject|layout|model|namespace|page|preservewhitespace|removeTagHelper|section|tagHelperPrefix|using)(?=\s).*/gm,
lookbehind: true,
inside: {
"keyword": /^@\w+/,
"csharp": cs
}
},
"value": inlineValue,
"delegate-operator": {
pattern: /(^|[^@])@(?=<)/,
lookbehind: true,
alias: "operator"
}
});
//#endregion
//# sourceMappingURL=cshtml.js.map