Return Data from Unified
Sometimes its necessary for unified to return data after parsing. An example would be errors encountered during processing that we don't want to add to the compiled output but still want to pass along to the calling function.
- initialize the data field with the key and value of the payload data
let proc = remark() ... .data("{somePayload}", []);
- inside a unified plugin, add data to the passed in payload
const someData = ... const payload = proc.data("{somepayload}") payload.push(someData)
- when parsing is complete, retrieve the value from the passed in data object
await proc.processSync("...") const payload = proc.data("{somePayload}") // do something with payload
Example
See how we pass in errors to and from the processor as an example of how to set this up
export function addError(proc: Processor, err: DendronError) {
const errors = proc.data("errors") as DendronError[];
errors.push(err);
// no need to put errors back into proc, it's a mutable array
}