本文整理汇总了Python中pygments.lexers.html.XmlLexer方法的典型用法代码示例。如果您正苦于以下问题:Python html.XmlLexer方法的具体用法?Python html.XmlLexer怎么用?Python html.XmlLexer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygments.lexers.html
的用法示例。
在下文中一共展示了html.XmlLexer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pygments.lexers import html [as 别名]
# 或者: from pygments.lexers.html import XmlLexer [as 别名]
def __init__(self, **options):
super(MozPreprocXulLexer, self).__init__(
XmlLexer, MozPreprocHashLexer, **options)
示例2: highlight_xml
# 需要导入模块: from pygments.lexers import html [as 别名]
# 或者: from pygments.lexers.html import XmlLexer [as 别名]
def highlight_xml(xml_str):
# Highlights a string containing XML, using terminal color codes
return highlight(xml_str, XmlLexer(), TerminalFormatter())
示例3: pretty_print_xml
# 需要导入模块: from pygments.lexers import html [as 别名]
# 或者: from pygments.lexers.html import XmlLexer [as 别名]
def pretty_print_xml(self, xml):
print(highlight(xml.toprettyxml(), XmlLexer(), TerminalFormatter()))
示例4: pretty_print_body
# 需要导入模块: from pygments.lexers import html [as 别名]
# 或者: from pygments.lexers.html import XmlLexer [as 别名]
def pretty_print_body(fmt, body):
try:
bstr = body.decode()
if fmt.lower() == 'json':
d = json.loads(bstr.strip())
s = json.dumps(d, indent=4, sort_keys=True)
print(pygments.highlight(s, JsonLexer(), TerminalFormatter()))
elif fmt.lower() == 'form':
qs = parse_qs(bstr, keep_blank_values=True)
for k, vs in qs.items():
for v in vs:
s = Colors.GREEN
s += '%s: ' % unquote(k)
s += Colors.ENDC
if v == '':
s += Colors.RED
s += 'EMPTY'
s += Colors.ENDC
else:
s += unquote(v)
print(s)
elif fmt.lower() == 'text':
print(bstr)
elif fmt.lower() == 'xml':
import xml.dom.minidom
xml = xml.dom.minidom.parseString(bstr)
print(pygments.highlight(xml.toprettyxml(), XmlLexer(), TerminalFormatter()))
else:
raise CommandError('"%s" is not a valid format' % fmt)
except CommandError as e:
raise e
except Exception as e:
raise CommandError('Body could not be parsed as "{}": {}'.format(fmt, e))
示例5: highlight_xform
# 需要导入模块: from pygments.lexers import html [as 别名]
# 或者: from pygments.lexers.html import XmlLexer [as 别名]
def highlight_xform(xml, **options):
formatter = XFormFormatter(style='friendly', **options)
return highlight(xml, XmlLexer(), formatter)