TinyMCE:保存内容时我的HTML会发生变化。我如何保留我的HTML?

时间:2023-01-07 07:25:34

I am using the formats paramter to initialize tinymce in order to use b-,i- and u-tags instead of spans and styles

我使用格式参数来初始化tinymce以便使用b-,i-和u-标签而不是跨度和样式

formats: {
    bold : {inline : 'b' },  
    italic : {inline : 'i' },
    underline: { inline: 'u' }
},

When i save the content, the u-tags get replaced by spans (i- and b-tags are not affected):

当我保存内容时,u-tags被替换为跨度(i-和b-标签不受影响):

<span style="text-decoration: underline;">underlined text</span>

What can i do to keep my u-tags in the html?

我该怎么做才能将我的u-tags保存在html中?

1 个解决方案

#1


2  

After some "try and error" i found a solution which works. But i am sure there is a more elegant way. Feel free to point me into the right direction. My solution consists of the replacement of the new span back to the u-tag on the onSave event:

经过一些“尝试和错误”,我找到了一个有效的解决方案。但我相信有更优雅的方式。随意指出我正确的方向。我的解决方案包括将新跨度替换回onSave事件上的u-tag:

ed.onSaveContent.add(function(ed, o) {
    o.content = o.content.replace(/<span style="text-decoration: ?underline;">(.*?)<\/span>/gi, "<u>$1</u>");   
});

Felix Risterer mentioned the legacyoutput plugin. It works with this plugin too, but i will stick with the solution above cause the legacyplugin does many things and i am not fully able to predict what else could be affected.

Felix Risterer提到了legacyoutput插件。它也适用于这个插件,但我会坚持上面的解决方案因为legacyplugin做了很多事情,我不能完全预测还有什么可能会受到影响。

#1


2  

After some "try and error" i found a solution which works. But i am sure there is a more elegant way. Feel free to point me into the right direction. My solution consists of the replacement of the new span back to the u-tag on the onSave event:

经过一些“尝试和错误”,我找到了一个有效的解决方案。但我相信有更优雅的方式。随意指出我正确的方向。我的解决方案包括将新跨度替换回onSave事件上的u-tag:

ed.onSaveContent.add(function(ed, o) {
    o.content = o.content.replace(/<span style="text-decoration: ?underline;">(.*?)<\/span>/gi, "<u>$1</u>");   
});

Felix Risterer mentioned the legacyoutput plugin. It works with this plugin too, but i will stick with the solution above cause the legacyplugin does many things and i am not fully able to predict what else could be affected.

Felix Risterer提到了legacyoutput插件。它也适用于这个插件,但我会坚持上面的解决方案因为legacyplugin做了很多事情,我不能完全预测还有什么可能会受到影响。