doc/devdocs/common/FilePreviewCommon.md
This project contains common code used for previewing and displaying files.
Monaco preview enables to display developer files. It is based on Microsoft's Monaco Editor which is maintained by the Visual Studio Code team.
This previewer is used for the File Explorer Dev File Previewer, as well as PowerToys Peek.
For a general overview of how Monaco is used in PowerToys, see the Monaco Editor documentation.
npm i monaco-editor in the command prompt.min folder (the minimised code) from the downloaded files.min folder into the /src/Monaco/monacoSRC folder of the PowerToys project.As an example on how to add a new language definition you can look at the one for registry files.
idDefinition to the name of your language.)export function idDefinition() {
return {
...
}
}
monacoSpecialLanguages.js file, after the other import statements:import { idDefinition } from './customLanguages/file.js';
Replace file.js with the name of your definition file from step 1. Please replace idDefinition with the string you used in step 1.
monacoSpecialLanguages.js file add the following line into the registerAdditionalLanguages function:registerAdditionalNewLanguage("id", [".fileExtension"], idDefinition(), monaco)
Replace id and idDefinition with your id and string used in step 1. Replace fileExtension with a set of file extensions you want the language to register to.
customTokenThemeRules.js:{token: 'token-name', foreground: 'ff0000'}
Replace
token-namewith the name of the token andff0000with the hex code of the desired color. Note: you can also specify abackgroundand afontStyleattribute for your token.
monacoSpecialLanguages.js file add the following line to the registerAdditionalLanguages function. (existingId is the id of the language you want to add the extension to. You can find these id's in the monaco_languages.json file):registerAdditionalLanguage("id", [".fileExtension"], "existingId", monaco)
phpExt and the existingId to php.Copy the existing language definition into the languageDefinitions function in the same file. You can find the existing definitions in the following folder: /src/Monaco/monacoSRC/min/vs/basic-languages/.
Execute the steps described in the monaco_languages.json section.
monaco_languages.json contains all extensions and IDs for the languages supported by Monaco. The MonacoHelper class and the installer are using this file to register preview handlers for the defined extensions.
After updating Monaco Editor and/or adding a new language you should update the monaco_languages.json file.
generateLanguagesJson.html file on a local webserver (as webbrowsers will block certain needed features when running the file locally.)vscode-preview-server: Launch on browser. The file will be opened in a browser.monaco_languages.json file