1

Last week i posted a question that CKEditor wasn't maintaining the trailing slash of the
element. This though had a simple solution. Jquery .replace("<br>", "<br />"). This will be done when the Html is read from the Editor.

It's not a solution that will win a price award. but it worked. (The old post has been removed. because it was project related. and not interesting for other people)

Now the following problem <img> needs to be generated as <img />. The problem stays that the Ckeditor isn't keeping the trailing slash for self closing elements.

Someone told me on the other topic(That's deleted), that possibly we are changing settings of the HTMLWriter plugin. What should be causing the problem. I know the code we are using very good and i am sure that we didn't configure any settings of the html writer.

Besides that we only added custom plugins to the Ckeditor. And we had to shutdown the ACF because it was creating to much problems.

Sadly i can't share any code because it's code of the client.

But does anyone know a simple solution to put the trailing slash? Or if you have had the same problem, and have a solution feel free to anwser.

Spons
  • 1,593
  • 1
  • 17
  • 46
  • Not really an answer but this might explain why it's doing this. In html self closing tabs aren't necessary. In xhtml it is but in html
    is just as valid as . That said, I tested with jquery and it seems to render those tags without trailing slashes. if you do $(element).html() it will strip them all. As far as I can tell, this shouldn't be a problem for any html parser unless you're passing the html to a xml parser, it will break.
    – Loïc Faure-Lacroix Jun 11 '13 at 13:45
  • That said, one possible answer would be to use a xhtml doctype instead. And the browser might render elements as it should. – Loïc Faure-Lacroix Jun 11 '13 at 13:48
  • Will try, because as you suggested i need to pass the html to a xml parser. – Spons Jun 11 '13 at 16:18
  • 2
    I've said that and I'll repeat that again - CKEditor by default produces trailing slashes. It uses writer which serializes pseudo DOM tree, so it has nothing to do with DOM or other native things. **Unless** you have changed some configuration options or disabled htmlwriter plugin. – Reinmar Jun 11 '13 at 18:40
  • I know that. And that's exactly why i am asking if someone knows a fast solution to solve this. or to add the needed slashes to the html. So that i can read it with a XML parser. – Spons Jun 11 '13 at 22:41

2 Answers2

2

Fix for CKEditor 4.x is following:

CKEDITOR.on('instanceReady', function(ev) {
    // Ends self closing tags the XHTML way, like <br />.
    ev.editor.dataProcessor.writer.selfClosingEnd = ' />';
});

Paste this code into config.js after CKEDITOR.editorConfig = function( config ) { ... }.

  • Thanks for still trying to solve this. Do it isn't a needed topic anymore. Besides that i don't think that it was the solution for my case back then, because i tried it. Besides that, the the configuration that you specified above is the same by default, as far as i remember. – Spons Feb 12 '14 at 07:19
  • Yes, it is default. I use this code to have
    instead of
    .
    – Ariel Bogdziewicz Feb 13 '14 at 13:18
0

MY answer would be:

that i never found a solution. After this we looked up and Xhtml validator. And this one fixed all closing tag problems.

Thanks for the effort anyway

Spons
  • 1,593
  • 1
  • 17
  • 46