truncate_words removes newlines as well as truncating text
|Reported by:||Owned by:||nobody|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The truncate_words function in django.utils.text and used by the truncatewords filter strips out newline characters from it's output. This is a problem if you then want to chain the output into another filter that utilises newlines (such as linebreaks).
The attached patch fixes this by first breaking the input text into lines, adding each line into the output (including original linebreaks), before truncating the final line to meet the word count.
Change History (7)
comment:1 Changed 9 years ago by
|Patch needs improvement:||unset|
|Triage Stage:||Unreviewed → Design decision needed|