YUI 丰富编辑器 +无效HTML +风格

发布于 2024-08-02 04:44:32 字数 163 浏览 0 评论 0原文

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

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

谢谢, 上校

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

止于盛夏 2024-08-09 04:44:32

我希望我正确理解你的问题。您只是希望能够在文本区域中插入这样的内容吗?

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

如果是这样,这就是我使用 YUI API 文档中指定的内容让它工作的方式。特别是 invalidHTML 上的这一部分

在我初始化之前我指定了所有我想要删除的无效标签:

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 之外的所有内容。因此,在您的情况下,您将省略样式标签。

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

这就是一切尘埃落定之后的样子。

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();
}

这就是我如何让它保留我想要的标签。例如。风格。

希望对您有所帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文