(Tinymce)在firefox中使用getContent{format:text}时,换行符会被剥离

(Tinymce)在firefox中使用getContent{format:text}时,换行符会被剥离,tinymce,Tinymce,我试图在firefox中键入几行,并希望使用getContent{format:text}只获取内容 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.

我试图在firefox中键入几行,并希望使用getContent{format:text}只获取内容

 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?
内容如下:(我有三行,每行从最左边的位置开始)
“如果需要,发短信给我
有
机会“
它在chrome中工作,在运行getContent时提供以下格式。
...
如果有,发短信给我
有
机会
...
但在firefox中,我得到了:
如果有机会发短信给我
它似乎把断线剥掉了。有人能帮忙吗?

为确保此类情况不会发生,您应该使用

标记,而不是常规的换行符(ctrl+return)。这是html代码中的默认过程。

我通过使用DOMParser()解决了这个问题


在这种情况下,我们仍然可以保留换行符。但请注意,不要更改tinymce配置以启用
。在TinyMCE 4+中,没有禁用剥离断线的选项。对我来说,一个有点脏的黑客工作-只需在初始化TinyMCE之前用

标记替换换行符:

//imagine that your textarea is called textarea#message
var a = $("textarea#message").val();
a = a.replace(/\n/g, '<br />');
$("textarea#message").val(a);
//假设您的textarea被称为textarea#message
var a=$(“textarea#message”).val();
a=a.替换(/\n/g,
); $(“文本区域#消息”).val(a);
如果需要不带

但带换行符的文本,只需应用相同的转换,反之亦然:

var a = $("textarea#message").val();
a = a.replace(/<br\s*[\/]?>/gi, "\n");
$("textarea#message").val(a);
var a=$(“textarea#message”).val();
a=a.replace(//gi,“\n”);
$(“文本区域#消息”).val(a);

参加聚会可能有点晚,但我碰巧遇到了同样的问题。firefox似乎在插入文本区域的文本中存在换行符问题。我的解决方案是这样的:

var text = text.replace("\r\n", "\\r\\n");
我猜FireFox是Slash(es)的超级粉丝

对于完整的解决方案,我使用了以下代码,它不使用format:text,而是使用format:html,首先由DOMParser解析:

var text = editor.getContent({ format: 'html' });
var doc = new DOMParser().parseFromString(text, 'text/html');
text = doc.body.textContent.replace("\r\n", "\\r\\n");
如果您仍然希望在代码中显示标记以及标记中的文本链接,请在DOMParser之前添加以下行:

    text = text.replace(/<a.*href="(.*?)".*>(.*?)<\/a>/gi, ' $2: $1 ');
text=text.replace(/

为此:

  • 转到某个页面://some.link

干杯!

谢谢您的回复。请您再详细说明一下。我的目标是从tinymce中提取没有格式的单词。这就是我使用getContent{format:text}. (我正在tinymce之外开发拼写检查)。您建议使用
作为标记。如何在tinymce中设置它?我想知道在我将文本传递给tinymce之前和之后是否有一种方便的方法来执行这两个javascript代码?
    text = text.replace(/<a.*href="(.*?)".*>(.*?)<\/a>/gi, ' $2: $1 ');