Processor

Defined in: node_modules/unified/lib/index.d.ts:15

Extends

  • CallableInstance<[], Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>>

Type Parameters

Type ParameterDefault typeDescription
ParseTree extends Nodeundefinedundefined
HeadTree extends Nodeundefinedundefined
TailTree extends Nodeundefinedundefined
CompileTree extends Nodeundefinedundefined
CompileResult extends CompileResultsundefinedundefined

Processor(…parameters): Processor

Defined in: node_modules/unified/lib/index.d.ts:15

Parameters

ParameterType
parameters[]

Returns

Processor

Constructors

Constructor

new Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>(): Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>

Defined in: node_modules/unified/lib/index.d.ts:19

Create a processor.

Returns

Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>

Overrides

CallableInstance<[], Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>>.constructor

Properties

attachers

attachers: [Plugin<unknown[], undefined, undefined>, ...parameters: unknown[]][]

Defined in: node_modules/unified/lib/index.d.ts:52

Internal list of configured plugins.

Deprecated

This is a private internal property and should not be used.


compiler

compiler: undefined | Compiler<CompileTree extends undefined ? Node : CompileTree, CompileResult extends undefined ? CompileResults : CompileResult>

Defined in: node_modules/unified/lib/index.d.ts:64

Compiler to use.


Compiler

Compiler: undefined | Compiler<CompileTree extends undefined ? Node : CompileTree, CompileResult extends undefined ? CompileResults : CompileResult>

Defined in: node_modules/unified/lib/index.d.ts:33

Compiler to use (deprecated).

Deprecated

Use compiler instead.


freezeIndex

freezeIndex: number

Defined in: node_modules/unified/lib/index.d.ts:72

Internal state to track where we are while freezing.

Deprecated

This is a private internal property and should not be used.


frozen

frozen: undefined | boolean

Defined in: node_modules/unified/lib/index.d.ts:80

Internal state to track whether we’re frozen.

Deprecated

This is a private internal property and should not be used.


namespace

namespace: Data

Defined in: node_modules/unified/lib/index.d.ts:88

Internal state.

Deprecated

This is a private internal property and should not be used.


parser

parser: undefined | Parser<ParseTree extends undefined ? Node : ParseTree>

Defined in: node_modules/unified/lib/index.d.ts:97

Parser to use.


Parser

Parser: undefined | Parser<ParseTree extends undefined ? Node : ParseTree>

Defined in: node_modules/unified/lib/index.d.ts:44

Parser to use (deprecated).

Deprecated

Use parser instead.


transformers

transformers: Pipeline

Defined in: node_modules/unified/lib/index.d.ts:105

Internal list of configured transformers.

Deprecated

This is a private internal property and should not be used.

Methods

copy()

copy(): Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>

Defined in: node_modules/unified/lib/index.d.ts:117

Copy a processor.

Returns

Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>

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.

Deprecated

This is a private internal method and should not be used.


data()

Call Signature

data<Key>(): Data

Defined in: node_modules/unified/lib/index.d.ts:177

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 Data interface.

Type Parameters
Type ParameterDescription
Key extends "settings"
Returns

Data

Example

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'}

Call Signature

data<Key>(dataset): Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>

Defined in: node_modules/unified/lib/index.d.ts:237

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 Data interface.

Type Parameters
Type ParameterDescription
Key extends "settings"
Parameters
ParameterTypeDescription
datasetData
Returns

Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>

Example

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'}

Call Signature

data<Key>(key?): Data[Key]

Defined in: node_modules/unified/lib/index.d.ts:297

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 Data interface.

Type Parameters
Type ParameterDescription
Key extends "settings"
Parameters
ParameterTypeDescription
key?Key
Returns

Data[Key]

Example

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'}

Call Signature

data<Key>(key?, value?): Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>

Defined in: node_modules/unified/lib/index.d.ts:357

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 Data interface.

Type Parameters
Type ParameterDescription
Key extends "settings"
Parameters
ParameterTypeDescription
key?Key
value?Data[Key]
Returns

Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>

Example

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()

freeze(): Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>

Defined in: node_modules/unified/lib/index.d.ts:375

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.

Returns

Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>

The current processor.


parse()

parse(file?): ParseTree extends undefined ? Node : ParseTree

Defined in: node_modules/unified/lib/index.d.ts:390

Parse text to a syntax tree.

Note: parse freezes the processor if not already frozen.

Note: parse performs the parse phase, not the run phase or other phases.

Parameters

ParameterTypeDescription
file?Compatiblefile to parse (optional); typically string or VFile; any value accepted as x in new VFile(x).

Returns

ParseTree extends undefined ? Node : ParseTree

Syntax tree representing file.


process()

Call Signature

process(file?, done?): undefined

Defined in: node_modules/unified/lib/index.d.ts:433

Process the given file as configured on the processor.

Note: process freezes the processor if not already frozen.

Note: process performs the parse, run, and stringify phases.

Parameters
ParameterTypeDescription
file?Compatible
done?ProcessCallback<VFileWithOutput<CompileResult>>
Returns

undefined

Call Signature

process(file?): Promise<VFileWithOutput<CompileResult>>

Defined in: node_modules/unified/lib/index.d.ts:476

Process the given file as configured on the processor.

Note: process freezes the processor if not already frozen.

Note: process performs the parse, run, and stringify phases.

Parameters
ParameterTypeDescription
file?Compatible
Returns

Promise<VFileWithOutput<CompileResult>>


processSync()

processSync(file?): VFileWithOutput<CompileResult>

Defined in: node_modules/unified/lib/index.d.ts:508

Process the given file as configured on the processor.

An error is thrown if asynchronous transforms are configured.

Note: processSync freezes the processor if not already frozen.

Note: processSync performs the parse, run, and stringify phases.

Parameters

ParameterTypeDescription
file?CompatibleFile (optional); typically string or VFile; any value accepted as x in new VFile(x).

Returns

VFileWithOutput<CompileResult>

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 (or Uint8Array). Some compilers, such as the one configured with rehype-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()

Call Signature

run(tree, done?): undefined

Defined in: node_modules/unified/lib/index.d.ts:547

Run transformers on a syntax tree.

Note: run freezes the processor if not already frozen.

Note: run performs the run phase, not other phases.

Parameters
ParameterTypeDescription
treeHeadTree extends undefined ? Node : HeadTree
done?RunCallback<TailTree extends undefined ? Node : TailTree>
Returns

undefined

Call Signature

run(tree, file?, done?): undefined

Defined in: node_modules/unified/lib/index.d.ts:586

Run transformers on a syntax tree.

Note: run freezes the processor if not already frozen.

Note: run performs the run phase, not other phases.

Parameters
ParameterTypeDescription
treeHeadTree extends undefined ? Node : HeadTree
file?Compatible
done?RunCallback<TailTree extends undefined ? Node : TailTree>
Returns

undefined

Call Signature

run(tree, file?): Promise<TailTree extends undefined ? Node : TailTree>

Defined in: node_modules/unified/lib/index.d.ts:625

Run transformers on a syntax tree.

Note: run freezes the processor if not already frozen.

Note: run performs the run phase, not other phases.

Parameters
ParameterTypeDescription
treeHeadTree extends undefined ? Node : HeadTree
file?Compatible
Returns

Promise<TailTree extends undefined ? Node : TailTree>


runSync()

runSync(tree, file?): TailTree extends undefined ? Node : TailTree

Defined in: node_modules/unified/lib/index.d.ts:643

Run transformers on a syntax tree.

An error is thrown if asynchronous transforms are configured.

Note: runSync freezes the processor if not already frozen.

Note: runSync performs the run phase, not other phases.

Parameters

ParameterTypeDescription
treeHeadTree extends undefined ? Node : HeadTreeTree to transform and inspect.
file?CompatibleFile associated with node (optional); any value accepted as x in new VFile(x).

Returns

TailTree extends undefined ? Node : TailTree

Transformed tree.


stringify()

stringify(tree, file?): CompileResult extends undefined ? Value : CompileResult

Defined in: node_modules/unified/lib/index.d.ts:673

Compile a syntax tree.

Note: stringify freezes the processor if not already frozen.

Note: stringify performs the stringify phase, not the run phase or other phases.

Parameters

ParameterTypeDescription
treeCompileTree extends undefined ? Node : CompileTreeTree to compile.
file?CompatibleFile associated with node (optional); any value accepted as x in new VFile(x).

Returns

CompileResult extends undefined ? Value : CompileResult

Textual representation of the tree (see note).

Note: unified typically compiles by serializing: most compilers return string (or Uint8Array). Some compilers, such as the one configured with rehype-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.


use()

Call Signature

use<Parameters_1, Input, Output>(preset?): Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>

Defined in: node_modules/unified/lib/index.d.ts:731

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: use cannot be called on frozen processors. Call the processor first to create a new unfrozen processor.

Type Parameters
Type ParameterDefault typeDescription
Parameters_1 extends unknown[][]-
Input extends undefinedstringNode
OutputInput
Parameters
ParameterTypeDescription
preset?nullPreset
Returns

Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>

Example

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}})

Call Signature

use<Parameters_1, Input, Output>(list): Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>

Defined in: node_modules/unified/lib/index.d.ts:789

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: use cannot be called on frozen processors. Call the processor first to create a new unfrozen processor.

Type Parameters
Type ParameterDefault typeDescription
Parameters_1 extends unknown[][]-
Input extends undefinedstringNode
OutputInput
Parameters
ParameterTypeDescription
listPluggableList
Returns

Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>

Example

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}})

Call Signature

use<Parameters_1, Input, Output>(plugin, …parameters): UsePlugin<ParseTree, HeadTree, TailTree, CompileTree, CompileResult, Input, Output>

Defined in: node_modules/unified/lib/index.d.ts:847

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: use cannot be called on frozen processors. Call the processor first to create a new unfrozen processor.

Type Parameters
Type ParameterDefault typeDescription
Parameters_1 extends unknown[][]-
Input extends undefinedstringNode
OutputInput
Parameters
ParameterTypeDescription
pluginPlugin<Parameters_1, Input, Output>
parametersParameters_1[boolean]
Returns

UsePlugin<ParseTree, HeadTree, TailTree, CompileTree, CompileResult, Input, Output>

Example

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}})