How to transform mark attributes

Hello. I created mark link plugin with href attr. Someone can use it with{ href }) and paste any href. I want to transform this href and store it another way (suppose check and add https:// prefix).

How can I define attr transform rule in plugin declaration?

You can use transformPasted to ‘fix’ pasted content, and set up your user interface to only create links with the expected href attributes.

In this case I have to add this transformation logic to every place where link.create({ href }) is called. I wanted to encapsulate it in link plugin declaration

transformPasted can be added to a plugin as @marijn suggested, see Plugin.props. I think that should still work. ProseMirror Reference manual

Or more generically if its not on paste? appendTransaction (ProseMirror Reference manual) will work if you are using plugins.

But perhaps you can clarify exactly what you mean by when “link.create({ href })” is called. Perhaps share a code snippet of what you are getting at?

You can’t. Attributes don’t support any kind of validation logic, and assume the code that creates them knows that it’s doing.

ok, thanks