Technically, we can synchronize the realtime WYSIWYG editor with the realtime Wiki editor by:
- using two realtime sessions: one for the WYSIWYG editor instances and one for the Wiki editor instances
- implementing an algorithm to choose one of the WYSIWYG editors to be responsible for the sync, e.g. the oldest editor in the session
- the WYSIWYG editor responsible for the sync will use an agent (fake user) that connects to both realtime sessions
- when a remote change is received from the Wiki session, it will convert to annotated HTML and pass the result to the WYSIWYG session
- when a remote change is received from the WYSIWYG session, it will convert the HTML to wiki syntax and pass the result to the Wiki session
- Of course, the conversion between HTML and wiki syntax is async which means additional remote changes can be received while waiting for the conversion, but we know how to handle this (because we do it already when the editor content is reloaded after a macro is inserted or updated)
The problem is that this creates a very bad editing experience:
- when we synchronize the WYSIWYG editor content we know that the HTML is valid / complete. It's not the same with wiki syntax: e.g. the sync may happen before the user closes the macro call they just opened, or before they close the macro parameter value, and so on. The rendering doesn't fail, but the output is not what the user intents and this leads to very surprising effects on the WYSIWYG side. Imagine Alice using the WYSIWYG editor to edit the Sandbox page and Bob using the Wiki editor. Bob wants to insert a macro at the start of the content. Writes the start macro syntax, the sync is triggered, and now the entire content is read-only for Alice because the rendering considers that the entire content is inside the macro that was opened by Bob but not closed.
- the WYSIWYG editor normalizes the wiki syntax. This means that for someone using the wiki editor it will be like having an "automatic formatter" that triggers automatically whenever you type...
For these reasons I don't think it makes sense to sync the WYSIWYG editor with the Wiki syntax (Source area). This means that the Source mode of the WYSIWYG editor won't be part of the realtime session:
- you will be able to switch to Source to see the wiki syntax
- but if you edit the source and switch back to WYSIWYG then you risk overwriting the remote changes that may have been received in the meantime
We can try to perform a 3-way merge when switching back to WYSIWYG (between the HTML before the switch to Source, the HTML with your Source changes and the HTML with the remote changes from other users) but if there are merge conflicts then the user will have to resolve them. |