How to implement new syntax?

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.

what’s the steps I need to do ?

Hi,

For implementing the new syntax, see https://rendering.xwiki.org/xwiki/bin/view/Main/Extending/

Fro the editor part, I’m not sure. There’s https://extensions.xwiki.org/xwiki/bin/view/Extension/Edit%20Module#HConfiguretheDefaultEditor but I don’t know if you say which editor to use based on a syntax. @mflorea would you know?

Thanks

Thanks, your information is helpful, I also readed those tutorials, the missing part is how to register a new editor at client side?

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.

hmm are you sure you need a new syntax in the end? what would be that syntax?

It seems you might just want to use a different editor for an existing syntax (like HTML or XHTML), no?

What are you editing exactly? Doc content? Attachment?

to view/edit docx files with onlyoffice, I have already tried a new rending macro, but it seems a little weird:
image

a onlyoffice editor inside a ckeditor :roll_eyes:, it make no sense to add other content around an word document.

sorry for my poor english…

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).

Hope this helps,
Marius

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.

ok so you don’t want a new rendering syntax. Syntaxes are not for attachments but for page content.

@mflorea thanks for your help. can you give more details about the sheet concept ?

take Diagram application as example, what’s the meaning of code below:

<object>
    <name>Diagram.DiagramClass</name>
    <number>0</number>
    <className>XWiki.ClassSheetBinding</className>
    <guid>73c96dda-5fb8-4f25-a22c-34bd6c64e78f</guid>
    <class>
      <name>XWiki.ClassSheetBinding</name>
      <customClass/>
      <customMapping/>
      <defaultViewSheet/>
      <defaultEditSheet/>
      <defaultWeb/>
      <nameField/>
      <validationScript/>
      <sheet>
        <customDisplay/>
        <disabled>0</disabled>
        <name>sheet</name>
        <number>1</number>
        <picker>0</picker>
        <prettyName>Sheet</prettyName>
        <size>30</size>
        <unmodifiable>0</unmodifiable>
        <validationMessage/>
        <validationRegExp/>
        <classType>com.xpn.xwiki.objects.classes.StringClass</classType>
      </sheet>
    </class>
    <property>
      <sheet>Diagram.DiagramSheet</sheet>
    </property>
  </object>
  <object>
    <name>Diagram.DiagramClass</name>
    <number>1</number>
    <className>XWiki.DocumentSheetBinding</className>
    <guid>0f50e355-cab4-4f90-91f2-38792f60c807</guid>
    <class>
      <name>XWiki.DocumentSheetBinding</name>
      <customClass/>
      <customMapping/>
      <defaultViewSheet/>
      <defaultEditSheet/>
      <defaultWeb/>
      <nameField/>
      <validationScript/>
      <sheet>
        <customDisplay/>
        <disabled>0</disabled>
        <name>sheet</name>
        <number>1</number>
        <picker>0</picker>
        <prettyName>Sheet</prettyName>
        <size>30</size>
        <unmodifiable>0</unmodifiable>
        <validationMessage/>
        <validationRegExp/>
        <classType>com.xpn.xwiki.objects.classes.StringClass</classType>
      </sheet>
    </class>
    <property>
      <sheet>XWiki.ClassSheet</sheet>
    </property>
  </object>

.

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.

It seems you need to go through https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Tutorials/FAQTutorial/ . See also https://extensions.xwiki.org/xwiki/bin/view/Extension/Sheet+Module (but it’s probably linked from the tutorials).