如何在 CKEditor5 的内容中允许自定义 HTML 标签和 JavaScript?

问题描述 投票:0回答:0

看起来,

CKEditor 5
正在做一些
sanitization
,所以自定义标签和
Javascript
代码从内容中删除。 需要什么配置才能允许
custom html tags
CKEditor5
中的 java 脚本代码?

下面是我的

React component

import React from 'react';
import { CKEditor } from "@ckeditor/ckeditor5-react";
import ClassicEditor from "@ckeditor/ckeditor5-build-classic";
import * as PropTypes from 'prop-types';

const HTMLEditor = ({ setHtml, content }) => {

  return (
    <div>
      <CKEditor
        editor={ClassicEditor}
        data={content}
        onChange={(event, editor) => {
          setHtml(editor.getData());
        }}
        config={ {
          toolbar: [ 'bold', 'italic' ],
          allowedContent: true,
          extraAllowedContent: '*(*);*{*}'
        } }
        onInit={editor => {
          console.log(editor);
          debugger;
          editor.config.allowedContent = true;
          editor.config.extraAllowedContent = '*(*)';
        }}
      />
    </div>
  );
}

export default HTMLEditor;

我尝试添加以下配置,但似乎不起作用:

config={ {
          toolbar: [ 'bold', 'italic' ],
          allowedContent: true,
          extraAllowedContent: '*(*);*{*}'
        } }

以下是依赖项:

"@ckeditor/ckeditor5-build-classic": "^37.0.1",
"@ckeditor/ckeditor5-react": "^6.0.0",
reactjs ckeditor5
© www.soinside.com 2019 - 2024. All rights reserved.