本文整理汇总了Python中gluon.html.TAG类的典型用法代码示例。如果您正苦于以下问题:Python TAG类的具体用法?Python TAG怎么用?Python TAG使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TAG类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_markdown
def test_markdown(self):
def markdown(text, tag=None, attributes={}):
r = {None: re.sub('\s+',' ',text), \
'h1':'#'+text+'\\n\\n', \
'p':text+'\\n'}.get(tag,text)
return r
a=TAG('<h1>Header</h1><p>this is a test</p>')
ret = a.flatten(markdown)
self.assertEqual(ret, '#Header\\n\\nthis is a test\\n')
示例2: test_TAG
def test_TAG(self):
self.assertEqual(TAG.first(TAG.second('test'), _key=3).xml(),
b'<first key="3"><second>test</second></first>')
# ending in underscore "triggers" <input /> style
self.assertEqual(TAG.first_(TAG.second('test'), _key=3).xml(),
b'<first key="3" />')
# unicode test for TAG
self.assertEqual(TAG.div(u'Texte en français avec des caractères accentués...').xml(),
b'<div>Texte en fran\xc3\xa7ais avec des caract\xc3\xa8res accentu\xc3\xa9s...</div>')
示例3: html_to_markmin
def html_to_markmin(html):
"""
Replace HTML with Markmin, converting unicode to references first
>>> html_to_markmin('<p class="foo"><b>Bold</b><i>Italics</i><ol><li>Item 1</li><li><a href="http://kvasir.io">Kvasir</a></li></ol><br>')
"**Bold**''Italics''\n- Item 1\n- [[Kvasir http://kvasir.io]]\n\n\n\n"
>>> html_to_markmin(u'<p>asdfsadf</p>')
'asdfsadf\n\n'
>>> html_to_markmin(u'<p>\ufffdq\ufffd</p>')
'\xef\xbf\xbdq\xef\xbf\xbd\n\n'
>>> html_to_markmin('[[ a link http://url.com]]')
'[[a link http://url.com]]'
"""
if html is None:
return ''
from gluon.html import markmin_serializer, TAG
html = html.encode('ascii', 'xmlcharrefreplace') # cleanup unicode
html = TAG(html).flatten(markmin_serializer) # turn to markmin
html = html.replace('[[ ', '[[') # fix bad url
html = html.replace(' ]]', ']]') # fix bad url
return html
示例4: xml_rec
def xml_rec(value, key, quote=True):
if hasattr(value, "custom_xml") and callable(value.custom_xml):
return value.custom_xml()
elif isinstance(value, (dict, Storage)):
return TAG[key](*[TAG[k](xml_rec(v, "", quote)) for k, v in value.items()])
elif isinstance(value, list):
return TAG[key](*[TAG.item(xml_rec(item, "", quote)) for item in value])
elif hasattr(value, "as_list") and callable(value.as_list):
return str(xml_rec(value.as_list(), "", quote))
elif hasattr(value, "as_dict") and callable(value.as_dict):
return str(xml_rec(value.as_dict(), "", quote))
else:
return xmlescape(value, quote)
示例5: FONT
def FONT(*args, **kwargs):
return TAG.font(*args, **kwargs)
示例6: test_TAG_pickler_unpickler
def test_TAG_pickler_unpickler(self):
# weird test
self.assertEqual(TAG_unpickler(TAG_pickler(TAG.div('data to be pickle'))[1][0]).xml(),
b'<div>data to be pickle</div>')