-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
format
to support MDX and plain markdown
Add `format` to support MDX and plain markdown * Default to detecting whether input is `mdx` or `md` based on whether the given file has an extension in `mdExtensions` and to handle both `mdExtensions` and `mdxExtensions` in integrations * Support `format: 'md'` to treat input as markdown and to handle `mdExtensions` in integrations * Support `format: 'mdx'` to treat input as MDX and to handle `mdxExtensions` in integrations * Switch which elements will turn into configurable components, previously that was everything that was written in the source markdown, now this is everything not explicitly written as JSX * Add tests for integration with `rehype-raw` * Fix docs on `evaluate` options Closes GH-17. Closes GH-19. Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com> Reviewed-by: Remco Haszing <remcohaszing@gmail.com>
- Loading branch information
Showing
21 changed files
with
598 additions
and
143 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,4 @@ | ||
export {createProcessor} from './lib/core.js' | ||
export {compile, compileSync} from './lib/compile.js' | ||
export {evaluate, evaluateSync} from './lib/evaluate.js' | ||
export {nodeTypes} from './lib/node-types.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,39 @@ | ||
import vfile from 'vfile' | ||
import {createProcessor} from './core.js' | ||
import {resolveFileAndOptions} from './util/resolve-file-and-options.js' | ||
|
||
/** | ||
* @typedef {import('vfile').VFileCompatible} VFileCompatible | ||
* @typedef {import('vfile').VFile} VFile | ||
* @typedef {import('./core').ProcessorOptions} ProcessorOptions | ||
* @typedef {import('./core').PluginOptions} PluginOptions | ||
* @typedef {import('./core').BaseProcessorOptions} BaseProcessorOptions | ||
* @typedef {Omit<BaseProcessorOptions, 'format'>} CoreProcessorOptions | ||
* | ||
* @typedef ExtraOptions | ||
* @property {'detect' | 'mdx' | 'md'} [format='detect'] Format of `file` | ||
* | ||
* @typedef {CoreProcessorOptions & PluginOptions & ExtraOptions} CompileOptions | ||
*/ | ||
|
||
/** | ||
* Compile MDX to JS. | ||
* | ||
* @param {VFileCompatible} vfileCompatible MDX document to parse (`string`, `Buffer`, `vfile`, anything that can be given to `vfile`) | ||
* @param {ProcessorOptions} [options] | ||
* @param {CompileOptions} [compileOptions] | ||
* @return {Promise<VFile>} | ||
*/ | ||
export function compile(vfileCompatible, options) { | ||
var {settings, file} = configure(vfileCompatible, options) | ||
return createProcessor(settings).process(file) | ||
export function compile(vfileCompatible, compileOptions) { | ||
var {file, options} = resolveFileAndOptions(vfileCompatible, compileOptions) | ||
return createProcessor(options).process(file) | ||
} | ||
|
||
/** | ||
* Synchronously compile MDX to JS. | ||
* | ||
* @param {VFileCompatible} vfileCompatible MDX document to parse (`string`, `Buffer`, `vfile`, anything that can be given to `vfile`) | ||
* @param {ProcessorOptions} [options] | ||
* @param {CompileOptions} [compileOptions] | ||
* @return {VFile} | ||
*/ | ||
export function compileSync(vfileCompatible, options) { | ||
var {settings, file} = configure(vfileCompatible, options) | ||
return createProcessor(settings).processSync(file) | ||
} | ||
|
||
function configure(vfileCompatible, options) { | ||
return {file: vfile(vfileCompatible), settings: options || {}} | ||
export function compileSync(vfileCompatible, compileOptions) { | ||
var {file, options} = resolveFileAndOptions(vfileCompatible, compileOptions) | ||
return createProcessor(options).processSync(file) | ||
} |
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
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
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
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,9 @@ | ||
// List of node types made by `mdast-util-mdx`, which have to be passed | ||
// through untouched from the mdast tree to the hast tree. | ||
export var nodeTypes = [ | ||
'mdxFlowExpression', | ||
'mdxJsxFlowElement', | ||
'mdxJsxTextElement', | ||
'mdxTextExpression', | ||
'mdxjsEsm' | ||
] |
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
Oops, something went wrong.