Superb article on building a real time rich text editor: https://ckeditor.com/blog/Lessons-learned-from-creating-a-rich-text-editor-with-real-time-collaboration/
Discusses operational transforms with hierarchical text (e.g. you edit text whilst the other user makes part of it a link) and markers (persistent regions that automatically move when you edit).