简体   繁体   English

如何使用 TinyMCE 设置自定义组件的样式?

[英]How to styling custom components with TinyMCE?

I am using React with webPack with tinyMCE and I have a styling issue.我将 React 与 webPack 与 tinyMCE 一起使用,但我遇到了样式问题。

I created my own btn and on click I create my html structure with classes.我创建了自己的 btn,单击时我创建了带有类的 html 结构。 like this :像这样

<div class="test" ><p>' + date + '</p></div><p></p>'

I tried importing the stylesheet into the file where the editor is used, but it didn't help.我尝试将样式表导入使用编辑器的文件中,但没有帮助。 How to correctly connect styles using webPack and react?如何使用 webPack 正确连接 styles 并做出反应?

var page1Config = {
  title: 'Redial Demo - Page 2',
  body: {
    type: 'panel',
    items: [
      {
        type: 'input',
        name: 'date',
        label: 'Введите Фразу',
        items: [
          { value: 'meow', text: 'Cat' },
          { value: 'woof', text: 'Dog' },
          { value: 'thunk', text: 'Rock' }
        ]
      },
    ]
  },
  buttons: [
    {
      type: 'custom',
      name: 'lastpage',
      text: 'Done',
      disabled: false
    }
  ],
  initialData: {
    choosydata: ''
  },
  onAction: (dialogApi, details) => {
    var {date} = dialogApi.getData();
// problem is here class="test"
    tinymce.activeEditor.execCommand('mceInsertContent', false, '<div class="test" ><p>' + date + '</p></div><p></p>');

    dialogApi.close();
  }
};

tinymce.init({
  force_br_newlines : true,
force_p_newlines : true,
  selector: 'textarea.wizard',
  toolbar: 'wizardExample',
  height: '900px',
  setup: (editor) => {
    editor.ui.registry.addButton('wizardExample', {
      icon: 'code-samplelklk',
      onAction: () => {
        editor.windowManager.open(page1Config)
      }
    })
  }
})

; ;

Example例子

Are you wanting to style the content in the editor via CSS?您想通过 CSS 在编辑器中设置内容的样式吗? If so you can use the content_css or content_style settings in your TinyMCE configuration to pass CSS to the editor:如果是这样,您可以使用 TinyMCE 配置中的 content_css 或 content_style 设置将 CSS 传递给编辑器:

https://www.tiny.cloud/docs/configure/content-appearance/#content_css https://www.tiny.cloud/docs/configure/content-appearance/#content_style https://www.tiny.cloud/docs/configure/content-appearance/#content_css https://www.tiny.cloud/docs/configure/content-appearance/#content_style

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

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