我正在使用 CK 编辑器并将初始数据传递给编辑器,如下所示
import React from 'react';
import CKEditor from '@ckeditor/ckeditor5-react';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
classEditor extends React.Component{
constructor(props){
super(props)
this.state={
editorState:'<div class="main"><div class="child-1"><div>Iam inside </div></div><div class="child-2">Child 2</div></div>'
}
}
render(){
return <CKEditor
editor={ClassicEditor}
data={this.state.editorState}
onInit={editor => {
// You can store the "editor" and use when it is needed.
console.log('Editor is ready to use!', editor);
}}
config={{
allowedContent:true,
extraAllowedContent:true
}}
onChange={(event, editor) => {
const data = editor.getData();
this.handleEditorChange(data);
console.log(data);
}}
/>
}
}
当调用 OnChange 处理程序时,它会将最初传递的 html 更改为类似这样的内容
<p>Iam inside</p><p>Child 2</p>
如何停止 CK 编辑器用 p 标签替换 div 标签并允许自定义样式和类名
最佳答案
尼基尔 关于您的帖子,您似乎要在编辑器中为内联文本创建自定义主题。我不确定这是否正确。 但是,如果是这样,您可以自定义编辑器主题并将其用于您的目的。 CKEditor 具有强大的内置功能。 另外,如果你想自定义编辑器,你也可以这样做。 请查看以下链接: https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/basic-api.html#creating-an-editor https://ckeditor.com/docs/ckeditor5/latest/framework/guides/deep-dive/ui/theme-customization.html 希望这有帮助。
关于ckeditor - CK Editor div 标签被替换为 p 标签(React JS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63986665/