Opened 12 years ago
Closed 11 years ago
#19496 closed New feature (fixed)
truncatechars_html
Reported by: | Stefano Vettorazzi Campos | Owned by: | Daniele Procida |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | truncatechars |
Cc: | saturn5971 | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Hi,
why don't have something like truncatewords_html for chars?
I don't have experience with the Django's source code, so I don't have a patch. But I can try if you want.
Change History (13)
comment:1 by , 12 years ago
Easy pickings: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 12 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:3 by , 12 years ago
Used truncatewords_html as a guideline, added docs & tests. All tests pass under sqlite. Pull request here: https://github.com/django/django/pull/633
comment:4 by , 12 years ago
Patch needs improvement: | set |
---|
>>> truncatechars_html('<h1>test</h1>', 5) u'<h1>t ...</h1>'
Should return u'<h1>te...</h1>'. Truncatewords adds an extra space in front of the ellipsis but truncatechars doesn't.
comment:5 by , 11 years ago
Owner: | changed from | to
---|
comment:6 by , 11 years ago
The above issue should now be fixed. It also appears to have broken truncatechars which I've now fixed
comment:7 by , 11 years ago
Actually there still appears to be issues when using html with only one tag pair in it
comment:8 by , 11 years ago
I have marked this ticket as suitable for a first-time committer attending a Don't be afraid to commit workshop.
The next planned session will be hosted by Cardiff Dev Workshop on Saturday 8th June.
If you want to tackle this ticket before then, or at any time in fact, please don't let the fact that it's assigned to me stop you. Feel free to re-assign it to yourself and do whatever you like to it.
comment:9 by , 11 years ago
Owner: | changed from | to
---|
comment:10 by , 11 years ago
truncatechars_html was incorrectly adding the '...' to text that was under the truncate length but only by 3 or fewer characters:
>>> truncatechars_html('abcd', 4) u'a...'
I've provided an updated patch here, including an addition to the test:
comment:11 by , 11 years ago
Easy pickings: | unset |
---|---|
Version: | 1.4 → master |
I've left some comments on the PR for improvement.
comment:12 by , 11 years ago
Cc: | added |
---|---|
Keywords: | truncatechars added; truncatchars removed |
Thanks! I updated my pull request in accord with Timo's suggestions.
https://github.com/django/django/pull/1689
To eliminate redundant code between _html_chars and _html_words, I've collapsed them into a single function, _truncate_html. I made the requested documentation changes as well.
comment:13 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Sure; we've added truncatedchars; makes sense that there would be a HTML-sensitive equivalent.