Input for run (optional).
Output for run (optional).
Input of stringify (optional).
Output of stringify (optional).
Rest ...parameters: []Create a processor.
Compiler to use (deprecated).
Use compiler instead.
Parser to use (deprecated).
Use parser instead.
Internal list of configured plugins.
This is a private internal property and should not be used.
Compiler to use.
Internal state to track where we are while freezing.
This is a private internal property and should not be used.
Internal state to track whether we’re frozen.
This is a private internal property and should not be used.
Internal state.
This is a private internal property and should not be used.
Parser to use.
Internal list of configured transformers.
This is a private internal property and should not be used.
Copy a processor.
New unfrozen processor (Processor) that is
configured to work the same as its ancestor.
When the descendant processor is configured in the future it does not
affect the ancestral processor.
This is a private internal method and should not be used.
Configure the processor with info available to all plugins. Information is stored in an object.
Typically, options can be given to a specific plugin, but sometimes it makes sense to have information shared with several plugins. For example, a list of HTML elements that are self-closing, which is needed during all phases.
👉 Note: setting information cannot occur on frozen processors. Call the processor first to create a new unfrozen processor.
👉 Note: to register custom data in TypeScript, augment the
Datainterface.
This example show how to get and set info:
import {unified} from 'unified'
const processor = unified().data('alpha', 'bravo')
processor.data('alpha') // => 'bravo'
processor.data() // => {alpha: 'bravo'}
processor.data({charlie: 'delta'})
processor.data() // => {charlie: 'delta'}
Configure the processor with info available to all plugins. Information is stored in an object.
Typically, options can be given to a specific plugin, but sometimes it makes sense to have information shared with several plugins. For example, a list of HTML elements that are self-closing, which is needed during all phases.
👉 Note: setting information cannot occur on frozen processors. Call the processor first to create a new unfrozen processor.
👉 Note: to register custom data in TypeScript, augment the
Datainterface.
This example show how to get and set info:
import {unified} from 'unified'
const processor = unified().data('alpha', 'bravo')
processor.data('alpha') // => 'bravo'
processor.data() // => {alpha: 'bravo'}
processor.data({charlie: 'delta'})
processor.data() // => {charlie: 'delta'}
Configure the processor with info available to all plugins. Information is stored in an object.
Typically, options can be given to a specific plugin, but sometimes it makes sense to have information shared with several plugins. For example, a list of HTML elements that are self-closing, which is needed during all phases.
👉 Note: setting information cannot occur on frozen processors. Call the processor first to create a new unfrozen processor.
👉 Note: to register custom data in TypeScript, augment the
Datainterface.
Optional key: KeyThis example show how to get and set info:
import {unified} from 'unified'
const processor = unified().data('alpha', 'bravo')
processor.data('alpha') // => 'bravo'
processor.data() // => {alpha: 'bravo'}
processor.data({charlie: 'delta'})
processor.data() // => {charlie: 'delta'}
Configure the processor with info available to all plugins. Information is stored in an object.
Typically, options can be given to a specific plugin, but sometimes it makes sense to have information shared with several plugins. For example, a list of HTML elements that are self-closing, which is needed during all phases.
👉 Note: setting information cannot occur on frozen processors. Call the processor first to create a new unfrozen processor.
👉 Note: to register custom data in TypeScript, augment the
Datainterface.
This example show how to get and set info:
import {unified} from 'unified'
const processor = unified().data('alpha', 'bravo')
processor.data('alpha') // => 'bravo'
processor.data() // => {alpha: 'bravo'}
processor.data({charlie: 'delta'})
processor.data() // => {charlie: 'delta'}
Freeze a processor.
Frozen processors are meant to be extended and not to be configured directly.
When a processor is frozen it cannot be unfrozen. New processors working the same way can be created by calling the processor.
It’s possible to freeze processors explicitly by calling .freeze().
Processors freeze automatically when .parse(), .run(), .runSync(),
.stringify(), .process(), or .processSync() are called.
The current processor.
Parse text to a syntax tree.
👉 Note:
parsefreezes the processor if not already frozen.
👉 Note:
parseperforms the parse phase, not the run phase or other phases.
Optional file: Compatiblefile to parse (optional); typically string or VFile; any value
accepted as x in new VFile(x).
Syntax tree representing file.
Process the given file as configured on the processor.
👉 Note:
processfreezes the processor if not already frozen.
👉 Note:
processperforms the parse, run, and stringify phases.
Optional file: CompatibleOptional done: ProcessCallback<VFileWithOutput<CompileResult>>Process the given file as configured on the processor.
👉 Note:
processfreezes the processor if not already frozen.
👉 Note:
processperforms the parse, run, and stringify phases.
Optional file: CompatibleProcess the given file as configured on the processor.
An error is thrown if asynchronous transforms are configured.
👉 Note:
processSyncfreezes the processor if not already frozen.
👉 Note:
processSyncperforms the parse, run, and stringify phases.
Optional file: CompatibleFile (optional); typically string or VFile; any value accepted as
x in new VFile(x).
The processed file.
The parsed, transformed, and compiled value is available at
file.value (see note).
👉 Note: unified typically compiles by serializing: most compilers return
string(orUint8Array). Some compilers, such as the one configured withrehype-react, return other values (in this case, a React tree). If you’re using a compiler that doesn’t serialize, expect different result values.To register custom results in TypeScript, add them to
CompileResultMap.
Run transformers on a syntax tree.
👉 Note:
runfreezes the processor if not already frozen.
👉 Note:
runperforms the run phase, not other phases.
Optional done: RunCallback<TailTree extends undefinedRun transformers on a syntax tree.
👉 Note:
runfreezes the processor if not already frozen.
👉 Note:
runperforms the run phase, not other phases.
Optional file: CompatibleOptional done: RunCallback<TailTree extends undefinedRun transformers on a syntax tree.
👉 Note:
runfreezes the processor if not already frozen.
👉 Note:
runperforms the run phase, not other phases.
Optional file: CompatibleRun transformers on a syntax tree.
An error is thrown if asynchronous transforms are configured.
👉 Note:
runSyncfreezes the processor if not already frozen.
👉 Note:
runSyncperforms the run phase, not other phases.
Tree to transform and inspect.
Optional file: CompatibleFile associated with node (optional); any value accepted as x in
new VFile(x).
Transformed tree.
Compile a syntax tree.
👉 Note:
stringifyfreezes the processor if not already frozen.
👉 Note:
stringifyperforms the stringify phase, not the run phase or other phases.
Tree to compile.
Optional file: CompatibleFile associated with node (optional); any value accepted as x in
new VFile(x).
Textual representation of the tree (see note).
👉 Note: unified typically compiles by serializing: most compilers return
string(orUint8Array). Some compilers, such as the one configured withrehype-react, return other values (in this case, a React tree). If you’re using a compiler that doesn’t serialize, expect different result values.To register custom results in TypeScript, add them to
CompileResultMap.
Configure the processor to use a plugin, a list of usable values, or a preset.
If the processor is already using a plugin, the previous plugin configuration is changed based on the options that are passed in. In other words, the plugin is not added a second time.
👉 Note:
usecannot be called on frozen processors. Call the processor first to create a new unfrozen processor.
Optional preset: null | PresetThere are many ways to pass plugins to .use().
This example gives an overview:
import {unified} from 'unified'
unified()
// Plugin with options:
.use(pluginA, {x: true, y: true})
// Passing the same plugin again merges configuration (to `{x: true, y: false, z: true}`):
.use(pluginA, {y: false, z: true})
// Plugins:
.use([pluginB, pluginC])
// Two plugins, the second with options:
.use([pluginD, [pluginE, {}]])
// Preset with plugins and settings:
.use({plugins: [pluginF, [pluginG, {}]], settings: {position: false}})
// Settings only:
.use({settings: {position: false}})
Configure the processor to use a plugin, a list of usable values, or a preset.
If the processor is already using a plugin, the previous plugin configuration is changed based on the options that are passed in. In other words, the plugin is not added a second time.
👉 Note:
usecannot be called on frozen processors. Call the processor first to create a new unfrozen processor.
There are many ways to pass plugins to .use().
This example gives an overview:
import {unified} from 'unified'
unified()
// Plugin with options:
.use(pluginA, {x: true, y: true})
// Passing the same plugin again merges configuration (to `{x: true, y: false, z: true}`):
.use(pluginA, {y: false, z: true})
// Plugins:
.use([pluginB, pluginC])
// Two plugins, the second with options:
.use([pluginD, [pluginE, {}]])
// Preset with plugins and settings:
.use({plugins: [pluginF, [pluginG, {}]], settings: {position: false}})
// Settings only:
.use({settings: {position: false}})
Configure the processor to use a plugin, a list of usable values, or a preset.
If the processor is already using a plugin, the previous plugin configuration is changed based on the options that are passed in. In other words, the plugin is not added a second time.
👉 Note:
usecannot be called on frozen processors. Call the processor first to create a new unfrozen processor.
Rest ...parameters: Parameters_2 | [boolean]There are many ways to pass plugins to .use().
This example gives an overview:
import {unified} from 'unified'
unified()
// Plugin with options:
.use(pluginA, {x: true, y: true})
// Passing the same plugin again merges configuration (to `{x: true, y: false, z: true}`):
.use(pluginA, {y: false, z: true})
// Plugins:
.use([pluginB, pluginC])
// Two plugins, the second with options:
.use([pluginD, [pluginE, {}]])
// Preset with plugins and settings:
.use({plugins: [pluginF, [pluginG, {}]], settings: {position: false}})
// Settings only:
.use({settings: {position: false}})
Output of
parse(optional).