(Tinymce) 换行符在使用 getContent{format:text} 时在 Firefox 中被剥离 [英] (Tinymce) Line breaks get stripped off in firefox while using getContent{format:text}

查看:78
本文介绍了(Tinymce) 换行符在使用 getContent{format:text} 时在 Firefox 中被剥离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 Firefox 中输入几行,并希望使用 getContent{format: text} 来仅获取内容.

I was trying to type the few lines in firefox and expect to use getContent{format: text} to only fetch the content.

 Here is the content: (I have three lines and each start with the leftmost postion)
 "text me if
 there is
 a chance"

 It works in chrome that it gives the following format when running getContent.
 ...
 <body>
 text me if

 there is

 a chance
 </body>
 ...

 However in firefox I got:

  <!DOCTYPE html>
  <html>
  <head>
  </head>
  <body>
  text me ifthere isa chance
  </body>
  </html>

 It seems to strip off the line break. Could someone help on this?

推荐答案

在 TinyMCE 4+ 中,没有禁用剥离换行符的选项.对我来说,一个小小的肮脏的黑客工作 - 只需在初始化 TinyMCE 之前用 <br> 标签替换换行符:

In TinyMCE 4+ there is no option to disable stripping off line breaks. For me a littly dirty hack worked - just replace line breaks with <br> tags before initializing TinyMCE:

//imagine that your textarea is called textarea#message
var a = $("textarea#message").val();
a = a.replace(/\n/g, '<br />');
$("textarea#message").val(a);

如果您需要没有 <br> 但带有换行符的后续文本,只需应用相同的转换,反之亦然:

If you need afterwards text without <br> but with line breaks, just apply the same transformation vise versa:

var a = $("textarea#message").val();
a = a.replace(/<br\s*[\/]?>/gi, "\n");
$("textarea#message").val(a);

这篇关于(Tinymce) 换行符在使用 getContent{format:text} 时在 Firefox 中被剥离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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