-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
further refinement, break into separate files, update test to use ts
- Loading branch information
Showing
11 changed files
with
3,152 additions
and
1,105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
__tests__ | ||
examples | ||
.prettierrc | ||
.prettierrc | ||
tsconfig.json | ||
babel.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
presets: [ | ||
['@babel/preset-env', { targets: { node: 'current' } }], | ||
'@babel/preset-typescript', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ReactNode } from 'react' | ||
import { MdxRemote } from 'types' | ||
|
||
export default function hydrate( | ||
/** Rendered MDX output. The direct output of `renderToString`. */ | ||
source: MdxRemote.Source, | ||
/** | ||
* A map of names to React components. | ||
* The key used will be the name accessible to MDX. | ||
* | ||
* For example: `{ ComponentName: Component }` will be accessible in the MDX as `<ComponentName/>`. | ||
*/ | ||
options: { components: MdxRemote.Components } | ||
): ReactNode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,10 @@ | ||
import * as React from 'react' | ||
import { Plugin, Compiler } from 'unified' | ||
import hydrate from 'hydrate' | ||
import renderToString from 'render-to-string' | ||
|
||
/** An object containing components to be made available within mdx content */ | ||
interface MdxRemoteComponentsType { | ||
[componentName: string]: React.FunctionComponent | React.Component | ||
} | ||
|
||
/** Format of the output from renderToString and input to hydrate */ | ||
interface MdxRemoteSourceType { | ||
compiledSource: string | ||
renderedOutput: string | ||
scope?: Record<string, unknown> | ||
} | ||
|
||
declare module 'next-mdx-remote' { | ||
export type MdxRemoteSource = MdxRemoteSourceType | ||
export type MdxRemoteComponents = MdxRemoteComponentsType | ||
declare module 'next-mdx-remote/render-to-string' { | ||
export default renderToString | ||
} | ||
|
||
declare module 'next-mdx-remote/hydrate' { | ||
export default function hydrate( | ||
/** Rendered MDX output. The direct output of `renderToString`. */ | ||
source: MdxRemoteSourceType, | ||
/** | ||
* A map of names to React components. | ||
* The key used will be the name accessible to MDX. | ||
* | ||
* For example: `{ ComponentName: Component }` will be accessible in the MDX as `<ComponentName/>`. | ||
*/ | ||
options: { components: MdxRemoteComponentsType } | ||
): React.ReactNode | ||
} | ||
|
||
declare module 'next-mdx-remote/render-to-string' { | ||
/** | ||
* Runs the MDX renderer on the MDX string provided with the components and data provided. | ||
*/ | ||
export default async function renderToString( | ||
/** Raw MDX contents as a string. */ | ||
source: string, | ||
/** Optional parameters, such as components, plugins, and data. */ | ||
params?: { | ||
/** | ||
* A object mapping names to React components. | ||
* The key used will be the name accessible to MDX. | ||
* | ||
* For example: `{ ComponentName: Component }` will be accessible in the MDX as `<ComponentName/>`. | ||
*/ | ||
components?: MdxRemoteComponentsType | ||
/** | ||
* An arbitrary object of data which will be supplied to the MDX. | ||
* | ||
* For example, in cases where you want to provide template variables to the MDX, like `my name is {name}`, | ||
* you could provide scope as `{ name: "Some name" }`. | ||
*/ | ||
scope?: Record<string, unknown> | ||
/** | ||
* These options are passed to the MDX compiler. | ||
* See [the MDX docs.](https://github.com/mdx-js/mdx/blob/master/packages/mdx/index.js). | ||
*/ | ||
mdxOptions?: { | ||
remarkPlugins?: Plugin[] | ||
rehypePlugins?: Plugin[] | ||
hastPlugins?: Plugin[] | ||
compilers?: Compiler[] | ||
filepath?: string | ||
} | ||
} | ||
): Promise<MdxRemoteSourceType> | ||
export default hydrate | ||
} |
Oops, something went wrong.