chore: Ensure dark theme codeblock are not set to italic #5

Merged
sheetjs merged 1 commits from chore/dark-theme-codeblock-font-style into master 2024-03-14 08:23:33 +00:00
Showing only changes of commit e6308dac88 - Show all commits

@ -1,6 +1,28 @@
// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion
/** @typedef { import('prism-react-renderer').PrismTheme['styles'] } PrismThemeStyle */
/** @typedef { import('prism-react-renderer').PrismTheme['styles'][number]['style'] } PrismThemeEntry */
/**
Updates styles array from prisma theme based off token type
@type {(theme: PrismThemeStyle, replace: Record<string, PrismThemeEntry>) => PrismThemeStyle}
*/
const updateThemeStyles = (styles, replace) => {
const copy = structuredClone(styles)
const types = Object.keys(replace)
copy.forEach(style => {
types.forEach((type) => {
if (style.types.includes(type)) {
style.style = { ...style.style, ...replace[type]}
}
})
})
return copy
}
const lightCodeTheme = require('prism-react-renderer/themes/github');
const darkCodeTheme = require('prism-react-renderer/themes/dracula');
@ -145,7 +167,19 @@ const config = {
},
prism: {
theme: lightCodeTheme,
darkTheme: darkCodeTheme,
darkTheme: {
// Dracula dark theme by default has keyword and variable font style set to italic
// reset to normal to be consistent with the light theme (github)
...darkCodeTheme,
styles: updateThemeStyles(/** @type {any} */ (darkCodeTheme.styles), {
'keyword': {
fontStyle: "normal"
},
'variable': {
fontStyle: "normal"
}
})
},
additionalLanguages: [ "visual-basic", "swift", "java", "php", "csharp", "perl", "ruby", "cpp", "applescript", "liquid", "rust", "dart", "wolfram", "matlab", "stata", "zig" ],
},
liveCodeBlock: {