Skip to content

Instantly share code, notes, and snippets.

@dizys
Last active March 5, 2024 22:52
Show Gist options
  • Save dizys/21db6ec6846e5650a8161152a8c6a8ee to your computer and use it in GitHub Desktop.
Save dizys/21db6ec6846e5650a8161152a8c6a8ee to your computer and use it in GitHub Desktop.
Convert VSCode theme JSON to Monaco editor theme JSON
// Taken from https://github.com/Nishkalkashyap/monaco-vscode-textmate-theme-converter/blob/master/src/index.ts
const input = {
// ...vscode theme json
};
function convertTheme(theme) {
const monacoThemeRule = [];
const returnTheme = {
inherit: false,
base: "vs-dark",
colors: theme.colors,
rules: monacoThemeRule,
encodedTokensColors: [],
};
theme.tokenColors.map((color) => {
if (typeof color.scope == "string") {
const split = color.scope.split(",");
if (split.length > 1) {
color.scope = split;
evalAsArray();
return;
}
monacoThemeRule.push(
Object.assign({}, color.settings, {
// token: color.scope.replace(/\s/g, '')
token: color.scope,
})
);
return;
}
evalAsArray();
function evalAsArray() {
color.scope.map((scope) => {
monacoThemeRule.push(
Object.assign({}, color.settings, {
token: scope,
})
);
});
}
});
return returnTheme;
}
let output = convertTheme(input)
console.log(JSON.stringify(output, undefined, 2))
@skittlesaur
Copy link

Thanks for sharing ♡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment