YUI 富编辑器 + invalidHTML + 样式 [英] YUI Rich Editor + invalidHTML + style

查看:29
本文介绍了YUI 富编辑器 + invalidHTML + 样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将内联样式标签插入到编辑器内容中.当我在富编辑器视图中调用 saveHTML 时,它会删除样式块.我已经尝试将 invalidHTML 的 style 属性更改为 false,但它似乎仍然去除了样式块.

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.

任何指向 API 的指针或建议在此阶段都会有所帮助!

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

谢谢,上校

推荐答案

我希望我能正确理解你的问题.你只是想在你的 textarea 中插入这样的东西?

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>

如果是这样,我就是这样使用 YUI API 文档中指定的内容来工作的.特别是 invalidHTML

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 }}

我的列表很长(基本上都是 html 标签),因为我排除了 p、style、br、ul、ol、li 之外的所有内容.因此,在您的情况下,您可以省略样式标签.

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.

然后我设置编辑器,然后在渲染之前将 invalidTags 作为编辑器的 invalidHTML 传递.

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.

希望能帮到你.

这篇关于YUI 富编辑器 + invalidHTML + 样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆