简体   繁体   English

tinyMCE

[英]tinyMCE turning <i> into <em> on getContent

in the dom in my tinyMCE editor i see 在我的tinyMCE编辑器中的dom中,我看到了

<p>
  <i>testing 123</i>
</p>

but when i run 但是当我跑步时

tinyMCE.activeEditor.getContent()

it returns 它返回

<p>
  <em>testing 123</em>
</p>

Why is it changing <i> into <em> ? 为什么将<i>更改为<em> Im having problems with this because i want to insert text dynamically that is surrounded with tags and things are getting confusing. 我对此有问题,因为我想动态插入被标签包围的文本,并且事情变得混乱。

The default rule set for the valid_elements option contains em/i which means that all <i> Tags will be replaced by <em> in the output. valid_elements选项的默认规则集包含em/i ,这意味着所有<i>标签将在输出中替换为<em> You could add your own valid_elements option which would leave <i> intact. 您可以添加自己的valid_elements选项,使<i>保持不变。 You could just modify the default rule set for that: 您可以为此修改默认规则集:

valid_elements : "@[id|class|style|title|dir<ltr?rtl|lang|xml::lang|onclick|ondblclick|"
+ "onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|"
+ "onkeydown|onkeyup],a[rel|rev|charset|hreflang|tabindex|accesskey|type|"
+ "name|href|target|title|class|onfocus|onblur],strong/b,em,i,strike,u,"
+ "#p,-ol[type|compact],-ul[type|compact],-li,br,img[longdesc|usemap|"
+ "src|border|alt=|title|hspace|vspace|width|height|align],-sub,-sup,"
+ "-blockquote,-table[border=0|cellspacing|cellpadding|width|frame|rules|"
+ "height|align|summary|bgcolor|background|bordercolor],-tr[rowspan|width|"
+ "height|align|valign|bgcolor|background|bordercolor],tbody,thead,tfoot,"
+ "#td[colspan|rowspan|width|height|align|valign|bgcolor|background|bordercolor"
+ "|scope],#th[colspan|rowspan|width|height|align|valign|scope],caption,-div,"
+ "-span,-code,-pre,address,-h1,-h2,-h3,-h4,-h5,-h6,hr[size|noshade],-font[face"
+ "|size|color],dd,dl,dt,cite,abbr,acronym,del[datetime|cite],ins[datetime|cite],"
+ "object[classid|width|height|codebase|*],param[name|value|_value],embed[type|width"
+ "|height|src|*],script[src|type],map[name],area[shape|coords|href|alt|target],bdo,"
+ "button,col[align|char|charoff|span|valign|width],colgroup[align|char|charoff|span|"
+ "valign|width],dfn,fieldset,form[action|accept|accept-charset|enctype|method],"
+ "input[accept|alt|checked|disabled|maxlength|name|readonly|size|src|type|value],"
+ "kbd,label[for],legend,noscript,optgroup[label|disabled],option[disabled|label|selected|value],"
+ "q[cite],samp,select[disabled|multiple|name|size],small,"
+ "textarea[cols|rows|disabled|name|readonly],tt,var,big"

Notice I replaced em/i with em,i . 注意,我用em,i代替了em/i em,i That way both <i> and <em> are valid tags and neither will be replaced in the output. 这样, <i><em>都是有效标记,并且不会在输出中替换它们。

If this is too much you could also reduce the list of the valid elements to contain only those elements that you really need in your HTML. 如果太多,您还可以减少有效元素的列表,以仅包含您在HTML中真正需要的那些元素。 For example you might not allow your users to create any tables and therefore you could just remove all references to table , tbody , tr , td etc. 例如,您可能不允许用户创建任何表,因此您可以删除对tabletbodytrtd等的所有引用。

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

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