本文整理匯總了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)