Api
Resources
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
create
processor()
- creates new unfrozen processor
- when the descendant processor is configured in the future it does not affect the ancestral 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).
- If you’re using a compiler that serializes, the result is available at file.contents. Otherwise, the result is available at file.result.
- freeze processor if not already frozen
use
- use cannot be called on frozen processors. Invoke the processor first to create a new unfrozen processor.
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.