“安全的” python HTML 文本格式化(ala Textile)
我一直在寻找纺织风格的现有 python 库来格式化文本以供用户输入。
如果只是我输入它,只输入 Textile 就可以了,但由于输入是针对 django 应用程序的,它将接受用户输入并显示它,同时仍然保持一些格式。
我设法在我看到的现有库中找到了一些小漏洞。他们有时不会以应有的方式逃避事情,会让我直接输入 HTML,这样的例子不胜枚举。
那么我可以使用哪些推荐的转换引擎呢?
I've been looking around for an existing python library in the style of textile to format text for users to enter.
If it was just me entering it, just textile would have been fine, but since the input is meant for a django app that will take user input and display it, while still maintaining some formatting.
I managed to find little loopholes here in there in the existing libraries I saw. They sometimes wouldn't escape things the way they should have, would let me input straight HTML and the list goes on.
So what are some recommendations of conversion engines I can use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用 Django,则可以尝试安全 Markdown:
您需要安装 Markdown,并在
settings.py
应用中安装django.contrib.markup
。如果你想在保存时清理 HTML,我很幸运地使用 feedparser 的清理 (http://www.feedparser. org/)。
If you're using Django, you could try safe markdown:
You'll need to have markdown installed, and
django.contrib.markup
in yoursettings.py
apps.If you want to sanitize HTML on save, I've had good luck using feedparser's sanitize (http://www.feedparser.org/).
如果您正在寻找纺织解决方案:django 标记使用的 PyTextile 实际上有一个 Textile_restricted() 函数,由于某种原因,该函数从未进入 django.contrib.markup。您可以使用此功能来提供受限纺织品。通过向模型添加一个调用textile_restricted的方法,或者使用自定义模板标签
textile_restricted
(由以下代码定义):If you are looking for a textile solution: the PyTextile that django markup uses actually has a textile_restricted() function, which for some reason, never made it into django.contrib.markup. You can use this function to provide restricted textile. Either by adding a method to your model that calls textile_restricted, or use a custom template tag
textile_restricted
, defined by the following code:您是否尝试过包含的 django.contrib.markup 库?
Did you try the included django.contrib.markup libraries?