Skip to content

Commit

Permalink
feat(nextra): allow define custom languages for shiki with `mdxOption…
Browse files Browse the repository at this point in the history
…s.rehypePrettyCodeOptions` option (#562)
  • Loading branch information
dimaMachina committed Jul 22, 2022
1 parent 3dd7dc2 commit 4a7cc10
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-tips-invite.md
@@ -0,0 +1,5 @@
---
'nextra': patch
---

feat(nextra): allow define custom languages for shiki with `mdxOptions.rehypePrettyCodeOptions` option
20 changes: 8 additions & 12 deletions packages/nextra/src/compile.ts
Expand Up @@ -46,17 +46,10 @@ export async function compileMdx(
source: string,
mdxOptions: LoaderOptions['mdxOptions'] &
Pick<ProcessorOptions, 'jsx' | 'outputFormat'> = {},
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 = {}
Expand All @@ -77,7 +70,10 @@ export async function compileMdx(
rehypePlugins: [
...(mdxOptions.rehypePlugins || []),
parseMeta,
[rehypePrettyCode, rehypePrettyCodeOptions],
[
rehypePrettyCode,
{ ...rehypePrettyCodeOptions, ...mdxOptions.rehypePrettyCodeOptions }
],
attachMeta
].filter(Boolean)
})
Expand Down
13 changes: 6 additions & 7 deletions 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<ProcessorOptions, 'rehypePlugins' | 'remarkPlugins'>
pageMapCache: PageMapCache
}

Expand Down Expand Up @@ -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<ProcessorOptions, 'rehypePlugins' | 'remarkPlugins'> & {
rehypePrettyCodeOptions?: Partial<RehypePrettyCodeOptions>
}
}

export type withNextra = (
Expand Down

0 comments on commit 4a7cc10

Please sign in to comment.