1.5 KiB
1.5 KiB
description, tags
| description | tags |
|---|---|
| API to define custom syntax extensions | meta/api |
API
syntax.define(spec)
Registers a custom syntax extension. The extension will be active after the next editor state rebuild (e.g. on page reload or config change).
Available keys:
name: AST node name (e.g. "LatexBlock")startMarker: Regex string for start delimiter (e.g."\\$\\$")endMarker: Regex string for end delimitermode:"block"or"inline"startMarkerClass: (optional) CSS class for the start markerbodyClass: (optional) CSS class for the body content between markersendMarkerClass: (optional) CSS class for the end markerrenderClass: (optional) CSS class applied to the rendered widgetrenderWidget: (optional) Callbackfunction(body, pageName)returning widget content for live editor preview. Previously namedrender, which is still supported for backwards compatibility.renderHtml: Callbackfunction(body, pageName)returning an HTML string orHTMLElement(e.g. viadom.*) for use when rendering to HTML.
Implementation
-- priority: 99
syntax = syntax or {}
function syntax.define(spec)
if not spec.name then error("syntax.define requires 'name'") end
if not spec.startMarker then error("syntax.define requires 'startMarker'") end
if not spec.endMarker then error("syntax.define requires 'endMarker'") end
if not spec.mode then error("syntax.define requires 'mode'") end
config.set({"syntaxExtensions", spec.name}, spec)
end