ckeditor / ckeditor5

Powerful rich text editor framework with a modular architecture, modern integrations, and features like collaborative editing.
https://ckeditor.com/ckeditor-5
Other
9.61k stars 3.7k forks source link

Loss of tag name capitalization in XmlDataProcessor.toData() when retrieving editor content as XML #15278

Open jzimpel opened 1 year ago

jzimpel commented 1 year ago

📋 Steps to reproduce

  1. Apply XmlDataProcessor as data processor of the editor
  2. Define a camel cased XML tag following https://ckeditor.com/docs/ckeditor5/latest/framework/deep-dive/schema.html
  3. Set data to the editor containing the camel cased XML tag
  4. Call the 'toData()' method of the editor and have a look at the output.

✔️ Expected result

The output of 'toData()' should contain the XML element with a camel cased tag name (the original case should be kept)

❌ Actual result

The output of 'toData()' contains the XML element with a tag name in lower case

❓ Possible solution

I managed to solve the problem by replacing the HTML document in the constructor of DomConverter with an XML document:

Original DomConverter source code:

this._domDocument = this.renderingMode === 'editing' ? global.document : global.document.implementation.createHTMLDocument('');

Modified DomConverter source code:

this._domDocument = this.renderingMode === 'editing' ? global.document : global.document.implementation.createDocument(null, null);

The issue is caused by the usage of an HTML document, as the HTMLDocument.createElement() method converts all tag names to lowercase. See https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement#tagname : "When called on an HTML document, createElement() converts tagName to lower case before creating the element." So, a default document should be used.

Maybe it would be possible to implement an option similar to the 'keepOriginalCase' option of DomConverter.domToView() , which when set true would cause the DomConverter to use a Document instead of an HTMLDocument.

💻 Version of CKEditor 37.1.0

CKEditorBot commented 2 weeks ago

There has been no activity on this issue for the past year. We've marked it as stale and will close it in 30 days. We understand it may still be relevant, so if you're interested in the solution, leave a comment or reaction under this issue.