Wagtail/Hallo.js-添加插件,但未保存修改后的内容 [英] Wagtail / Hallo.js - Adding plugins but modified content is not saved

查看:51
本文介绍了Wagtail/Hallo.js-添加插件,但未保存修改后的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Wagtail 1.3.1和Django 1.7.11上运行.

我已经激活了hallohtml和hallojustify插件,它们出现在工具栏中(没有图标,但按钮在这里).

可以使用按钮,并且可以在文本区域中看到修改(例如,我可以将字段居中并看到它).

发布页面时,不会保存hallojustify或hallohtml所做的修改,而我仍然可以使用粗体/斜体按钮并保存内容.看来html已清理完毕...

我应该错过一些东西,但是...

  @ hooks.register('insert_editor_js')def editor_js():js_files = []js_includes = format_html_join('\ n',``,((settings.STATIC_URL,filename)表示js_files中的文件名))返回js_includes + format_html("< script>registerHalloPlugin('hallojustify');registerHalloPlugin('hallohtml');</script>") 

解决方案

通过设计,Wagtail仅允许HTML标签和属性的子集,并去除不在其白名单中的任何内容.这样做有几个原因:防止编辑者插入恶意内容(例如< script> 标签),并鼓励站点开发人员将内容和演示文稿分开.(您不应该真正在格式文本内容中包括格式信息,例如左/右/中心对齐,而这些信息应该在模板和CSS中定义.)

您可以使用 construct_whitelister_element_rules 钩子-但是,我建议您重新考虑是否真的需要使用这么多功能来重载RTF编辑器,或者是否有一种结构化的方式实现所需的功能(例如 StreamField ).

I'm running on Wagtail 1.3.1, Django 1.7.11.

I have activated hallohtml and hallojustify plugins and they appear in toolbar (without icons but buttons are here).

The buttons can be used and the modifications are seen in the textarea (I mean that I can center a field for example and I see it).

When I publish the page, the modifications made by either hallojustify or hallohtml are not saved whereas I can still use the bold/italic buttons and save the content. It looks like the html is cleaned up...

I should miss something but...

@hooks.register('insert_editor_js')
def editor_js():
js_files = [
]
js_includes = format_html_join('\n', '',
((settings.STATIC_URL, filename) for filename in js_files)
)

return js_includes + format_html(
        """
        <script>
          registerHalloPlugin('hallojustify');
          registerHalloPlugin('hallohtml');
        </script>
        """
    )

解决方案

By design, Wagtail only allows a subset of HTML tags and attributes, and strips out any that are not on its whitelist. This is done for several reasons: it prevents editors from inserting malicious content (such as <script> tags), and encourages site developers to keep content and presentation separate. (You shouldn't really be including formatting information such as left/right/centre alignment inside rich text content - that should be defined inside your template and CSS.)

You can customise the HTML whitelisting rules using the construct_whitelister_element_rules hook - however, I'd encourage you to reconsider whether you really need to overload the rich text editor with so much functionality, or whether there's a more structured way of achieving what you want (such as StreamField).

这篇关于Wagtail/Hallo.js-添加插件,但未保存修改后的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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