Python 的轻量级标记语言
在编写 Python Web 应用程序时,我想创建一个文本区域,用户可以在其中以轻量级标记语言输入文本。 文本将导入到 html 模板并在页面上查看。 今天,我使用此命令创建文本区域,它允许用户输入任何(html)文本:
my_text = cgidata.getvalue('my_text', 'default_text')
ftable.AddRow([Label(_('Enter your text')),
TextArea('my_text', my_text, rows=8, cols=60).Format()])
我如何更改它以便只允许一些(安全的,最终轻量级的)标记? 只要它能轻松地与 Python 集成,所有建议(包括消毒剂)都是受欢迎的。
Programming a Python web application, I want to create a text area where the users can enter text in a lightweight markup language. The text will be imported to a html template and viewed on the page. Today I use this command to create the textarea, which allows users to enter any (html) text:
my_text = cgidata.getvalue('my_text', 'default_text')
ftable.AddRow([Label(_('Enter your text')),
TextArea('my_text', my_text, rows=8, cols=60).Format()])
How can I change this so that only some (safe, eventually lightweight) markup is allowed? All suggestions including sanitizers are welcome, as long as it easily integrates with Python.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个简单的清理功能使用白名单,与 python-html-sanitizer- 的解决方案大致相同scrapber-filter,但也允许限制属性的使用(因为您可能不希望有人使用
style
属性等):This simple sanitizing function uses a whitelist and is roughly the same as the solution of python-html-sanitizer-scrubber-filter, but also allows to limit the use of attributes (since you probably don't want someone to use, among others, the
style
attribute):您可以使用 重组文本 。 我不确定它是否有清理选项,但 Python 很好地支持它,并且它生成各种格式。
You could use restructured text . I'm not sure if it has a sanitizing option, but it's well supported by Python, and it generates all sorts of formats.
使用 python markdown 实现
非常灵活,可以使用各种扩展,创建你自己的等等。
Use the python markdown implementation
It is very flexible, you can use various extensions, create your own etc.