用于pyhton的xhtml移动配置文件html转换器和清理器
gomobile.xhtmlmp的Python项目详细描述
xhtml提供了xhtml移动配置文件清洗器。它接受任意的html代码 并将其转换为有效的xhtml-mp代码,该代码可以放在xhtml-mp页中。
该代码还将过滤外部源内容(如<;script>;标记)中可能存在的恶意代码。
功能
- 将任何传入的html/xhtml转换为与移动配置文件兼容的
- 在图像上强制使用alt文本-特别适用于外部跟踪图像(feedburner tracker)
- 防止跨站点脚本攻击(XSS)和其他恶意,如 lxml.html.clean
- Unicode兼容-吃时髦的字符
用法
干净的xhtml(html)
这个函数可以满足您的所有需要。
运行xhtml mobile profile cleaner获取html代码:
@param html: HTML as a string or lxml Document @return: XHTML, utf-8 encoded string
示例:
from gomobile.xhtmlmp.transformers.xhtmlmp_safe import clean_xhtml_mp html = '<img src="http://www.foobar.com">' output = clean_xhtml_mp(html) self.assertEqual(output, '<img src="http://www.foobar.com" alt=""/>', "Got:" + output)
路线图
未来的功能包括:
- 图像源的自动调整大小
单元测试
把gomobile.xhtml放到pythonpath上。
正常运行单元测试,如:
python tests/test_image.py
另请参见
0.1
- 初始版本