﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29372	linebreaksbr and linebreaks can not work in template filters	何翔宇(Sean Ho)	何翔宇(Sean Ho)	"In template, linebreaksbr and linebreaks can convert newlines in a piece of plain text to HTML line breaks ( <br>).

They all use the same way which is ""replace('\n', '<br>')"", the correct way is “""replace(r'\n', '<br>')”.


{{{
@register.filter(is_safe=True, needs_autoescape=True)
@stringfilter
def linebreaksbr(value, autoescape=True):
    """"""
    Convert 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>'))
}}}


{{{
@keep_lazy_text
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)
}}}


Attachments is error result in html."	Bug	closed	Template system	2.0	Normal	needsinfo	linebreaksbr linebreaks template-filters		Unreviewed	1	0	0	0	1	0
