[英]Why are Custom Elements Breaking TinyMCE in WordPress?
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>
The problem is that when I try to change text from Paragraph
to Header
, nothing happens: 问题是,当我尝试将文本从“ Paragraph
更改为“ Header
,什么也没发生:
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>
I have tried adding column
and content
to the extended_valid_elements
and the custom_elements
lists, and that has had zero effect. 我尝试将column
和content
添加到extended_valid_elements
和custom_elements
列表中,但效果为零。
$init['custom_elements'] = 'content[*],column[*]';
$init['extended_valid_elements'] = 'content[*],column[*]';
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将我的自定义元素视为有效?
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
Change this: 更改此:
$init['custom_elements'] = 'content[*],column[*]';
$init['extended_valid_elements'] = 'content[*],column[*]';
To this: 对此:
$init['custom_elements'] = 'content,column';
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.