[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
This commit is contained in:
Родитель
50b1342234
Коммит
35b9bcacdb
|
@ -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'}
|
||||
```
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
<!-- Include Monaco Editor source code -->
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<None Include="$(MSBuildThisFileDirectory)\Monaco\customTokenColors.js">
|
||||
<Link>Assets\Monaco\customTokenColors.js</Link>
|
||||
<None Include="$(MSBuildThisFileDirectory)\Monaco\customTokenThemeRules.js">
|
||||
<Link>Assets\Monaco\customTokenThemeRules.js</Link>
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="$(MSBuildThisFileDirectory)\Monaco\monacoSpecialLanguages.js">
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
root: [
|
||||
[/^#.*$/, 'comment'],
|
||||
[/.*((?<!(^|\/))\*\*.*|\*\*(?!(\/|$))).*/, 'invalid'],
|
||||
[/((?:^!\s*(?:\\\s|\S)+)?)((?:^\s*(?:\\\s|\S)+)?)((?:\s+(?:\\\s|\S)+)*)/, ['custom-gitignore.negation', 'tag', 'invalid']]
|
||||
[/((?:^!\s*(?:\\\s|\S)+)?)((?:^\s*(?:\\\s|\S)+)?)((?:\s+(?:\\\s|\S)+)*)/, ['custom-negation', 'tag', 'invalid']]
|
||||
]
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
export function srtDefinition() {
|
||||
return {
|
||||
tokenizer: {
|
||||
root: [
|
||||
[/\s*\d+/, 'number', '@block']
|
||||
],
|
||||
|
||||
block: [
|
||||
[/^\d{2}:\d{2}:\d{2},\d{3} --> \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']
|
||||
]
|
||||
}
|
||||
};
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
export const customTokenColors = [
|
||||
{token: 'custom-gitignore.negation', foreground: 'c00ce0'}
|
||||
];
|
|
@ -0,0 +1,3 @@
|
|||
export const customTokenThemeRules = [
|
||||
{token: 'custom-negation.gitignore', foreground: 'c00ce0'}
|
||||
];
|
|
@ -79,7 +79,7 @@
|
|||
<script src="http://[[PT_URL]]/monacoSpecialLanguages.js" type="module"></script>
|
||||
<script type="module">
|
||||
import { registerAdditionalLanguages } from 'http://[[PT_URL]]/monacoSpecialLanguages.js';
|
||||
import { customTokenColors } from 'http://[[PT_URL]]/customTokenColors.js';
|
||||
import { customTokenThemeRules } from 'http://[[PT_URL]]/customTokenThemeRules.js';
|
||||
require.config({ paths: { vs: 'http://[[PT_URL]]/monacoSRC/min/vs' } });
|
||||
require(['vs/editor/editor.main'], async function () {
|
||||
await registerAdditionalLanguages(monaco)
|
||||
|
@ -88,7 +88,7 @@
|
|||
monaco.editor.defineTheme('theme', {
|
||||
base: theme, // Sets the base theme to "vs" or "vs-dark" depending on the user's preference
|
||||
inherit: true,
|
||||
rules: customTokenColors,
|
||||
rules: customTokenThemeRules,
|
||||
colors: {} // `colors` is a required attribute
|
||||
});
|
||||
|
||||
|
|
|
@ -2,18 +2,20 @@
|
|||
|
||||
import { regDefinition } from './customLanguages/reg.js';
|
||||
import { gitignoreDefinition } from './customLanguages/gitignore.js';
|
||||
import { srtDefinition } from './customLanguages/srt.js';
|
||||
|
||||
export async function registerAdditionalLanguages(monaco){
|
||||
await languageDefinitions();
|
||||
registerAdditionalLanguage("cppExt", [".ino", ".pde"], "cpp", monaco)
|
||||
registerAdditionalLanguage("xmlExt", [".wsdl", ".csproj", ".vcxproj", ".vbproj", ".fsproj"], "xml", monaco)
|
||||
registerAdditionalLanguage("txtExt", [".sln", ".log", ".vsconfig", ".env", ".srt", ".ahk", ".ion"], "txt", monaco)
|
||||
registerAdditionalLanguage("razorExt", [".razor"], "razor", monaco)
|
||||
registerAdditionalLanguage("vbExt", [".vbs"], "vb", monaco)
|
||||
registerAdditionalLanguage("iniExt", [".inf", ".gitconfig", ".gitattributes", ".editorconfig"], "ini", monaco)
|
||||
registerAdditionalLanguage("shellExt", [".ksh", ".zsh", ".bsh"], "shell", monaco)
|
||||
registerAdditionalNewLanguage("reg", [".reg"], regDefinition(), monaco)
|
||||
registerAdditionalNewLanguage("gitignore", [".gitignore"], gitignoreDefinition(), monaco)
|
||||
registerAdditionalLanguage("cppExt", [".ino", ".pde"], "cpp", monaco);
|
||||
registerAdditionalLanguage("xmlExt", [".wsdl", ".csproj", ".vcxproj", ".vbproj", ".fsproj"], "xml", monaco);
|
||||
registerAdditionalLanguage("txtExt", [".sln", ".log", ".vsconfig", ".env", ".ahk", ".ion"], "txt", monaco);
|
||||
registerAdditionalLanguage("razorExt", [".razor"], "razor", monaco);
|
||||
registerAdditionalLanguage("vbExt", [".vbs"], "vb", monaco);
|
||||
registerAdditionalLanguage("iniExt", [".inf", ".gitconfig", ".gitattributes", ".editorconfig"], "ini", monaco);
|
||||
registerAdditionalLanguage("shellExt", [".ksh", ".zsh", ".bsh"], "shell", monaco);
|
||||
registerAdditionalNewLanguage("reg", [".reg"], regDefinition(), monaco);
|
||||
registerAdditionalNewLanguage("gitignore", [".gitignore"], gitignoreDefinition(), monaco);
|
||||
registerAdditionalNewLanguage("srt", [".srt"], srtDefinition(), monaco);
|
||||
}
|
||||
|
||||
// Language definitions taken from Monaco source code
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -36,7 +36,7 @@
|
|||
<script src="http://PowerToysLocalMonaco/monacoSRC/min/vs/loader.js"></script>
|
||||
<script type="module">
|
||||
import { registerAdditionalLanguages } from 'http://PowerToysLocalMonaco/monacoSpecialLanguages.js';
|
||||
import { customTokenColors } from 'http://PowerToysLocalMonaco/customTokenColors.js';
|
||||
import { customTokenThemeRules } from 'http://PowerToysLocalMonaco/customTokenThemeRules.js';
|
||||
require.config({ paths: { vs: 'http://PowerToysLocalMonaco/monacoSRC/min/vs' } });
|
||||
require(['vs/editor/editor.main'], async function () {
|
||||
await registerAdditionalLanguages(monaco)
|
||||
|
|
Загрузка…
Ссылка в новой задаче