本文整理匯總了Python中webhelpers2.html.HTML.br方法的典型用法代碼示例。如果您正苦於以下問題:Python HTML.br方法的具體用法?Python HTML.br怎麽用?Python HTML.br使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類webhelpers2.html.HTML
的用法示例。
在下文中一共展示了HTML.br方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_html
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import br [as 別名]
def test_html():
a = HTML.a(href='http://mostlysafe\" <tag', c="Bad <script> tag")
eq_(a, u'<a href="http://mostlysafe" <tag">Bad <script> tag</a>')
img = HTML.img(src='http://some/image.jpg')
eq_(img, u'<img src="http://some/image.jpg" />')
br = HTML.br()
eq_(u'<br />', br)
示例2: test_html
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import br [as 別名]
def test_html(self):
a = HTML.a(href='http://mostlysafe\" <tag', c="Bad <script> tag")
assert a == '<a href="http://mostlysafe" <tag">Bad <script> tag</a>'
img = HTML.img(src="http://some/image.jpg")
assert img == '<img src="http://some/image.jpg" />'
br = HTML.br()
assert "<br />" == br
示例3: render
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import br [as 別名]
from webhelpers2.html import HTML, escape, literal, lit_sub
# render() and sanitize() are imported from the private module 'render'.
from webhelpers2.html.render import render, sanitize
__all__ = [
"format_paragraphs",
"nl2br",
"render",
"sanitize",
]
_universal_newline_rx = re.compile(R"\r\n|\n|\r") # All types of newline.
_paragraph_rx = re.compile(R"\n{2,}") # Paragraph break: 2 or more newlines.
br = HTML.br() + "\n"
def nl2br(text):
"""Insert a <br /> before each newline.
"""
if text is None:
return literal("")
text = lit_sub(_universal_newline_rx, "\n", text)
text = HTML(text).replace("\n", br)
return text
def format_paragraphs(text, preserve_lines=False):
"""Convert text to HTML paragraphs.
``text``:
the text to convert. Split into paragraphs at blank lines (i.e.,