简体   繁体   English

CKeditor - 更改表格样式

[英]CKeditor - Change table style

I am trying to change the table style for CKeditor , since it keeps outputting this. 我正在尝试更改CKeditor的表格样式,因为它一直在输出它。

<table class="ckeditor_table" style="width: 100%;border-collapse:collapse;border-spacing:0;table-layout:fixed;border: 2px solid #333;background:#fff;"><tr><td style="border: 1px dashed #999;padding: 3px 5px;vertical-align: top;min-height:20px;">
  </td><td style="border: 1px dashed #999;padding: 3px 5px;vertical-align: top;min-height:20px;">
  </td><td style="border: 1px dashed #999;padding: 3px 5px;vertical-align: top;min-height:20px;">
  </td><td style="border: 1px dashed #999;padding: 3px 5px;vertical-align: top;min-height:20px;">
  </td><td style="border: 1px dashed #999;padding: 3px 5px;vertical-align: top;min-height:20px;">
  </td></tr><tr><td style="border: 1px dashed #999;padding: 3px 5px;vertical-align: top;min-height:20px;">
  </td><td style="border: 1px dashed #999;padding: 3px 5px;vertical-align: top;min-height:20px;">
  </td><td style="border: 1px dashed #999;padding: 3px 5px;vertical-align: top;min-height:20px;">
  </td><td style="border: 1px dashed #999;padding: 3px 5px;vertical-align: top;min-height:20px;">
  </td><td style="border: 1px dashed #999;padding: 3px 5px;vertical-align: top;min-height:20px;">
  </td></tr><tr><td style="border: 1px dashed #999;padding: 3px 5px;vertical-align: top;min-height:20px;">
  </td><td style="border: 1px dashed #999;padding: 3px 5px;vertical-align: top;min-height:20px;">
  </td><td style="border: 1px dashed #999;padding: 3px 5px;vertical-align: top;min-height:20px;">
  </td><td style="border: 1px dashed #999;padding: 3px 5px;vertical-align: top;min-height:20px;">
  </td><td style="border: 1px dashed #999;padding: 3px 5px;vertical-align: top;min-height:20px;">
</table>

I want to output something like this instead. 我想输出这样的东西。

<table class="table">
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>

How do I make this possible? 我该如何做到这一点? I have tried config.allowedContent = true; 我试过config.allowedContent = true; but that didn't work, it still outputs the annoying white background on my dark theme. 但这不起作用,它仍然在我黑暗的主题上输出恼人的白色背景。

I am using CKeditor plugin for MyBB. 我正在为MyBB使用CKeditor插件。

When you look at the source code of the mybb ckeditor plugin, you can see they print out the inline style you posted. 当您查看mybb ckeditor插件的源代码时,您可以看到它们打印出您发布的内联样式。

while(preg_match("#\[table\](.*?)\[/table\]#si", $m, $m1))
{
    while(preg_match("#\[tr\](.*?)\[/tr\]#si", $m1[1], $m2))
    {
        $m2[1] = preg_replace("#\[td\](.*?)\[/td\]#si", '<td style="border: 1px dashed #999;padding: 3px 5px;vertical-align: top;min-height:20px;">$1</td>', $m2[1]);
        $m1[1] = str_replace($m2[0], '<tr>'.$m2[1].'</tr>', $m1[1]);
    }
    $m = str_replace($m1[0], '<table class="ckeditor_table" style="width: 100%;border-collapse:collapse;border-spacing:0;table-layout:fixed;border: 2px solid #333;background:#fff;">'.$m1[1].'</table>', $m);
}

You could remove the inline style from the 'inc/plugins/ckeditor/hooks.php' file, but that's a bad practice (issues when update). 您可以从'inc / plugins / ckeditor / hooks.php'文件中删除内联样式,但这是一种不好的做法(更新时出现问题)。

So I wrote a small plugin , which you can copy into your plugin folder and activate (the filename should be cktableoverride.php). 所以我写了一个小插件 ,你可以将其复制到你的插件文件夹并激活(文件名应该是cktableoverride.php)。
The plugin hooks into the same event the ckeditor plugin uses to override the template. 该插件挂钩到ckeditor插件用于覆盖模板的同一事件。 When the plugin is activated, you'll get a table structure without inline styles, so you can style it through css (or add your own inline style in the plugin code). 当插件被激活时,您将获得没有内联样式的表结构,因此您可以通过css设置样式(或在插件代码中添加自己的内联样式)。

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

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