From 35b9bcacdb34371f4f66360c4be74d5c4f859d81 Mon Sep 17 00:00:00 2001 From: PesBandi <127593627+PesBandi@users.noreply.github.com> Date: Tue, 3 Dec 2024 18:25:35 +0100 Subject: [PATCH] [Monaco] Use syntax highlighting for `.srt` (#35651) * [FilePreview] Use syntax highlighting for .srt * Change customTokenColors to customTokenThemeRules * Ignore text on the same line as a timestamp * Update tokenization rules --- doc/devdocs/common/FilePreviewCommon.md | 2 +- .../generateAllFileComponents.ps1 | 2 +- src/Monaco.props | 4 +-- src/Monaco/customLanguages/gitignore.js | 2 +- src/Monaco/customLanguages/srt.js | 29 +++++++++++++++++++ src/Monaco/customTokenColors.js | 3 -- src/Monaco/customTokenThemeRules.js | 3 ++ src/Monaco/index.html | 4 +-- src/Monaco/monacoSpecialLanguages.js | 20 +++++++------ src/Monaco/monaco_languages.json | 2 +- .../Assets/RegistryPreview/index.html | 2 +- 11 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 src/Monaco/customLanguages/srt.js delete mode 100644 src/Monaco/customTokenColors.js create mode 100644 src/Monaco/customTokenThemeRules.js diff --git a/doc/devdocs/common/FilePreviewCommon.md b/doc/devdocs/common/FilePreviewCommon.md index 85b74ca7e7..33c11aad28 100644 --- a/doc/devdocs/common/FilePreviewCommon.md +++ b/doc/devdocs/common/FilePreviewCommon.md @@ -47,7 +47,7 @@ registerAdditionalNewLanguage("id", [".fileExtension"], idDefinition(), monaco) * The id can be anything. Recommended is one of the file extensions. For example "php" or "reg". -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/Monaco/customTokenColors.js): +4. In case you wish to add a custom color for a token, you can do so by adding the following line to [`customTokenThemeRules.js`](/src/Monaco/customTokenThemeRules.js): ```javascript {token: 'token-name', foreground: 'ff0000'} ``` diff --git a/installer/PowerToysSetup/generateAllFileComponents.ps1 b/installer/PowerToysSetup/generateAllFileComponents.ps1 index 50ce0f2dd6..3592b14362 100644 --- a/installer/PowerToysSetup/generateAllFileComponents.ps1 +++ b/installer/PowerToysSetup/generateAllFileComponents.ps1 @@ -30,7 +30,7 @@ Function Generate-FileList() { $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", "customTokenColors.js", "*.pri") + $fileInclusionList = @("*.dll", "*.exe", "*.json", "*.msix", "*.png", "*.gif", "*.ico", "*.cur", "*.svg", "index.html", "reg.js", "gitignore.js", "srt.js", "monacoSpecialLanguages.js", "customTokenThemeRules.js", "*.pri") $dllsToIgnore = @("System.CodeDom.dll", "WindowsBase.dll") diff --git a/src/Monaco.props b/src/Monaco.props index 0aeef121e2..471772823d 100644 --- a/src/Monaco.props +++ b/src/Monaco.props @@ -2,8 +2,8 @@ - - Assets\Monaco\customTokenColors.js + + Assets\Monaco\customTokenThemeRules.js Always diff --git a/src/Monaco/customLanguages/gitignore.js b/src/Monaco/customLanguages/gitignore.js index e4539dd50a..8b5d393993 100644 --- a/src/Monaco/customLanguages/gitignore.js +++ b/src/Monaco/customLanguages/gitignore.js @@ -6,7 +6,7 @@ root: [ [/^#.*$/, 'comment'], [/.*((? \d{2}:\d{2}:\d{2},\d{3}/, { + cases: { + '@eos': {token: 'type.identifier', next: '@subtitle'}, + '@default': {token: 'type.identifier', next: '@ignore'} + } + }], + [/^$/, 'string', '@pop'] + ], + + ignore: [ + [/.+$/, '', '@subtitle'] + ], + + subtitle: [ + [/^$/, 'string', '@popall'], + [/<\/?(?:[ibu]|font(?:\s+color="[^"]+"\s*)?)>/, 'tag'], + [/./, 'string'] + ] + } + }; +} \ No newline at end of file diff --git a/src/Monaco/customTokenColors.js b/src/Monaco/customTokenColors.js deleted file mode 100644 index aa20d58d42..0000000000 --- a/src/Monaco/customTokenColors.js +++ /dev/null @@ -1,3 +0,0 @@ -export const customTokenColors = [ - {token: 'custom-gitignore.negation', foreground: 'c00ce0'} -]; \ No newline at end of file diff --git a/src/Monaco/customTokenThemeRules.js b/src/Monaco/customTokenThemeRules.js new file mode 100644 index 0000000000..cbba1b1f39 --- /dev/null +++ b/src/Monaco/customTokenThemeRules.js @@ -0,0 +1,3 @@ +export const customTokenThemeRules = [ + {token: 'custom-negation.gitignore', foreground: 'c00ce0'} +]; \ No newline at end of file diff --git a/src/Monaco/index.html b/src/Monaco/index.html index 1888cdac39..020c4c3c33 100644 --- a/src/Monaco/index.html +++ b/src/Monaco/index.html @@ -79,7 +79,7 @@