MCPcopy
hub / github.com/django/django / linebreaksbr

Function linebreaksbr

django/template/defaultfilters.py:499–508  ·  view source on GitHub ↗

Convert all newlines in a piece of plain text to HTML line breaks (``<br>``).

(value, autoescape=True)

Source from the content-addressed store, hash-verified

497@register.filter(is_safe=True, needs_autoescape=True)
498@stringfilter
499def linebreaksbr(value, autoescape=True):
500 """
501 Convert all newlines in a piece of plain text to HTML line breaks
502 (``<br>``).
503 """
504 autoescape = autoescape and not isinstance(value, SafeData)
505 value = normalize_newlines(value)
506 if autoescape:
507 value = escape(value)
508 return mark_safe(value.replace("\n", "<br>"))
509
510
511@register.filter(is_safe=True)

Callers 7

contentsMethod · 0.90
test_newlineMethod · 0.90
test_carriageMethod · 0.90
test_carriage_newlineMethod · 0.90
test_non_string_inputMethod · 0.90
test_autoescapeMethod · 0.90
test_autoescape_offMethod · 0.90

Calls 3

normalize_newlinesFunction · 0.90
escapeFunction · 0.90
mark_safeFunction · 0.90

Tested by 6

test_newlineMethod · 0.72
test_carriageMethod · 0.72
test_carriage_newlineMethod · 0.72
test_non_string_inputMethod · 0.72
test_autoescapeMethod · 0.72
test_autoescape_offMethod · 0.72