如何将(否则)无效的 HTML 元素添加到 TinyMCE 中

发布于 2024-09-06 21:35:29 字数 764 浏览 7 评论 0 原文

我的 HTML 包含这样的元素,因为它使用 django-basic-apps 中的内联。

<inline type="myapp.mymodel" id="4" />

我正在尝试使用tinymce 将其中之一插入到DOM 中。在网站的前端,这些被处理成好的代码。

在tinyMCE中,我添加了配置:

extend_valid_elements: 'inline[id|ids|type|filter|class|template]',

但任何时候我尝试插入via:

tinyMCE.execCommand('mceInsertRawHtml',false,'<inline type="myapp.mymodel" id="4" />');

都不会发生,

如果我这样做:

tinyMCE.activeEditor.getContent()

TinyMCE会删除我的代码中的任何元素。

此外,我希望这些元素通过CSS或其他方式显示在tinyMCE中,但我可能必须破解DTD。

如果这不起作用,我想到的一个可能的解决方案是将内容预渲染为有效的内容:

然后在保存之前,将其转换回应有的样子。

请就我应该研究的事情提供任何建议。

My HTML contains elements like this, because it uses inlines from django-basic-apps.

<inline type="myapp.mymodel" id="4" />

I'm trying to use tinymce to insert one of these into the DOM. On the frontend of the site, these are processed into good code.

In tinyMCE I've added the config:

extend_valid_elements: 'inline[id|ids|type|filter|class|template]',

But anytime I try to insert via:

tinyMCE.execCommand('mceInsertRawHtml',false,'<inline type="myapp.mymodel" id="4" />');

nothing happens,

And if I do:

tinyMCE.activeEditor.getContent()

TinyMCE removes any <inline elements that are in my code.

Furthermore, I would like these elements to display in the tinyMCE via CSS or something, but I'll probably have to hack the DTD.

If that doesn't work a possible solution that I've thought of would be to pre-render the content to something that IS valid:

And then before save, convert that back to what it should be.

Please provide any suggestions for things I should look into.

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

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

发布评论

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

评论(2

薔薇婲 2024-09-13 21:35:29

在tinymce tiny_mce_src.js 的源代码中搜索字符串valid_elements 并直接在其中添加元素和属性。

In the source code of tinymce tiny_mce_src.js search for the string valid_elements and add your elements and attributes directly there.

白况 2024-09-13 21:35:29

请改用 mceInsertContent 命令,并且不要使用自闭合标签:

tinyMCE.execCommand('mceInsertContent', false, '<inline type="myapp.mymodel" id="4"></inline>');

Use mceInsertContent command instead, and don't use self-closing tags:

tinyMCE.execCommand('mceInsertContent', false, '<inline type="myapp.mymodel" id="4"></inline>');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文