From cdf5677eb9c6ab35d7355c241cfd0c079270c42b Mon Sep 17 00:00:00 2001 From: PesBandi <127593627+PesBandi@users.noreply.github.com> Date: Fri, 14 Jun 2024 17:09:52 +0200 Subject: [PATCH] [Monaco]Improve `.gitignore` definition (#33263) * Update gitignore.js * Update gitignore.js * Add custom color for negations * Add custom color for negations * Regex refactoring * Regex refactoring again * Move customTokenColors to a separate file * Move customTokenColors to a separate file * Update devdocs * Use kebab case for token names * Update negation color * Update index.html formatting --- doc/devdocs/common/FilePreviewCommon.md | 11 ++++- installer/PowerToysSetup/generateFileList.ps1 | 2 +- .../Monaco/customLanguages/gitignore.js | 4 +- .../Assets/Monaco/customTokenColors.js | 3 ++ .../Assets/Monaco/index.html | 45 +++++++++++-------- .../FilePreviewCommon.csproj | 3 ++ 6 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 src/common/FilePreviewCommon/Assets/Monaco/customTokenColors.js diff --git a/doc/devdocs/common/FilePreviewCommon.md b/doc/devdocs/common/FilePreviewCommon.md index 7293e8c978..aee9de2b2a 100644 --- a/doc/devdocs/common/FilePreviewCommon.md +++ b/doc/devdocs/common/FilePreviewCommon.md @@ -47,7 +47,16 @@ registerAdditionalNewLanguage("id", [".fileExtension"], idDefinition(), monaco) * The id can be anything. Recommended is one of the file extensions. For example "php" or "reg". -4. Execute the steps described in the [monaco_languages.json](#monaco_languagesjson) section. +4. In case you wish to add a custom color for a token, you can do so by adding the following line to [`customTokenColors.js`](/src/common/FilePreviewCommon/Assets/Monaco/customTokenColors.js): +```javascript +{token: 'token-name', foreground: 'ff0000'} +``` +> Replace `token-name` with the name of the token and `ff0000` with the hex code of the desired color. +> Note: you can also specify a `background` and a `fontStyle` attribute for your token. + +* Keep in mind that these rules apply to all languages. Therefore, you should not change the colors of any default tokens. Instead, create new tokens specific to the language you are adding. + +5. Execute the steps described in the [monaco_languages.json](#monaco_languagesjson) section. ### Add a new file extension to an existing language diff --git a/installer/PowerToysSetup/generateFileList.ps1 b/installer/PowerToysSetup/generateFileList.ps1 index 9d9fe36c10..f674eae374 100644 --- a/installer/PowerToysSetup/generateFileList.ps1 +++ b/installer/PowerToysSetup/generateFileList.ps1 @@ -21,7 +21,7 @@ $fileWxs = Get-Content $wxsFilePath; $fileExclusionList = @("*.pdb", "*.lastcodeanalysissucceeded", "createdump.exe", "powertoys.exe") -$fileInclusionList = @("*.dll", "*.exe", "*.json", "*.msix", "*.png", "*.gif", "*.ico", "*.cur", "*.svg", "index.html", "reg.js", "gitignore.js", "monacoSpecialLanguages.js", "*.pri") +$fileInclusionList = @("*.dll", "*.exe", "*.json", "*.msix", "*.png", "*.gif", "*.ico", "*.cur", "*.svg", "index.html", "reg.js", "gitignore.js", "monacoSpecialLanguages.js", "customTokenColors.js", "*.pri") $dllsToIgnore = @("System.CodeDom.dll", "WindowsBase.dll") diff --git a/src/common/FilePreviewCommon/Assets/Monaco/customLanguages/gitignore.js b/src/common/FilePreviewCommon/Assets/Monaco/customLanguages/gitignore.js index 365f8f69cc..e4539dd50a 100644 --- a/src/common/FilePreviewCommon/Assets/Monaco/customLanguages/gitignore.js +++ b/src/common/FilePreviewCommon/Assets/Monaco/customLanguages/gitignore.js @@ -5,8 +5,8 @@ tokenizer: { root: [ [/^#.*$/, 'comment'], - [/^\s*!.*/, 'invalid'], - [/^\s*[^#]+/, "tag"] + [/.*((?