mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-05 07:07:21 +00:00
Highlighted code blocks inside the app (#1153)
This commit is contained in:
1 parent
0b42c0288e
commit
f4a86c2fb8
60 files changed
+2550
-41
No files matched your search
@@ -0,0 +1,51 @@
|
||||
namespace AIStudio.Tools.CodeHighlighting.Languages;
|
||||
|
||||
/// <summary>
|
||||
/// How JavaScript code looks to the tokenizer, JSX included, whose tags stay plain.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A template literal stays one string, including the expressions within it. A regular expression
|
||||
/// literal stays plain: telling it from a division needs the grammar of the language.
|
||||
/// </remarks>
|
||||
public static class JavaScriptCodeRules
|
||||
{
|
||||
/// <summary>
|
||||
/// The keywords of JavaScript, which TypeScript has, too.
|
||||
/// </summary>
|
||||
internal static readonly string[] KEYWORDS =
|
||||
[
|
||||
"async", "await", "break", "case", "catch", "class", "const", "continue", "debugger", "default", "delete", "do",
|
||||
"else", "export", "extends", "finally", "for", "from", "function", "if", "import", "in", "instanceof", "let",
|
||||
"new", "of", "return", "static", "super", "switch", "this", "throw", "try", "typeof", "var", "void", "while",
|
||||
"with", "yield",
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// The words of JavaScript which stand for a value, which TypeScript has, too.
|
||||
/// </summary>
|
||||
internal static readonly string[] LITERALS = ["true", "false", "null", "undefined", "NaN", "Infinity"];
|
||||
|
||||
/// <summary>
|
||||
/// The strings of JavaScript, which TypeScript has, too.
|
||||
/// </summary>
|
||||
internal static readonly IReadOnlyList<CodeStringRule> STRINGS =
|
||||
[
|
||||
new("`", "`", IsMultiline: true),
|
||||
new("\"", "\""),
|
||||
new("'", "'"),
|
||||
];
|
||||
|
||||
public static readonly CodeLanguageRules RULES = new()
|
||||
{
|
||||
Keywords = CodeLanguageRules.Words(KEYWORDS),
|
||||
Literals = CodeLanguageRules.Words(LITERALS),
|
||||
FunctionDeclarations = CodeLanguageRules.Words("function"),
|
||||
TypeDeclarations = CodeLanguageRules.Words("class"),
|
||||
LineComments = ["//"],
|
||||
BlockComments = [new("/*", "*/")],
|
||||
Strings = STRINGS,
|
||||
AnnotationPrefix = '@',
|
||||
WordStartCharacters = "$",
|
||||
WordCharacters = "$",
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user