Reputation: 773
I would like to know how to display the html as such using CKEditor 4 reactjs. It displays the editor but the inline style are removed and all div tag changed to P tag.
How to dsiplay the html as it is without changing div to P tag
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>
}
}
Upvotes: 2
Views: 1206
Reputation: 440
To fix this issue please use 'react-ckeditor-component' rather than the 'ckeditor4-react' like this:
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>
}
}
After wasting too many time, I got this solution of the above question please appreciate it
Upvotes: 1