Creating Custom Tags
You can create custom tags by extending theTagPlugin class and registering them with the TagPluginRegistry.
Extending TagPlugin
Create a class that extendsTagPlugin and implements the transform method:
The transform Method
Thetransform method receives three arguments:
props- The attributes passed to the tagchildren- An array of AST nodes representing the tag’s childrencontext- APluginContextobject containing:nodeHelpers- Utilities for working with AST nodes (toMarkdown,isMdxJsxElement, etc.)scope- The current variable scopecreateNodeTransformer- Factory to create a transformer for processing child nodestagName- The name of the tag being processed
Promise resolving to either a single Node or an array of Node objects.
Registering Custom Tags
Register your custom tag with theTagPluginRegistry:
Example: Quote Tag
Here’s a complete example of a custom tag that wraps content in a blockquote:Built-In Tags
ForEach
TheForEach tag allows you to loop through an array.
Syntax
arr: Array<T>An array of items you want to iterate onchildren: (item: T, index: number) => Node- A callback function for each item
Conditionals
TheIf, ElseIf and Else tags allows you to conditionally output content.
Syntax
If/ElseIf:
condition: boolean- The condition to checkchildren: Node- The node to render if condition is true
Else:
children: Node- The content to render if no previous condition was met.
Raw
TheRaw tag allows you to output raw text without interpolation.
Syntax
children: Node- The raw text