简体   繁体   English

如何在 reactjs 的 CKEditor5 工具栏中添加下划线选项和 Alignment 选项

[英]How Can I add underline option & Alignment option in toolbar of CKEditor5 in reactjs

How can I add options as Text Alignment & Underline in CKEditor in reactjs, I tried but did not get success.如何在 reactjs 的 reactjs 中添加选项作为文本 Alignment 和 CKEditor 中的下划线,但没有成功。 Please help me请帮我

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} />

以供参考

Using the ClassicEditor removes some buttons like the "Underline, Subscript, Superscript".使用 ClassicEditor 会删除一些按钮,例如“下划线、下标、上标”。 You will need to use a Customized version of the editor and not the Classic version.您将需要使用编辑器的自定义版本,而不是经典版本。

I've come in contact with CKEditor team.我已经与 CKEditor 团队取得了联系。 They have sent me to their online builder: https://ckeditor.com/ckeditor-5/online-builder/他们已将我发送给他们的在线构建器: https://ckeditor.com/ckeditor-5/online-builder/

I've tried it and it looks simple enough to use.我已经尝试过了,它看起来很简单好用。 There are a lot of options so you'll need to go through it.有很多选项,所以你需要通过它 go 。

Basically, pick your Editor type, add plugins, choose your language, build and use the build.基本上,选择你的编辑器类型,添加插件,选择你的语言,构建和使用构建。

Hope it helps希望能帮助到你

I see the question is already answered, but I thought I could add how I solved this.我看到这个问题已经回答了,但我想我可以补充一下我是如何解决这个问题的。

While installing the ckeditor for react I used在安装 ckeditor 进行反应时,我使用了

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

in place of the example given in the docs代替文档中给出的示例

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

and then I followed the method of creating a decoupled editor as shown in the docs然后我按照文档中所示的创建解耦编辑器的方法

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;

This is for Angular, would be helpful if anyone looking for this.这是给 Angular 的,如果有人在找这个会很有帮助。

Reference: https://github.com/ckeditor/ckeditor5-angular/issues/156 1)参考: https://github.com/ckeditor/ckeditor5-angular/issues/156 1)

npm install --save ckeditor5-build-classic-plus npm install --save ckeditor5-build-classic-plus

  1. include in hmtl包含在 hmtl 中

<ckeditor (ready)="editorsReady($event)" [editor]="Editor" data="test" [config]="optionsNews"> <ckeditor (ready)="editorsReady($event)" [editor]="Editor" data="test" [config]="optionsNews">

  1. include in ts file where you are using the editor(eg any editor compoenent)包含在您使用编辑器的 ts 文件中(例如任何编辑器组件)

import ClassicEditor from 'ckeditor5-build-classic-plus';从'ckeditor5-build-classic-plus'导入ClassicEditor;

public editorsReady(editor) {
         editor.ui.getEditableElement().parentElement.insertBefore(
         editor.ui.view.toolbar.element,
       editor.ui.getEditableElement() );
       }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM