TinyMCE 编辑器中的换行符在预览中显示额外的行,而不是在代码中
我将 BBCode 插件与 TinyMCE 结合使用,发现预览和 HTML 代码之间的换行符显示不一样。
我在编辑器窗口中有以下几行:
This is line one
This is line three
第二行是空的。当我在 HTML 中查看此内容时,我得到以下内容。
This is line one
This is line three
没有多余的空行。
tinyMCE.init({
mode : "textareas",
theme : "advanced",
plugins : "bbcode",
entity_encoding : "raw",
remove_linebreaks : false,
force_p_newlines : false,
force_br_newlines : true,
forced_root_block : ''
});
我缺少什么?
I'm using the BBCode plugin with TinyMCE and see that line breaks are not showing the same between the preview and the HTML code.
I have the following lines in the editor window:
This is line one
This is line three
Line two is empty. When I'm viewing this in HTML I get the following.
This is line one
This is line three
Without the extra empty line.
tinyMCE.init({
mode : "textareas",
theme : "advanced",
plugins : "bbcode",
entity_encoding : "raw",
remove_linebreaks : false,
force_p_newlines : false,
force_br_newlines : true,
forced_root_block : ''
});
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我已经使用 Firefox 3.5.7 和 Google Chrome 4.0.223.11 在我的测试页面上进行了测试。
html:
可以使用简单的 CSS(“bbcode.css”)删除段落之间的空格,如下所示:
I have tested it on my test page with Firefox 3.5.7 and Google Chrome 4.0.223.11.
html:
The space between the paragraphs can be removed using a simple CSS ("bbcode.css") like this:
您可能需要使用
nl2br()
函数 输出 HTML 代码:,您可以将
force_p_newlines
选项设置为true
。我已经测试过它,你是对的,但这种行为只发生在 BBCode 插件上。我相信通过使用
tinyMCE.init
中的preformatted : true
选项,您应该能够解决您的问题。You probably need to use the
nl2br()
function to output your HTML code:Alternatively you could set the
force_p_newlines
option totrue
.I've tested it and you're right but the behavior only happens with the BBCode plugin. I believe that by using the
preformatted : true
option intinyMCE.init
you should be able to solve your problem.仅供参考 - 尽管围绕它的政治戏剧是使用
标签而不是使用
标签是“正确的做法”,但问题是我的想法是,我在电子邮件中发送内容 - 在电子邮件中,我无法控制标签上的 CSS(除非我想向每个标签添加内联 CSS) 。因此,
标签为最终用户添加了看似双倍行距的内容。我在网站上添加了 CSS 来消除间距,并且内容看起来不错。
因此,在使用
标签之后,然后使用转到“正确的方式”,我将返回使用
;再次标记...
FYI -- despite the political drama around it being the "right thing to do" to use
<p>
tags and not use<br>
tags, the issue for me was that I was sending content out in emails -- and in emails, I don't have control over CSS on the<p>
tags (unless I want to add inline CSS to every tag). So the<p>
tags were adding what appeared like double line spacing for end-users. I had added the CSS on my site to remove the spacing and the content looked fine there.So after using
<br>
tags, then going to the "right way" with<p>
, I'm going back to using<br>
tags again...这是执行此操作的另一种方法。只需更改 Enter 和 Shift+Enter 键的行为即可。
Here's another way of doing this. Just change the behaviour of Enter and Shift+Enter Keys.
从 TinyMCE 配置中,您可以选择换行符
http://www.tinymce.com/ wiki.php/Configuration3x:force_br_newlines
From TinyMCE configuration you can choose the beavhior of newlines
http://www.tinymce.com/wiki.php/Configuration3x:force_br_newlines
尝试添加配置对象
try adding in the config object
我有同样的问题。这是bbcode插件的解决方案:
I have the same problem. This is a solution for bbcode plugin:
使用 TinyMCE 4 我有同样的问题,但对我来说使用这个配置
with TinyMCE 4 i have the same problem but for me working this config