Prevent marks from breaking up links

Is there any way to promote links so that inner marks do not break them into several links? It’s certainly weird for a user to try and bold the middle of a link. My common use case is around spell checking. I mark misspelled words which causes the link to break up. In either case it would be best if links remained on the outside of the inner markings.

<p>
  <a href=\"http://prosemirror.net/\">this is </a>
  <strong><a href=\"http://prosemirror.net/\">a link</a></strong>
  <a href=\"http://prosemirror.net/\"> to a site</a>
</p>

Inline DOM nodes are flattened (i.e. don’t nest) in the editor view, so no, you can’t get links spanning multiple pieces of markup. (And yes, allowing people to bold something in the middle of a link is definitely a supported use case.)

Is the solution to use an inline node instead of a mark to represent links? I could then allow this inline node to have a child text node which can have any marks it wants.

That might work, once #114 is done, but it isn’t yet. Why do you need links to be single nodes?

Any a:hover styles will look wrong if the link is broken up into several links. I have an underline decoration and want the entire link to be underlined.

I see. But do you really need this kind of hover functionality in the editing view, as opposed to the output render?

Hmmm that’s a good point. I think that’s less than ideal but definitely a reasonable work around. This will work for the spell checking case but not for the (albeit weird) case of a user bolding the middle of a link.

Converting a document to HTML normally (by directly calling toDOM will not produce this kind of flat structure. The way the nodes are nested is determined by the way you specify the mark types in your schema (the ones defined first will be the outermost nodes).

1 Like

OH SNAP! That’s great! I’ll re-order my marks in the schema. This means the only negative is that I don’t have a:hover while editing which is totally live-able.

Thanks for the help!