简体   繁体   English

为什么自定义元素会破坏WordPress中的TinyMCE?

[英]Why are Custom Elements Breaking TinyMCE in WordPress?

Background 背景

I am working on extending the visual editor inside WordPress, which is just TinyMCE: 我正在扩展WordPress内部的可视编辑器,这只是TinyMCE:

在此处输入图片说明

I am using a structure of: 我正在使用以下结构:

<section>
    <controls></controls>
    <content>
        <column class="one-third">
        </column>
        <column class="two-thirds">
        </column>
    </content>
</section>

Problem 问题

The problem is that when I try to change text from Paragraph to Header , nothing happens: 问题是,当我尝试将文本从“ Paragraph更改为“ Header ,什么也没发生:

在此处输入图片说明

Problem Cause 问题原因

I've tracked the issue down to using custom elements. 我已将问题归结为使用自定义元素。 When I change my code to use this structure, the problem goes away: 当我更改代码以使用此结构时,问题消失了:

<section>
    <controls></controls>
    <article>
        <div class="one-third">
        </div>
        <div class="two-thirds">
        </div>
    </article>
</section>

Attempted Solutions 尝试的解决方案

I have tried adding column and content to the extended_valid_elements and the custom_elements lists, and that has had zero effect. 我尝试将columncontent添加到extended_valid_elementscustom_elements列表中,但效果为零。

$init['custom_elements'] = 'content[*],column[*]';
$init['extended_valid_elements'] = 'content[*],column[*]';

Question

Is there anything that pops out immediately that I'm doing completely wrong? 是否有突然出现的提示我做错了什么? Is there a way to get around this, or to force TinyMCE to treat my custom elements as valid? 有没有办法解决这个问题,或迫使TinyMCE将我的自定义元素视为有效?

Problem 问题

In the custom_elements declaration, you used content[*], column[*] instead of content, column . custom_elements声明中,您使用content[*], column[*]而不是content, column While the extended_valid_elements does require the attributes to be declared, custom_elements doesn't. 尽管extended_valid_elements确实需要声明属性,但custom_elements却不需要。

Per the TinyMCE docs: https://www.tinymce.com/docs/configure/content-filtering/#custom_elements 根据TinyMCE文档: https//www.tinymce.com/docs/configure/content-filtering/#custom_elements

Solution: 解:

Change this: 更改此:

$init['custom_elements'] = 'content[*],column[*]';
$init['extended_valid_elements'] = 'content[*],column[*]';

To this: 对此:

$init['custom_elements'] = 'content,column';

Edit 编辑

Please note, it is critical that there are no spaces included in the comma-delimited lists. 请注意,以逗号分隔的列表中不能包含空格,这一点至关重要。

'content,column'; <--- works. <---有效。

'content, column'; <--- doesn't work. <--- 不起作用。

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

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