From 4a7cc103039705d5dc8844afd000add5ed6f7f3b Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Fri, 22 Jul 2022 15:35:25 +0200 Subject: [PATCH] feat(nextra): allow define custom languages for shiki with `mdxOptions.rehypePrettyCodeOptions` option (#562) --- .changeset/pretty-tips-invite.md | 5 +++++ packages/nextra/src/compile.ts | 20 ++++++++------------ packages/nextra/src/types.ts | 13 ++++++------- 3 files changed, 19 insertions(+), 19 deletions(-) create mode 100644 .changeset/pretty-tips-invite.md diff --git a/.changeset/pretty-tips-invite.md b/.changeset/pretty-tips-invite.md new file mode 100644 index 0000000000..151a354e40 --- /dev/null +++ b/.changeset/pretty-tips-invite.md @@ -0,0 +1,5 @@ +--- +'nextra': patch +--- + +feat(nextra): allow define custom languages for shiki with `mdxOptions.rehypePrettyCodeOptions` option diff --git a/packages/nextra/src/compile.ts b/packages/nextra/src/compile.ts index b5a6d28c4f..3ed9d1af57 100644 --- a/packages/nextra/src/compile.ts +++ b/packages/nextra/src/compile.ts @@ -46,17 +46,10 @@ export async function compileMdx( source: string, mdxOptions: LoaderOptions['mdxOptions'] & Pick = {}, - nextraOptions: { - unstable_staticImage: boolean - unstable_flexsearch: - | boolean - | { - codeblocks: boolean - } - } = { - unstable_staticImage: false, - unstable_flexsearch: false - }, + nextraOptions: Pick< + LoaderOptions, + 'unstable_staticImage' | 'unstable_flexsearch' + > = {}, resourcePath: string ) { let structurizedData = {} @@ -77,7 +70,10 @@ export async function compileMdx( rehypePlugins: [ ...(mdxOptions.rehypePlugins || []), parseMeta, - [rehypePrettyCode, rehypePrettyCodeOptions], + [ + rehypePrettyCode, + { ...rehypePrettyCodeOptions, ...mdxOptions.rehypePrettyCodeOptions } + ], attachMeta ].filter(Boolean) }) diff --git a/packages/nextra/src/types.ts b/packages/nextra/src/types.ts index 390d309f0e..14ebec0927 100644 --- a/packages/nextra/src/types.ts +++ b/packages/nextra/src/types.ts @@ -1,15 +1,11 @@ import { Heading as MDASTHeading } from 'mdast' import { ProcessorOptions } from '@mdx-js/mdx' +import { Options as RehypePrettyCodeOptions } from 'rehype-pretty-code' import { PageMapCache } from './plugin' -export interface LoaderOptions { - theme: Theme - themeConfig: string +export interface LoaderOptions extends NextraConfig { locales: string[] defaultLocale: string - unstable_staticImage: boolean - unstable_flexsearch: boolean - mdxOptions: Pick pageMapCache: PageMapCache } @@ -49,8 +45,11 @@ type Theme = string export type NextraConfig = { theme: Theme themeConfig: string - unstable_flexsearch: boolean + unstable_flexsearch?: boolean | { codeblocks: boolean } unstable_staticImage?: boolean + mdxOptions?: Pick & { + rehypePrettyCodeOptions?: Partial + } } export type withNextra = (