如何使用< br>代替< br />在CKeditor中 [英] How to use <br> instead of <br /> in CKeditor

查看:116
本文介绍了如何使用< br>代替< br />在CKeditor中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在是2017年,HTML5时代已经来临!在HTML5中,换行符为< br> ,而不是< br /> 。但是终其一生,我无法让CKeditor放弃< br /> 而赞成< br>

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

错误的< br /> 给了我各种各样的问题。其中:

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


  • 代码验证失败

  • (在Firefox中)使用JavaScript的innerHTML用< br /> 创建的代码块,返回< br> -弄乱了有关更改的比较。

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

 

我发现了这个有关该问题的旧论坛条目(在相关程序中,而不是在CKeditor本身中):

http://ckeditor.com/forums/Support/are-not-validated-W3C-validator-How-change

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

但是建议的修复方法(在配置文件中更改 config.docType )无效!

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

我在顶级config.js和core / config.js中都尝试了一堆不同的docType,

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

顶级config.js ,我尝试过:

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

core / config.js 中,我尝试过:
docType:'< !DOCTYPE html>',

但是没有任何效果! :(

But nothing works! :(

我还尝试在众多文件中查找< br /> 的实例,但是在CKeditor的核心部分没有找到任何内容。我认为< br /> 字符串是动态创建的?

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??

我如何让CKeditor吐出< br> 而不是< br />

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

谢谢!

推荐答案

是的,

只需添加:

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

据我了解,它的作用是等待核心插件 HTML Output Writer 加载-修改后,它会修改 writer ,这是每个编辑器实例的属性。上面的方法将更改应用于所有编辑器,但是也可以对单个编辑器实例进行更改(尽管我很难想象为什么有人会想要做后者。)

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

有关更多信息,请参阅CKEditor4文档:
如何输出HTML

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

好吧,CKEditor震撼了! :D

All right, CKEditor rocks! :D

这篇关于如何使用&lt; br&gt;代替&lt; br /&gt;在CKeditor中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆