Hi, xwiki community!
I want to implement a new syntax, but when user choose this syntax, I want to edit it with a custom editor.
for example, a new syntax called onlyoffice-word, when user choose this, I want to edit with a onlyoffice document editor inside an iframe.
I am aware of that there is a paid extension called onlyoffice connector, but I think a onlyoffice document should be treated as a special page(with custom content type, bound to custom editor), not an attachment.
We don’t associate editors to wiki syntax. We associate editors to data types (which is more generic). “Content that has a syntax” is such a data type (org.xwiki.rendering.syntax.SyntaxContent to be precise). So you can’t say “use this editor for Markdown and this other editor for HTML”. You can only say “use this editor for any text content that has a syntax associated, whatever that syntax” (of course the syntax is a parameter that the editor gets in order to load / configure the necessary modules).
Of course, you can define custom data types (such as “Markdown content” or “HTML content”) but since these data types are not used in XWiki Standard, you won’t be able to replace the editor used for the page content for instance. XWiki Standard considers that the data type of page content is org.xwiki.rendering.syntax.SyntaxContent so it looks for an editor associated to this data type. The reason for this is because the XWiki Rendering is polyglot so we don’t need a different editor per syntax: we just need to have the right syntax-to-XDOM parser and the right XDOM-to-syntax renderer.
You can do that easily: define an xclass to mark OnlyOffice wiki pages (by adding an xobject of that xclass to these OnlyOffice wiki pages) and then write a sheet to control how these pages are displayed and edited.
The Diagram Application, for instance, doesn’t define a new syntax or a new editor. It simply marks the diagram pages with a DiagramClass object and then from the DiagramSheet it reads the diagram XML from the page content and passes it either to the diagram viewer or diagram editor (i.e. draw.io library).
Thanks for the details. This actually corresponds to what I thought. I consider this to be a current XWiki limitation since I find the use case valid. We could want to say, use this editor when editing in wysiwyg for the XXX syntax (and if no editor is mapped for a given syntax, it would fall back to the editor for the SyntaxContent). It’s just that so far we’ve not had the need and nobody has asked for it.
Well, we can define a proxy / dispatcher editor, associated to org.xwiki.rendering.syntax.SyntaxContent that checks the syntax parameter and loads other editors, based on some other configuration (e.g. looks for the editor configured for the Markdown syntax). So there are ways to overcome this “limitation” in case we need to.