【问题标题】:How to use MathType plugin in CKEditor 5 using ReactJS?如何使用 ReactJS 在 CKEditor 5 中使用 MathType 插件?
【发布时间】:2020-04-15 14:13:15
【问题描述】:

我已经安装了三个包:

  1. @ckeditor/ckeditor5-react
  2. @ckeditor/ckeditor5-build-classic
  3. @wiris/mathtype-ckeditor5/src/plugin

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

这是我的示例代码:

<CKEditor
  data={input.value}
  editor={ClassicEditor}
  onChange={(event, editor) => {
    return input.onChange(editor.getData());
  }}
/>;

谁能解释我如何使用它? 谢谢。

【问题讨论】:

    标签: reactjs ckeditor ckeditor5 mathtype wiris


    【解决方案1】:

    这里是a link,您应该查看以了解如何将插件添加到 ckeditor。

    TL;DR:您应该创建一个包含您的插件(在您的情况下为 MathType 插件)的新构建,最简单的方法是使用他们的 online builder,然后您可以使用您生成的构建而不是 @987654323 @例如。

    我已经完成了这项工作并发布到 npm,你可以安装它:

    npm install ckeditor5-classic-with-mathtype

    这是一个使用 react 的例子:

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

    【讨论】:

    • 谢谢@Idriss AIT HAFID,真的很有帮助,拯救了我的一天
    • 很高兴它有帮助:)
    【解决方案2】:

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

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

    【讨论】:

    • 问题是如何使用完整的 MathType 编辑器,目前我在编辑器中得到 4-5 个符号。我订阅了wiris,但不知道在哪里使用密钥。
    • 使用包,您可以在编辑器中添加数学公式对吗?
    • 使用此软件包后,我可以获得具有某些功能的数学编辑器,但我需要为 mathType 编辑器提供的完整公式。检查下面的 url wiris.com/en/mathtype
    • 是的,这就是这个包提供的。还剩下什么功能?当您单击平方根图标时,您将看到一个数学类型编辑器。
    • 是的,我可以看到数学类型编辑器,但像这样:ibb.co/YydF2nk
    【解决方案3】:

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

    步骤如下:

    1. 包含在 index.html 中
    2. 在组件中渲染普通文本区域
    <textarea name="question" id="question" cols="100" rows="6"></textarea>
    
    1. 在 componentDidMount 函数中使用以下代码:
    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 标签。需要在组件中加载脚本:

    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);
    
    

    【讨论】:

      猜你喜欢
      • 2022-11-04
      • 2019-12-17
      • 2019-04-18
      • 2018-08-03
      • 1970-01-01
      • 2018-10-02
      • 2016-02-16
      • 2022-08-06
      • 2022-11-10
      相关资源
      最近更新 更多