如何阻止 CKEditor 4 在插入时从文档中删除 <style> 和 <link href> 标签

How to stop CKEditor 4 from stripping <style> and <link href> tags from the document on insert

我的问题是 CKEditor 4 似乎在插入编辑器时剥离了某些数据,我已经验证数据在传递给 CK 之前是正确的。

我已经包含了

config.allowedContent = true;

这应该完全阻止 CK 格式化我的文本,但是当我使用 editor.insertHtml 方法并传入一大块 html 包含

<html lang="en-GB" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
    <link href="http://fonts.googleapis.com/css?family=Droid+Sans" rel="stylesheet" type="text/css"/>
    <link href="http://fonts.googleapis.com/css?family=Bree+Serif" rel="stylesheet" type="text/css"/>
    <link href="http://fonts.googleapis.com/css?family=Droid+Sans+Mono" rel="stylesheet" type="text/css"/>
    <link href="http://192.168.0.50/css/new/all.css?v=1" media="all" rel="stylesheet" type="text/css"/>
    <link href="http://192.168.0.50/css/new/templates.css?v=1" media="all" rel="stylesheet" type="text/css"/>
    <link href="http://192.168.0.50/css/pre_review/colors.css?v=1" rel="stylesheet" type="text/css"/>
    <link href="http://192.168.0.50/css/pre_review/paged_test.css?v=2" media="paged" rel="stylesheet"
        type="text/css"/>
    <link href="http://192.168.0.50/css/pre_review/bootstrap.min.css?v=1" media="all" rel="stylesheet"
        type="text/css"/>
    <link href="http://192.168.0.50/css/pre_review/main.css?v=1" rel="stylesheet" type="text/css"/>
    <style type="text/css">html { -ro-editable: true; }</style>
</head>
<body>

将其插入编辑器后,我查看了源代码,剩下的是

<html>
<head>
<title></title>
</head>
<body>
<p><!--?xml version="1.0" encoding="UTF-8"?--><!-- Comment by kp --><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<style type="text/css">html { -ro-editable: true; }
</style>

有人遇到过这个问题吗?

editor.insertHtml() 不能用于插入整个页面的 HTML,包括像 <html> 这样的标签。它只能用于粘贴等目的 - 因此插入 <body>.

的片段

我猜你只是想使用 editor.setData() method. And remember to initialise editor in the full page 模式。