Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FilePreview] Use syntax highlighting for .srt #35651

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/devdocs/common/FilePreviewCommon.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
```
Expand Down
2 changes: 1 addition & 1 deletion installer/PowerToysSetup/generateAllFileComponents.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions src/Monaco.props
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
2 changes: 1 addition & 1 deletion src/Monaco/customLanguages/gitignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']]
PesBandi marked this conversation as resolved.
Show resolved Hide resolved
]
}
};
Expand Down
44 changes: 44 additions & 0 deletions src/Monaco/customLanguages/srt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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}/, 'tag', '@subtitle'],
[/^$/, 'string', '@pop']
],

tags: [
[/^$/, 'string', '@popall'],
[/<b>/, 'string.bold', '@bold'],
[/<i>/, 'string.emphasis', '@italic'],
[/<u>/, 'string.underline', '@underline']
],

subtitle: [
{include: '@tags'},
[/./, 'string']
],

bold: [
[/<\/b>/, 'string.bold', '@pop'],
{include: '@tags'},
[/./, 'string.bold'],
],

italic: [
[/<\/i>/, 'string.emphasis', '@pop'],
{include: '@tags'},
[/./, 'string.emphasis'],
],

underline: [
[/<\/u>/, 'string.underline', '@pop'],
{include: '@tags'},
[/./, 'string.underline'],
],
}
};
}
3 changes: 0 additions & 3 deletions src/Monaco/customTokenColors.js

This file was deleted.

6 changes: 6 additions & 0 deletions src/Monaco/customTokenThemeRules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const customTokenThemeRules = [
{token: 'custom-negation.gitignore', foreground: 'c00ce0'},
{token: 'string.bold', fontStyle: 'bold'},
{token: 'string.emphasis', fontStyle: 'italic'},
{token: 'string.underline', fontStyle: 'underline'}
PesBandi marked this conversation as resolved.
Show resolved Hide resolved
];
4 changes: 2 additions & 2 deletions src/Monaco/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
});

Expand Down
20 changes: 11 additions & 9 deletions src/Monaco/monacoSpecialLanguages.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Monaco/monaco_languages.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading