我想知道如何使用CKEditor 4 reactjs显示html。 它显示编辑器,但内联样式已删除,所有div标签都更改为P标签。
如何在不将div更改为P标签的情况下直接显示html
import React from "react";
import CKEditor from 'ckeditor4-react';
class Editor extends React.PureComponent{
constructor(props) {
super(props);
this.state = {
config: {
extraAllowedContent: 'div(*)',
allowedContent: true
}
emailbody: `
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body style="background-color: #DAD5CE; font-family:'browntt-regular', Verdana, Geneva, Tahoma, sans-serif">
<div class="content-box" style="display: block; align-items: center; justify-content: center; margin:25px 0">
<div style="height:100%; text-align: center;display:block; ">
<div style="font-weight: normal; font-size: 24pt; color: #000">order confirmation</div>
<div class="orderdate" style="font-size: 12pt; color: #51545D">order date:
<span style="color: #B39137;">${orderdate!''} </span>
</div>
</div>
</div>
</body>
</html>`
}
handleChange = value => {
this.setState({ emailbody: value });
}
render(){
<div>
<CKEditor
data={this.state.emailbody}
onChange={this.handleChange}
config={this.config}
/>
</div>
}
}
答案 0 :(得分:0)
要解决此问题,请使用“ react-ckeditor-component”而不是“ ckeditor4-react”,如下所示:
import CKEditor from 'react-ckeditor-component';
class Editor extends React.PureComponent{
constructor(props) {
super(props);
this.state = {
emailbody: `
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body style="background-color: #DAD5CE; font-family:'browntt-regular', Verdana, Geneva, Tahoma, sans-serif">
<div class="content-box" style="display: block; align-items: center; justify-content: center; margin:25px 0">
<div style="height:100%; text-align: center;display:block; ">
<div style="font-weight: normal; font-size: 24pt; color: #000">order confirmation</div>
<div class="orderdate" style="font-size: 12pt; color: #51545D">order date:
<span style="color: #B39137;">${orderdate!''} </span>
</div>
</div>
</div>
</body>
</html>`
}
handleChange = (event) => {
this.setState({
emailbody: event.target.value
});
};
render(){
<div>
<CKEditor
content={this.state.content}
config={{
extraAllowedContent: 'div(*)',
allowedContent: true
}}
events={{
change: this.handleChange
}}
/>
</div>
}
}
浪费了很多时间后,我得到了上述问题的解决方案,请您感激