Create custom extensions
mainYou can extend existing extensions to change their behavior (e.g., changing the rendered HTML tag) or build entirely new ones by extending Tiptap\Core\Node.
When building custom nodes, you can implement:
addOptions(): Define configuration options.parseHTML(): Define how HTML is converted to the node.renderHTML(): Define how the node is rendered to HTML.
Extension Priority:
Extensions are evaluated in descending order of priority. The default priority is 100. If a node needs to take precedence over another (e.g., TaskItem over ListItem), set a higher public static $priority value.
use Tiptap\Core\Node;
class CustomNode extends Node
{
public static $name = 'customNode';
public static $priority = 100;
public function addOptions()
{
return ['HTMLAttributes' => []];
}
public function parseHTML()
{
return [['tag' => 'my-custom-tag']];
}
public function renderHTML($node)
{
return ['my-custom-tag', ['class' => 'foobar'], 0];
}
}