How to use <br> instead of <br /> in CKeditor

Deadly 提交于 2019-12-08 08:14:49

问题


It's 2017 and it's the age of HTML5! In HTML5, the line break is <br>, NOT <br />. But for the life of it, I can't get CKeditor to ditch <br /> in favor of <br>.

The incorrect <br />'s are giving me all sorts of problems. Among them:

  • Failed code validation
  • (In Firefox) Using JavaScript's innerHTML on a code block that was created with <br />'s, returns <br>'s instead - which messes up comparisons about changes.

     

I found this old forum entry about the issue (in a related program, not in CKeditor itself):
http://ckeditor.com/forums/Support/are-not-validated-W3C-validator-How-change

But the suggested fix (changing config.docType in the config file) does NOT WORK!

I tried a bunch of different docTypes's, in both the top-level config.js and in core/config.js .

In top-level config.js , I tried:

config.docType = '<!DOCTYPE html>';

In core/config.js, I tried: docType: '<!DOCTYPE html>',

But nothing works! :(

I also tried to hunt down instances of <br /> in the multitudes of files, but didn't find any in the core part of CKeditor. I presume that the <br /> string gets created dynamically??

How can I get CKeditor to spit out <br> rather than <br /> ?

Thanks!


回答1:


Yay, it took some hardcore Googling (hard to phrase the search), but I found the answer! I hope this will help others.

Simply add:

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

What it does, from what I understand, is to wait for the core plugin "HTML Output Writer" to be loaded - and when it is, it modifies the "writer", which is a property of each editor instance. The above way applies the change to all editors, but it could also be done to individual editor instances (though I find it hard to imagine why anyone would want to do the latter.)

For more info, from the CKEditor4 documentation: How Do I Output HTML Instead of XHTML Code Using CKEditor?

All right, CKEditor rocks! :D



来源:https://stackoverflow.com/questions/41496028/how-to-use-br-instead-of-br-in-ckeditor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!