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

Type Parameters

Hierarchy (view full)

Constructors

Properties

Compiler to use (deprecated).

Deprecated

Use compiler instead.

Parser to use (deprecated).

Deprecated

Use parser instead.

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

Internal list of configured plugins.

Deprecated

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

Compiler to use.

freezeIndex: number

Internal state to track where we are while freezing.

Deprecated

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

frozen: undefined | boolean

Internal state to track whether we’re frozen.

Deprecated

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

namespace: Data

Internal state.

Deprecated

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

Parser to use.

transformers: Pipeline

Internal list of configured transformers.

Deprecated

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

Methods

  • 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

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

    • Key extends "settings"

    Parameters

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

    • Key extends "settings"

    Parameters

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

    • Key extends "settings"

    Parameters

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

  • 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

    Returns undefined

  • 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

    Returns Promise<VFileWithOutput<CompileResult>>

  • 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

    • Optional file: Compatible

      File (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.

  • 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

    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.

  • 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

    Parameters

    • Optional preset: null | Preset

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

    Parameters

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

    Parameters

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