API Reference
Plugins
Plugins are a nice way to extend templates with customized functionality which can encapsulate any number of blocks, filters,
preferred configuration and dependencies by implementing the IScriptPlugin interface.
The MarkdownScriptPlugin is a good example of this which registers a markdown Page format, Script Methods, Filter Transformer and markdown Block:
public class MarkdownScriptPlugin : IScriptPlugin
{
public bool RegisterPageFormat { get; set; } = true;
public void Register(ScriptContext context)
{
if (RegisterPageFormat)
context.PageFormats.Add(new MarkdownPageFormat());
context.FilterTransformers["markdown"] = MarkdownPageFormat.TransformToHtml;
context.ScriptMethods.Add(new MarkdownScriptMethods());
context.ScriptBlocks.Add(new MarkdownScriptBlock());
}
}The MarkdownScriptPlugin is pre-registered when using the #Script Pages, for
all other contexts it can be registered and customized with:
var context = new ScriptContext {
Plugins = { new MarkdownScriptPlugin { RegisterPageFormat = false } }
}.Init();Removing Plugins
When needed any default plugins can be removed with the RemovePlugins() API:
var context = new ScriptContext()
.RemovePlugins(x => x is DefaulScripttBlocks) // Remove default blocks
.RemovePlugins(x => x is HtmlScriptBlocks) // Remove all html blocks
.Init();Or you can use the OnAfterPlugins callback to remove any individual blocks or filters that were added by any plugin.
E.g. the capture block can be removed with:
var context = new ScriptContext {
OnAfterPlugins = ctx => ctx.RemoveBlocks(x => x.Name == "capture")
}
.Init();Advanced plugin registration
For greater control over the registration and execution of plugins, they can implement IScriptPluginBefore to have custom logic
executed before plugins are registered or implement IScriptPluginAfter for executing any logic after.
ScriptContext
The ScriptContext is the sandbox where all templates are executed within that can be customized with the available APIs below:
Preconfigured defaults
Some