Link Search Menu Expand Document

Exapmle

var unified = require('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}})

Processor

props

processor.data([key[, value]])

methods

run(node[, file][, done])

  • Run transformers on a syntax tree.

processor.process(file[, done])

  • return
    • Promise if done is not given. The returned promise is rejected with a fatal error, or resolved with the processed file.
    • The parsed, transformed, and compiled value is exposed on file.contents or file.result (see notes).
  • details
    • process performs the parse, run, and stringify phases.
    • unified typically compiles by serializing: most compilers return string (or Buffer).

Compiler

  • source: https://github.com/unifiedjs/unified#processorcompiler

  • compile ast to text

  • can be a function, in which case it should return a string

  • can also be a constructor function (a function with a compile field, or other fields, in its prototype), in which case itโ€™s constructed with new. Instances must have a compile method that is called without arguments and should return a string.

Plugin

  • They change the processor: such as the parser, the compiler, or configuring data
  • They specify how to handle syntax trees and files

Transformer

function transformer(node, file[, next])

Transformers handle syntax trees and files. A transformer is a function that is called each time a syntax tree and file are passed through the run phase. If an error occurs (either because itโ€™s thrown, returned, rejected, or passed to next), the process stops.


Table of contents


Copyright © 2020 Thence LLC