当前位置: 首页>>代码示例>>Python>>正文


Python text.normalize_newlines方法代码示例

本文整理汇总了Python中django.utils.text.normalize_newlines方法的典型用法代码示例。如果您正苦于以下问题:Python text.normalize_newlines方法的具体用法?Python text.normalize_newlines怎么用?Python text.normalize_newlines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.text的用法示例。


在下文中一共展示了text.normalize_newlines方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: linebreaks

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import normalize_newlines [as 别名]
def linebreaks(value, autoescape=False):
    """Converts newlines into <p> and <br />s."""
    value = normalize_newlines(value)
    paras = re.split('\n{2,}', value)
    if autoescape:
        paras = ['<p>%s</p>' % escape(p).replace('\n', '<br />') for p in paras]
    else:
        paras = ['<p>%s</p>' % p.replace('\n', '<br />') for p in paras]
    return '\n\n'.join(paras) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:11,代码来源:html.py

示例2: standardize_report_output_field

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import normalize_newlines [as 别名]
def standardize_report_output_field(field_content):
    # Normalize newlines replaces \r\n from windows with \n
    standardized_text = normalize_newlines(field_content)

    # Replace blank fields with "N/A"
    if len(standardized_text) == 0:
        standardized_text = "N/A"

    return standardized_text 
开发者ID:lmco,项目名称:dart,代码行数:11,代码来源:formatters.py

示例3: linebreaks

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import normalize_newlines [as 别名]
def linebreaks(value, autoescape=False):
    """Convert newlines into <p> and <br />s."""
    value = normalize_newlines(value)
    paras = re.split('\n{2,}', str(value))
    if autoescape:
        paras = ['<p>%s</p>' % escape(p).replace('\n', '<br />') for p in paras]
    else:
        paras = ['<p>%s</p>' % p.replace('\n', '<br />') for p in paras]
    return '\n\n'.join(paras) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:11,代码来源:html.py

示例4: linebreaks

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import normalize_newlines [as 别名]
def linebreaks(value, autoescape=False):
    """Convert newlines into <p> and <br>s."""
    value = normalize_newlines(value)
    paras = re.split('\n{2,}', str(value))
    if autoescape:
        paras = ['<p>%s</p>' % escape(p).replace('\n', '<br>') for p in paras]
    else:
        paras = ['<p>%s</p>' % p.replace('\n', '<br>') for p in paras]
    return '\n\n'.join(paras) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:11,代码来源:html.py

示例5: linebreaks

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import normalize_newlines [as 别名]
def linebreaks(value, autoescape=False):
    """Converts newlines into <p> and <br />s."""
    value = normalize_newlines(force_text(value))
    paras = re.split('\n{2,}', value)
    if autoescape:
        paras = ['<p>%s</p>' % escape(p).replace('\n', '<br />') for p in paras]
    else:
        paras = ['<p>%s</p>' % p.replace('\n', '<br />') for p in paras]
    return '\n\n'.join(paras) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:11,代码来源:html.py

示例6: clean_html

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import normalize_newlines [as 别名]
def clean_html(text):
    """
    Clean the given HTML.  Specifically, do the following:
        * Convert <b> and <i> to <strong> and <em>.
        * Encode all ampersands correctly.
        * Remove all "target" attributes from <a> tags.
        * Remove extraneous HTML, such as presentational tags that open and
          immediately close and <br clear="all">.
        * Convert hard-coded bullets into HTML unordered lists.
        * Remove stuff like "<p>&nbsp;&nbsp;</p>", but only if it's at the
          bottom of the text.
    """
    from django.utils.text import normalize_newlines
    text = normalize_newlines(force_text(text))
    text = re.sub(r'<(/?)\s*b\s*>', '<\\1strong>', text)
    text = re.sub(r'<(/?)\s*i\s*>', '<\\1em>', text)
    text = fix_ampersands(text)
    # Remove all target="" attributes from <a> tags.
    text = link_target_attribute_re.sub('\\1', text)
    # Trim stupid HTML such as <br clear="all">.
    text = html_gunk_re.sub('', text)
    # Convert hard-coded bullets into HTML unordered lists.
    def replace_p_tags(match):
        s = match.group().replace('</p>', '</li>')
        for d in DOTS:
            s = s.replace('<p>%s' % d, '<li>')
        return '<ul>\n%s\n</ul>' % s
    text = hard_coded_bullets_re.sub(replace_p_tags, text)
    # Remove stuff like "<p>&nbsp;&nbsp;</p>", but only if it's at the bottom
    # of the text.
    text = trailing_empty_content_re.sub('', text)
    return text 
开发者ID:blackye,项目名称:luscan-devel,代码行数:34,代码来源:html.py

示例7: linebreaksbr

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import normalize_newlines [as 别名]
def linebreaksbr(value, autoescape=None):
    """
    Converts all newlines in a piece of plain text to HTML line breaks
    (``<br />``).
    """
    autoescape = autoescape and not isinstance(value, SafeData)
    value = normalize_newlines(value)
    if autoescape:
        value = escape(value)
    return mark_safe(value.replace('\n', '<br />')) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:12,代码来源:defaultfilters.py

示例8: test_normalize_newlines

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import normalize_newlines [as 别名]
def test_normalize_newlines(self):
        self.assertEqual(text.normalize_newlines("abc\ndef\rghi\r\n"), "abc\ndef\nghi\n")
        self.assertEqual(text.normalize_newlines("\n\r\r\n\r"), "\n\n\n\n")
        self.assertEqual(text.normalize_newlines("abcdefghi"), "abcdefghi")
        self.assertEqual(text.normalize_newlines(""), "")
        self.assertEqual(text.normalize_newlines(lazystr("abc\ndef\rghi\r\n")), "abc\ndef\nghi\n") 
开发者ID:nesdis,项目名称:djongo,代码行数:8,代码来源:test_text.py

示例9: clean_html

# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import normalize_newlines [as 别名]
def clean_html(text):
    """
    Clean the given HTML.  Specifically, do the following:
        * Convert <b> and <i> to <strong> and <em>.
        * Encode all ampersands correctly.
        * Remove all "target" attributes from <a> tags.
        * Remove extraneous HTML, such as presentational tags that open and
          immediately close and <br clear="all">.
        * Convert hard-coded bullets into HTML unordered lists.
        * Remove stuff like "<p>&nbsp;&nbsp;</p>", but only if it's at the
          bottom of the text.
    """
    text = normalize_newlines(force_text(text))
    text = re.sub(r'<(/?)\s*b\s*>', '<\\1strong>', text)
    text = re.sub(r'<(/?)\s*i\s*>', '<\\1em>', text)
    text = fix_ampersands(text)
    # Remove all target="" attributes from <a> tags.
    text = link_target_attribute_re.sub('\\1', text)
    # Trim stupid HTML such as <br clear="all">.
    text = html_gunk_re.sub('', text)
    # Convert hard-coded bullets into HTML unordered lists.

    def replace_p_tags(match):
        s = match.group().replace('</p>', '</li>')
        for d in DOTS:
            s = s.replace('<p>%s' % d, '<li>')
        return '<ul>\n%s\n</ul>' % s
    text = hard_coded_bullets_re.sub(replace_p_tags, text)
    # Remove stuff like "<p>&nbsp;&nbsp;</p>", but only if it's at the bottom
    # of the text.
    text = trailing_empty_content_re.sub('', text)
    return text 
开发者ID:ofa,项目名称:connect,代码行数:34,代码来源:django_clean_html_backport.py


注:本文中的django.utils.text.normalize_newlines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。