Skip to content

Dynamic style management in Tiptap: updating classes and removing elements #5798

Discussion options

You must be logged in to vote

By replicating the TextStyle & Color extension + a function to update each marks, it did the trick :

  const deleteFontSizeClass = (className) =>{
    editor.state.doc.descendants((node, pos) => {
      if (node.marks) {
        node.marks.forEach((mark) => {
          if(mark.type.name == 'textClass'){
            if(mark.attrs.fontSize == className){
              editor.chain().setTextSelection({ from: pos, to: pos + node.nodeSize }).unsetFontSize().run()
            }
          }
        });
      }
      return true; 
    });
  }

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pat123456
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant