BlockNote icon indicating copy to clipboard operation
BlockNote copied to clipboard

Dynamically add styles to text

Open vijayk1989 opened this issue 10 months ago • 2 comments

Is your feature request related to a problem? Please describe. I want to auto underline text after typing based on a criteria. For example. I have an array with the names: [Jane, John]. Now when I type the word Jane or John I want that text to be underlined after I finish typing them. I know its possible to add styles to selected text so I tried something similar with a debounced function to add an underline to a word dyanmically but I have been unable to make it work.

Describe the solution you'd like I want to be able to add styles to text (not selected text) any text in the document.

Describe alternatives you've considered I have tried scanning the full document and applying styles but I am not able to make it work.

vijayk1989 avatar Jan 18 '25 15:01 vijayk1989

Technically this is currently possible to do by parsing the whole document in the onChange handler of BlockNoteView, and applying styles where you find content between [] brackets, but this is extremely tedious.

TipTap, the underlying editor used by BlockNote, has a feature called input rules which is made for this exact use case. However, we don't have a wrapper for this in the current BlockNote API, so you would have to create a TipTap extension and pass it to the editor via the _extensions option, smth like this:

const editor = useCreateBlockNote({
  _extensions: {
    dynamicUnderline: Extension.create({
      name: "dynamicUnderline",
      addInputRules() {
        ...
      }
    })
  }
});

matthewlipski avatar Feb 17 '25 19:02 matthewlipski

There's an example of this here: https://www.blocknotejs.org/examples/extensions/tiptap-arrow-conversion

YousefED avatar Feb 24 '25 12:02 YousefED

BlockNote Extensions now support input rules https://www.blocknotejs.org/docs/features/extensions

nperez0111 avatar Sep 19 '25 14:09 nperez0111