-
|
Beta Was this translation helpful? Give feedback.
Answered by
sharpchen
Dec 10, 2023
Replies: 1 comment 1 reply
-
Do you mean code block in rendered markdown? This is specified by textmate rules from
{
"scope": "comment",
"settings": {
"foreground": "#6A9955",
"fontStyle":"italic" // delete it!
}
},
import * as shikiji from 'shikiji';
import * as fs from 'fs';
// assuming that you have these theme available in somewhere. Then find its path by name.
type CustomMarkdownTheme = 'Eva-Dark' | 'Eva-Light' | 'Rider-Dark' | 'Darcula' | 'vscode-dark-plus';
export async function getRegisteredMarkdownTheme(theme: CustomMarkdownTheme): Promise<shikiji.ThemeRegistration> {
let isThemeRegistered = (await shikiji.getSingletonHighlighter())
.getLoadedThemes() // this method returns names of loaded themes, name is specified in each textmate rule json.
.find(x => x === theme);
if (!isThemeRegistered) {
const myTheme = JSON.parse(
fs.readFileSync(/* find the path of your json */), 'utf8')
);
(await shikiji.getSingletonHighlighter()).loadTheme(myTheme);
}
return (await shikiji.getSingletonHighlighter()).getTheme(theme);
}
// config.mts
export default defineConfig({
markdown: {
lineNumbers: true,
theme: {
light: await getRegisteredMarkdownTheme('Eva-Light'),
dark: await getRegisteredMarkdownTheme('vscode-dark-plus'),
},
},...
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
gyhyfj
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you mean code block in rendered markdown?
This is specified by textmate rules from
xx.json
. Vitepress usesshikiji
to perform highlighting(built-in themes are also fromshikiji
). This is my solution.shikiji
you can find them innode_modules\shikiji\dist\themes\*.mjs
. The anon object in the module is the presentation of the theme. No matter what method you take, make it a json and include it in your project."scope": "comment"
in your json like this, add or change thefontStyle
. (To make it normal, delete thefontStyle
property)