添加
时删除不需要的换行符在CK编辑器中
当在 CKEditor 中加载包含一组段落的内容时,它会将我的
标记替换为
	
这意味着编辑器将转换此内容:
<p>paragraph 1</p>
<p>paragraph 2</p>
<p>paragraph 3</p>
最终结果是这样的:
<p>
paragraph 1</p>
<p>
paragraph 2</p>
<p>
paragraph 3</p>
如何修复它,以便 CKEditor 在看到段落标签时不会添加额外的换行符?
When loading content with a set of paragraphs in CKEditor, it replaces my <p>
tags with <p>
That means the editor converts this:
<p>paragraph 1</p>
<p>paragraph 2</p>
<p>paragraph 3</p>
into what ends up like this:
<p>
paragraph 1</p>
<p>
paragraph 2</p>
<p>
paragraph 3</p>
How do I fix it so that CKEditor doesn't add the extra newline characters when it sees the paragraph tags?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在其他地方(我很抱歉,我没有记下我从哪里得到它。),我找到了解决所有块级标签的这个问题的代码。对于我的项目,由于输出到 XML 并作为 CDATA 导入到其他应用程序,额外的换行符成为一个问题。
因此,在我的 ckeditor_config.js 文件中,在 CKEDITOR.editorConfig 函数之后,我输入了以下内容:
其中一些元素可能不需要这种处理;显然,可以根据您的需要轻松编辑 blockTags 数组。
Elsewhere (my apologies that I did not make a note of where I got it from.), I found code to fix this problem for all the block-level tags. For my project, the extra new-lines were a problem due to outputting to XML and importing into other applications as CDATA.
So, in my ckeditor_config.js file, after the CKEDITOR.editorConfig function, I put in this:
Some of those elements may not need this treatment; obviously the blockTags array can easily be edited to your needs.
将此行添加到 ckeditor.js 配置文件中:
有关 HTML Writer 格式的更多信息,请参阅
Add this line to the ckeditor.js configuration file:
More about the formatting of the HTML Writer can be found in Developers Guide: Output Formatting at CKSource Docs.
我相信有一个设置可以格式化代码,或者自动缩进或者类似的东西。其目的是使源代码更具可读性。我想它的有效性还有待商榷。
I believe there's a setting to format the code, or auto-indent or something along those lines. It was intended to make the source code more readable. It's effectiveness is open to opinion I guess.
如果您像我一样并且想在实例级别执行此操作并且不想触及配置文件,以便轻松更新/升级。那么这是另一个解决方案。
参考:输出格式
If you are like me and would like to do it at instance level and don't want to touch the configuration files so that it is easy to update/upgrade. Then here is another solution.
Reference: Output Formatting
像魅力一样工作的最佳解决方案:
编辑 contents.css 文件并设置段落样式,例如
Best solution that would work like a charm:
edit contents.css file and setting style for paragraphs e.g.