首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用MathType插件在CKEditor 5中使用ReactJS?

如何使用MathType插件在CKEditor 5中使用ReactJS?
EN

Stack Overflow用户
提问于 2020-04-15 14:13:15
回答 3查看 3.3K关注 0票数 8

我安装了三个软件包:

  1. @ckeditor/ckeditor 5-反应性
  2. @ckeditor/ckeditor 5-构建-经典
  3. @wiris/mathtype-ckeditor5 5/src/plugin

我可以设置简单的ckeditor5,但不知道如何在这个编辑器中使用MathType插件。

下面是我的示例代码:

代码语言:javascript
复制
<CKEditor
  data={input.value}
  editor={ClassicEditor}
  onChange={(event, editor) => {
    return input.onChange(editor.getData());
  }}
/>;

有人能解释我怎么用这个吗?谢谢。

EN

回答 3

Stack Overflow用户

发布于 2020-04-23 19:37:33

这里是一个链接,您应该了解如何向ckeditor添加插件。

TL;DR:您应该创建一个包含插件的新构建(在您的例子中是MathType插件),最简单的方法是使用它们的在线建设者,然后可以使用您生成的构建,而不是@ckeditor/ckeditor5-build-classic

我已经完成了这项工作,并将其发布给国家预防机制,您可以通过以下方式安装它:

npm install ckeditor5-classic-with-mathtype

下面是一个与react一起使用它的示例:

代码语言:javascript
复制
import CKEditor from '@ckeditor/ckeditor5-react';
import ClassicEditor from 'ckeditor5-classic-with-mathtype';

...

render() {
        return (
                <CKEditor
                    editor={ClassicEditor}
                    config={{
                        toolbar: {
                            items: [
                                'heading', 'MathType', 'ChemType',
                                '|',
                                'bold',
                                'italic',
                                'link',
                                'bulletedList',
                                'numberedList',
                                'imageUpload',
                                'mediaEmbed',
                                'insertTable',
                                'blockQuote',
                                'undo',
                                'redo'
                            ]
                        },
                    }}
                    data="<p>Hello from CKEditor 5 with MathType!</p>"
                    onInit={editor => {
                        // You can store the "editor" and use when it is needed.
                        // console.log( 'Editor is ready to use!', editor );
                    }}
                />
        );
    }
票数 8
EN

Stack Overflow用户

发布于 2020-05-21 07:55:14

https://www.npmjs.com/package/ckeditor5-build-classic-mathtype,一个定制经典编辑器构建的软件包,它添加了mathtype插件。

代码语言:javascript
复制
import CKEditor from '@ckeditor/ckeditor5-react'
import ClassicEditor from 'ckeditor5-build-classic-mathtype'

...

render() {
        return (
                <CKEditor
                    editor={ClassicEditor}
                    data="<p>Hello from CKEditor 5 with MathType!</p>"
                    onInit={editor => {
                        // You can store the "editor" and use when it is needed.
                        // console.log( 'Editor is ready to use!', editor );
                    }}
                />
        )
    }
票数 1
EN

Stack Overflow用户

发布于 2020-05-15 14:41:46

我使用过MathType编辑器在ReactJs中使用Javascript。

以下是步骤:

  1. 包括在index.html中
  2. 呈现组件中的正常文本区域
代码语言:javascript
复制
<textarea name="question" id="question" cols="100" rows="6"></textarea>
  1. 在componentDidMount函数中使用以下代码:
代码语言:javascript
复制
let ED = window.CKEDITOR;
    let mathElements = [
          'math',
          'maction',
          'maligngroup',
          'malignmark',
          'menclose',
          'merror',
          'mfenced',
          'mfrac',
          'mglyph',
          'mi',
          'mlabeledtr',
          'mlongdiv',
          'mmultiscripts',
          'mn',
          'mo',
          'mover',
          'mpadded',
          'mphantom',
          'mroot',
          'mrow',
          'ms',
          'mscarries',
          'mscarry',
          'msgroup',
          'msline',
          'mspace',
          'msqrt',
          'msrow',
          'mstack',
          'mstyle',
          'msub',
          'msup',
          'msubsup',
          'mtable',
          'mtd',
          'mtext',
          'mtr',
          'munder',
          'munderover',
          'semantics',
          'annotation',
          'annotation-xml'
      ];

    ED.plugins.addExternal( 'ckeditor_wiris',  'https://www.wiris.net/demo/plugins/ckeditor/', 'plugin.js' );

    ED.replace( 'question', {
        extraPlugins: 'ckeditor_wiris',
        // For now, MathType is incompatible with CKEditor file upload plugins.
        removePlugins: 'filetools,uploadimage,uploadwidget,uploadfile,filebrowser,easyimage',
        height: 320,
        // Update the ACF configuration with MathML syntax.
        extraAllowedContent: mathElements.join( ' ' ) + '(*)[*]{*};img[data-mathml,data-custom-editor,role](Wirisformula)'
    } );

如果要检查react组件中的Ml标记,请执行以下操作。需要在组件中加载脚本:

代码语言:javascript
复制
const script = document.createElement("script");
script.src ='https://www.wiris.net/demo/plugins/app/WIRISplugins.js?viewer=image;
script.async = true;
document.body.appendChild(script);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61230962

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档