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

Fixed shiki import to work with "type": "module" #2628

Merged
merged 5 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/great-hotels-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'astro': patch
'@astrojs/markdown-remark': patch
---

Fixed shiki to work with `{ "type": "module" }`
7 changes: 4 additions & 3 deletions packages/astro/components/Code.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import shiki from 'shiki';
import type * as shiki from 'shiki';
import { getHighlighter } from 'shiki';

export interface Props {
/** The code to highlight. Required. */
Expand Down Expand Up @@ -49,10 +50,10 @@ function repairShikiTheme(html: string): string {
return html;
}

const highlighter = await shiki.getHighlighter({
const highlighter = await getHighlighter({
theme,
// Load custom lang if passed an object, otherwise load the default
langs: typeof lang !== 'string' ? [lang] : undefined
langs: typeof lang !== 'string' ? [lang] : undefined,
});
const _html = highlighter.codeToHtml(code, { lang: typeof lang === 'string' ? lang : lang.id });
const html = repairShikiTheme(_html);
Expand Down
5 changes: 3 additions & 2 deletions packages/markdown/remark/src/remark-shiki.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import shiki from 'shiki';
import type * as shiki from 'shiki';
import { getHighlighter } from 'shiki';
import { visit } from 'unist-util-visit';

export interface ShikiConfig {
Expand Down Expand Up @@ -30,7 +31,7 @@ export interface ShikiConfig {
}

const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }: ShikiConfig) => {
const highlighter = await shiki.getHighlighter({ theme });
const highlighter = await getHighlighter({ theme });

for (const lang of langs) {
await highlighter.loadLanguage(lang);
Expand Down