将以下内容添加到您的配置文件CKEditor 文件:
config.enterMode = CKEDITOR.ENTER_BR;
Example:
...
CKEDITOR.editorConfig = function (config)
{
config.enterMode = CKEDITOR.ENTER_BR;
...
};
Details
The configuration setting that controls this behavior is based on what you want to happen when the user presses Enter.
Just in case someone who's new to working with HTML reads this, I'm including some basic explanation of the concepts involved and why a tag will need to be inserted when the Enter key is pressed.
我们知道,如果我们在 HTML 文档中输入一些文本,然后在新行中添加其他文本,浏览器不会将文本显示为两行,它会忽略任何回车符,并将字符之间的多个空格压缩为单个空格空间。
以下 HTML:
qwer
tyui
将呈现为:
奎尔蒂伊
因此编辑器需要插入一个 HTML 标签来告诉浏览器应该在新行上显示第二组文本。
控制它的配置设置是config.enterMode
它提供了三个选项:
1 - 插入段落
The default setting creates a paragraph element each time Enter is pressed:
config.enterMode = CKEDITOR.ENTER_P; // inserts `<p>...</p>`
2 - 插入“div”
您可以选择创建一个div
元素而不是段落:
config.enterMode = CKEDITOR.ENTER_DIV; // inserts `<div></div>`
3 - 插入中断(您正在寻找的设置)
如果您不想将文本换行,您可以选择插入换行标记:
config.enterMode = CKEDITOR.ENTER_BR; // inserts `<br />`
CKEditor 文档表明使用ENTER_BR不推荐设置 http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.enterMode:
注意:建议使用CKEDITOR.ENTER_P
由于其语义价值和正确性而设置。编辑器针对此设置进行了优化。
另一个相关设置“autoParagraph”
还有第二个设置可以控制类似的情况 -config.autoParagraph
。它如何发挥作用取决于config.enterMode
上面讨论的设置。
autoParagraph
确定是否内联元素,例如span
被包裹在块元素中(p
or div
)由指定enterMode
环境。默认情况下是包装内联元素,因此如果您输入这样的跨度(作为 HTML):
<span>asdfg</span>
它将被包裹在 p 或 div 元素中,如下所示:
<p><span>asdfg</span></p>
or this:
<div><span>asdfg</span></div>
如果将其设置为,则内联元素将不会被换行false
或者如果你设置enterMode
to CKEDITOR.ENTER_BR
.
CKEditor 文档包含以下注释:config.autoParagraph http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.autoParagraph:
注意:更改默认值可能会带来不可预测的可用性问题。
更多设置
还有另外三个设置与此主题有些相关:
config.fillEmptyBlocks
config.forceEnterMode
config.ignoreEmptyParagraph
参考
可用配置选项的完整列表可以在此处找到:
- CKEDITOR.config - CKEditor 3 JavaScript API 文档 http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html
- CKEDITOR.config - CKEditor 4 文档 http://docs.ckeditor.com/#!/api/CKEDITOR.config