below is my tiptap code which creates paragraph
<script>
this.editor.commands.insertContent({
type: 'paragraph',
HTMLAttributes: {
class: 'created-paragraph',
},
content: [{ type: 'text', text }],
});
</script>
i created a paragraph like this, but "HTMLAttributes" is not working, how to add a class in other way? i cant figure it out 🙁
i hope guys u can help me
2
Answers
You can add classes or styles to the content by extending the schema and creating your own node with the desired attributes.
Usage in editor
When you use this.editor.commands.insertContent to insert a paragraph, you can use the custom node
you can use the
addClass
method to add a class to a node.The
chain
method is used for chaining commands. Each call to a method likefocus
,insertContent
, oraddClass
returns a new chain instance, and therun
method is used to execute the chain of commands.