如何在tinyEditor中设置带有换行符和html标签的内容

How to set content with line break and html tags in tinyEditor

我将 tinymce 编辑器 的内容保存在 MySQL table 中,并想粘贴我从数据库返回编辑器。
我使用 htmlentities() 函数对输入进行编码,将其保存到数据库中,然后使用 html_entity_decode() 对内容进行解码 在显示之前。
<?php echo html_entity_decode($content->post); ?> 将输出:

<p>adf adf adfadf aadf <img src="images/k0RpgvZ.png" alt="image" width="27" height="18" /></p>

我面临两个问题:

  1. 如何将此内容显示为 html,而不仅仅是文本?
  2. 我还想使用从数据库中检索到的值来设置 tinyEditor 的内容。 这个代码片段就是这样做的(取自tiny blog)。
tinymce.init({
    selector: '#myTextarea',
    setup: function (editor) {
      editor.on('init', function (e) {
        editor.setContent('<?php echo $content->post; ?>');
      });
    }
  });

但是,它仅在 $content->post 包含单个单词时有效(没有 space,没有换行符,没有特殊字符)。
一旦出现换行符或 space,...,我就会收到错误消息:

Uncaught SyntaxError: '' string literal contains an unescaped line break

如何处理这些问题?

试试这个:

editor.setContent(`<?php echo $content->post; ?>`);