YUI Rich Editor + invalidHTML + style

两盒软妹~` 提交于 2019-12-23 01:40:11

问题


I am trying to insert an inline style tag into the editor content. When I call saveHTML it strips out the style block when I'm in rich editor view. I have tried changing the style property of invalidHTML to false, but it still seems to strip the style block out.

Any pointers to the API or suggestions would be helpful at this stage!

Thanks, Col.


回答1:


I hope I understand your question properly. You just want to be able to insert something like this in your textarea?

<style>
    .className { font-weight: bold;}
</style>

If so this is how I have it working using what is specified in the YUI API documentation. In particular this part on invalidHTML

Before I initialize the editor I specify all the invalid tags I want stripped out:

var invalidTags = {"abbr":{ "keepContents":true }, 
    "acronym":{ "keepContents":true }, "address":{ "keepContents":true }, 
    "applet":"", "area":"", "base":"", "basefont":"", "bdo":"", "big":"", 
    "blockquote":{ "keepContents":true }, "body":{ "keepContents":true }}

Mine's a rather long list (basically all html tags) as I exclude everything except p, style, br, ul, ol, li. So in your case you'd leave out the style tag.

Then I set up the editor and then pass in the invalidTags as the invalidHTML for the editor before rendering.

So this is what everything looks like after all is said and done.

var invalidTags = {"abbr":{ "keepContents":true }, 
    "acronym":{ "keepContents":true }, "address":{ "keepContents":true }, 
    "applet":"", "area":"", "base":"", "basefont":"", "bdo":"", "big":"", 
    "blockquote":{ "keepContents":true }, "body":{ "keepContents":true }}

var editor = new YAHOO.widget.Editor('myeditor', {
    height: '300px',
    width: '500px',
    dompath: true,
    filterWord: true
}

editor.invalidHTML = invalidTags;
editor.render();

YAHOO.util.Event.on('Update', 'click', function() {
    editor.saveHTML();
}

So that's that for how I get it to preserve the tags I want. eg. style.

Hope that helps you out.



来源:https://stackoverflow.com/questions/1303999/yui-rich-editor-invalidhtml-style

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!