简体   繁体   English

YUI丰富的编辑器+无效的HTML +样式

[英]YUI Rich Editor + invalidHTML + style

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. 当我调用saveHTML时,当我进入丰富的编辑器视图时,它将删除样式块。 I have tried changing the style property of invalidHTML to false, but it still seems to strip the style block out. 我曾尝试将invalidHTML的样式属性更改为false,但似乎仍将样式块删除。

Any pointers to the API or suggestions would be helpful at this stage! 在此阶段,任何指向API或建议的指针都将有所帮助!

Thanks, Col. 谢谢,上校

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. 如果是这样,这就是我如何使用YUI API文档中指定的内容进行工作。 In particular this part on invalidHTML 特别是关于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. 我的名单很长(基本上是所有html标签),因为我排除了除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. 然后,我设置了编辑器,然后在呈现之前将invalidTags作为编辑器的invalidHTML传递。

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. 希望对您有所帮助。

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

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