【问题标题】:How Can I add underline option & Alignment option in toolbar of CKEditor5 in reactjs如何在 reactjs 的 CKEditor5 工具栏中添加下划线选项和对齐选项
【发布时间】:2020-08-18 21:57:06
【问题描述】:

如何在 reactjs 的 CKEditor 中添加选项作为文本对齐和下划线,我试过但没有成功。 请帮帮我

text-editor.js

import React from 'react'
import CKEditor from '@ckeditor/ckeditor5-react';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';

const TextEditor = ({handleChildClick}) => {
    return (
        <div className="container">
            <CKEditor
                editor={ ClassicEditor }
                onChange={ ( event, editor ) => {
                    const data = editor.getData();
                    handleChildClick(data)
                } }
            />
            <style>
                {`
                .ck-content { height: 150px; }
                `}
            </style>
        </div>
    );
}; 
export default TextEditor
Parent.js

<TextEditor handleChildClick={getDataFromTextEditor} />

【问题讨论】:

    标签: reactjs ckeditor options text-alignment underline


    【解决方案1】:

    我看到问题已经回答了,但我想我可以补充一下我是如何解决这个问题的。

    在为我使用的 react 安装 ckeditor 时

    npm install --save @ckeditor/ckeditor5-react @ckeditor/ckeditor5-build-decoupled-document
    
    

    代替文档中给出的示例

    npm install --save @ckeditor/ckeditor5-react @ckeditor/ckeditor5-build-classic
    
    

    然后我按照文档中显示的创建解耦编辑器的方法

    import { CKEditor } from '@ckeditor/ckeditor5-react';
    import DecoupledEditor from '@ckeditor/ckeditor5-build-decoupled-document';
    
    class App extends Component {
        editor = null;
    
        render() {
            return (
                <div className="App">
                    <h2>CKEditor 5 using a custom build - decoupled editor</h2>
                    <CKEditor
                        onReady={ editor => {
                            console.log( 'Editor is ready to use!', editor );
                            editor.ui.getEditableElement().parentElement.insertBefore(
                                editor.ui.view.toolbar.element,
                                editor.ui.getEditableElement()
                            );
    
                            this.editor = editor;
                        } }
                        onError={ ( { willEditorRestart } ) => {
    
                            // This is why you need to remove the older toolbar.
                            if ( willEditorRestart ) {
                                this.editor.ui.view.toolbar.element.remove();
                            }
                        } }
                        onChange={ ( event, editor ) => console.log( { event, editor } ) }
                        editor={ DecoupledEditor }
                        data="<p>Hello from CKEditor 5's decoupled editor!</p>"
                        config={ /* the editor configuration */ }
                    />
            );
        }
    }
    
    export default App;
    

    【讨论】:

      【解决方案2】:

      使用 ClassicEditor 可以删除一些按钮,例如“下划线、下标、上标”。您将需要使用编辑器的自定义版本,而不是经典版本。

      我已经与 CKEditor 团队取得了联系。他们已将我发送给他们的在线构建器: https://ckeditor.com/ckeditor-5/online-builder/

      我试过了,它看起来很简单好用。有很多选择,所以你需要通过它。

      基本上,选择您的编辑器类型,添加插件,选择您的语言,构建并使用构建。

      希望对你有帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-20
        • 2011-03-11
        • 2018-07-20
        • 1970-01-01
        相关资源
        最近更新 更多