“安全” python HTML文本格式(ala textile) [英] A "safe" python HTML text formatting (ala textile)

查看:142
本文介绍了“安全” python HTML文本格式(ala textile)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个现有的Python图书馆,以纺织品的形式格式化文本,供用户进入。

I've been looking around for an existing python library in the style of textile to format text for users to enter.

如果只是我输入,只是纺织品一直都很好,但是由于输入是用于一个django应用程序,将用户输入并显示它,同时仍然保留一些格式。

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.

我设法在我看到的现有图书馆里找到一些漏洞。他们有时候不会以这样的方式逃避事情,请允许我直接输入HTML,列表继续下去。

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?

推荐答案

如果您使用Django,您可以尝试安全的降价:

If you're using Django, you could try safe markdown:

{% load markup %}

{{ foo|markdown:"safe" }}

您需要安装markdown,而 django.contrib.markup c $ c> settings.py 应用程序。

You'll need to have markdown installed, and django.contrib.markup in your settings.py apps.

如果要在保存时清除HTML,我已经好运使用feedparser的清理 http://www.feedparser.org/ )。

If you want to sanitize HTML on save, I've had good luck using feedparser's sanitize (http://www.feedparser.org/).

import feedparser

body = feedparser._sanitizeHTML(body, 'utf8')

这篇关于“安全” python HTML文本格式(ala textile)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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