Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't Load custom theme.json with Shikiji #1258

Closed
alvarosabu opened this issue Jan 26, 2024 · 4 comments
Closed

Can't Load custom theme.json with Shikiji #1258

alvarosabu opened this issue Jan 26, 2024 · 4 comments

Comments

@alvarosabu
Copy link
Contributor

Describe the bug
Hi, when I try to load my custom theme.json that I used for shiki before:

import { defineShikijiSetup } from '@slidev/types'

const myTheme = JSON.parse(fs.readFileSync('setup/theme/penguin-theme.json', 'utf8'))

export default defineShikijiSetup(() => ({
  theme: myTheme,
}))

It throws an error:

file:///Users/alvarosabu/Projects/alvarosabu/talks/slidev-theme-penguin/node_modules/.pnpm/shikiji-core@0.9.19/node_modules/shikiji-core/dist/index.mjs:5030
                    throw new Error(`[shikiji] Theme \`${theme}\` is not built-in.`);
                          ^

Error: [shikiji] Theme `theme-penguin` is not built-in.
    at resolveTheme (file:///Users/alvarosabu/Projects/alvarosabu/talks/slidev-theme-penguin/node_modules/.pnpm/shikiji-core@0.9.19/node_modules/shikiji-core/dist/index.mjs:5030:27)
    at file:///Users/alvarosabu/Projects/alvarosabu/talks/slidev-theme-penguin/node_modules/.pnpm/shikiji-core@0.9.19/node_modules/shikiji-core/dist/index.mjs:5035:57
    at Array.map (<anonymous>)
    at getHighlighter (file:///Users/alvarosabu/Projects/alvarosabu/talks/slidev-theme-penguin/node_modules/.pnpm/shikiji-core@0.9.19/node_modules/shikiji-core/dist/index.mjs:5035:48)

Is it currently possible to load custom themes? Thanks

To Reproduce
Steps to reproduce the behavior:

  1. npm run dev

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: None
  • Slidev version: v0.46.3
@antfu
Copy link
Member

antfu commented Jan 26, 2024

Can you share a minimal repro? Thanks

@alvarosabu
Copy link
Contributor Author

@antfu antfu closed this as completed in d8dd15f Jan 26, 2024
@antfu
Copy link
Member

antfu commented Jan 26, 2024

Before the release, here is the workaround:

import fs from 'node:fs';

/* ./setup/shiki.ts */

import { defineShikijiSetup } from '@slidev/types';

const myTheme = JSON.parse(
  fs.readFileSync('setup/theme/penguin-theme.json', 'utf8')
);

export default defineShikijiSetup(() => ({
  themes: { default: myTheme },
  defaultColor: 'default',
}));

@alvarosabu
Copy link
Contributor Author

Thanks @antfu that was extremely quick 🙏🏻

openscript pushed a commit to openscript/slidev that referenced this issue Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants