diff options
author | 2023-05-03 23:07:57 +0800 | |
---|---|---|
committer | 2023-05-03 11:07:57 -0400 | |
commit | 49514e4ce40fedb39bf7decd2c296258efbdafc7 (patch) | |
tree | 49bf68d5af0f1d36374040dd820ec5f6cd8e3ef3 /packages/markdown/remark/src | |
parent | 297a1dae51962bde7a66cc3a4062ff23b64412bc (diff) | |
download | astro-49514e4ce40fedb39bf7decd2c296258efbdafc7.tar.gz astro-49514e4ce40fedb39bf7decd2c296258efbdafc7.tar.zst astro-49514e4ce40fedb39bf7decd2c296258efbdafc7.zip |
Upgrade shiki to v0.14.1 (#6932)
* Upgrade shiki
* Update themes
* Update languages
* Simplify
* Fix compat for other remark code
* Update theme again
* Fix language gen
* Add changeset
* Fix code
* Update test theme colors
* Update changeset
* Fix test again
Diffstat (limited to 'packages/markdown/remark/src')
-rw-r--r-- | packages/markdown/remark/src/remark-shiki.ts | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/packages/markdown/remark/src/remark-shiki.ts b/packages/markdown/remark/src/remark-shiki.ts index ad7c982f9..8035635f9 100644 --- a/packages/markdown/remark/src/remark-shiki.ts +++ b/packages/markdown/remark/src/remark-shiki.ts @@ -10,10 +10,30 @@ import type { ShikiConfig } from './types.js'; */ const highlighterCacheAsync = new Map<string, Promise<shiki.Highlighter>>(); +// Map of old theme names to new names to preserve compatibility when we upgrade shiki +const compatThemes: Record<string, string> = { + 'material-darker': 'material-theme-darker', + 'material-default': 'material-theme', + 'material-lighter': 'material-theme-lighter', + 'material-ocean': 'material-theme-ocean', + 'material-palenight': 'material-theme-palenight', +}; + +const normalizeTheme = (theme: string | shiki.IShikiTheme) => { + if (typeof theme === 'string') { + return compatThemes[theme] || theme; + } else if (compatThemes[theme.name]) { + return { ...theme, name: compatThemes[theme.name] }; + } else { + return theme; + } +}; + const remarkShiki = async ( { langs = [], theme = 'github-dark', wrap = false }: ShikiConfig, scopedClassName?: string | null ) => { + theme = normalizeTheme(theme); const cacheID: string = typeof theme === 'string' ? theme : theme.name; let highlighterAsync = highlighterCacheAsync.get(cacheID); if (!highlighterAsync) { |