summaryrefslogtreecommitdiff
path: root/packages/integrations/markdoc/src/extensions/shiki.ts
diff options
context:
space:
mode:
authorGravatar Ben Holmes <hey@bholmes.dev> 2023-05-25 11:35:07 -0400
committerGravatar GitHub <noreply@github.com> 2023-05-25 11:35:07 -0400
commit16b836411980f18c58ca15712d92cec1b3c95670 (patch)
treecbcd2443815e225cff53ad1d4a94477bfc367f5a /packages/integrations/markdoc/src/extensions/shiki.ts
parent223e0131fcd3cfc83575ab9860eb2648b7240b35 (diff)
downloadastro-16b836411980f18c58ca15712d92cec1b3c95670.tar.gz
astro-16b836411980f18c58ca15712d92cec1b3c95670.tar.zst
astro-16b836411980f18c58ca15712d92cec1b3c95670.zip
Markdoc - improve syntax highlighting support (#7209)
* feat: prism and shiki support, with better exports! * chore: update tests * chore: fix lock * chore: add prism test * chore: remove `async` from prism * docs: update syntax highlight readme * chore: changeset * edit: remove `await` from prism docs * chore: update old changest with new shiki instructions * fix: add trailing newline on ts-expect-error * refactor: resolve promises internally * docs: remove `await` from shiki examples
Diffstat (limited to 'packages/integrations/markdoc/src/extensions/shiki.ts')
-rw-r--r--packages/integrations/markdoc/src/extensions/shiki.ts14
1 files changed, 3 insertions, 11 deletions
diff --git a/packages/integrations/markdoc/src/extensions/shiki.ts b/packages/integrations/markdoc/src/extensions/shiki.ts
index d03a60139..491deed56 100644
--- a/packages/integrations/markdoc/src/extensions/shiki.ts
+++ b/packages/integrations/markdoc/src/extensions/shiki.ts
@@ -2,11 +2,11 @@
// @ts-expect-error Cannot find module 'astro/runtime/server/index.js' or its corresponding type declarations.
import { unescapeHTML } from 'astro/runtime/server/index.js';
-import Markdoc from '@markdoc/markdoc';
import type { ShikiConfig } from 'astro';
import type * as shikiTypes from 'shiki';
import type { AstroMarkdocConfig } from '../config.js';
-import { MarkdocError } from '../utils.js';
+import Markdoc from '@markdoc/markdoc';
+import { getHighlighter } from 'shiki';
// Map of old theme names to new names to preserve compatibility when we upgrade shiki
const compatThemes: Record<string, string> = {
@@ -51,19 +51,11 @@ const INLINE_STYLE_SELECTOR = /style="(.*?)"/;
*/
const highlighterCache = new Map<string, shikiTypes.Highlighter>();
-export async function shiki({
+export default async function shiki({
langs = [],
theme = 'github-dark',
wrap = false,
}: ShikiConfig = {}): Promise<AstroMarkdocConfig> {
- let getHighlighter: (options: shikiTypes.HighlighterOptions) => Promise<shikiTypes.Highlighter>;
- try {
- getHighlighter = (await import('shiki')).getHighlighter;
- } catch {
- throw new MarkdocError({
- message: 'Shiki is not installed. Run `npm install shiki` to use the `shiki` extension.',
- });
- }
theme = normalizeTheme(theme);
const cacheID: string = typeof theme === 'string' ? theme : theme.name;