Last active
March 5, 2024 22:52
-
-
Save dizys/21db6ec6846e5650a8161152a8c6a8ee to your computer and use it in GitHub Desktop.
Convert VSCode theme JSON to Monaco editor theme JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing ♡