A plugin that can be added to an [[ArgdownApplication]] with app.AddPlugin(plugin, processorId).
Can walk the Argdown AST by using tokenListeners and ruleListeners. Should use the run method for everything else.
Plugins should avoid keeping any local mutable state. Instead they should use
the provided request object for configuration and the provided response object for returning any produced or transformed data.
The only exceptions are I/O operations (e.g. loading or saving files).
exportinterfaceIGreetingSettings{ addHello?:boolean; } // We augment the request and response types from @argdown/core // to add our plugin settings and data: declaremodule"@argdown/core"{ interfaceIArgdownRequest{ greeting?:IGreetingSettings; } interfaceIArgdownResponse{ greeting:string; } }
exportclassGreetingPluginimplementsIArgdownPlugin{ name = "GreetingPlugin"; prepare:IRequestHandler = (request, response)=>{ // check if requirements are met if(!response.ast){ thrownewArgdownPluginError(this.name, "No ast found in response."); } // create default settings if(!request.greeting){ request.greeting = {}; } if(request.greeting.sayHello === undefined){ request.greeting.sayHello = true; } }; run:IRequestHandler = (request, response)=>{ if(request.greeting && request.greeting.addHello){ // adding data to response object response.greeting = "Hallo World!"; } }; ruleListeners = { [RuleNames.STATEMENT+"Entry"]: (request, response, node, parentNode, childIndex, logger)=>{ // use the logger parameter instead of console.log logger.log("verbose", `Statement: ${node.statement.text}`); } } }
A plugin that can be added to an [[ArgdownApplication]] with
app.AddPlugin(plugin, processorId).Can walk the Argdown AST by using
tokenListenersandruleListeners. Should use therunmethod for everything else.Plugins should avoid keeping any local mutable state. Instead they should use the provided request object for configuration and the provided response object for returning any produced or transformed data. The only exceptions are I/O operations (e.g. loading or saving files).
See the guide on writing custom plugins for more information.
Example