List Info

Thread: splitting loooooooong words?




splitting loooooooong words?
user name
2006-11-21 16:25:40
Greetingd!

Is there a template filter whitch splits a long word into
two pieces?
For example, I want no word longer that 10 characters.
Any long URL can break site's look

wordcount only wraps words, but if there is a very long
word, it does not work?
Do I have to create my own filter?

Viestards

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

splitting loooooooong words?
user name
2006-11-21 16:39:14
On 11/21/06, viestards <viestards.listsgmail.com> wrote:
> Is there a template filter whitch splits a long word
into two pieces?
> For example, I want no word longer that 10 characters.
> Any long URL can break site's look

If you want something that works on any text-based content,
then no.

If you're just worried about long URLs, though the
'urlizetrunc'[1]
filter will handle this for you. You might also look at its
implementation for ideas to create a more generic filter.

[1] http://www.djangoproject.com/documentation/temp
lates/#urlizetrunc

-- 
"May the forces of evil become confused on the way to
your house."
  -- George Carlin

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

splitting loooooooong words?
user name
2006-11-21 18:15:45
Here's a simple truncatechars filter:

from django.template import Library
register = Library()

register.filter
def truncatechars(value,arg=50):
    '''
    Takes a string and truncates it to the requested amount,
by
inserting an ellipses into the middle.
    '''
    arg = int(arg)
    if arg < len(value):
        half = (arg-3)/2
        return "%s...%s" %
(value[:half],value[-half:])
    return value

James Bennett wrote:
> On 11/21/06, viestards <viestards.listsgmail.com> wrote:
> > Is there a template filter whitch splits a long
word into two pieces?
> > For example, I want no word longer that 10
characters.
> > Any long URL can break site's look
>
> If you want something that works on any text-based
content, then no.
>
> If you're just worried about long URLs, though the
'urlizetrunc'[1]
> filter will handle this for you. You might also look at
its
> implementation for ideas to create a more generic
filter.
>
> [1] http://www.djangoproject.com/documentation/temp
lates/#urlizetrunc
>
> --
> "May the forces of evil become confused on the way
to your house."
>   -- George Carlin


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

splitting loooooooong words?
user name
2006-11-22 18:04:10
On 11/21/06, baxtergretschpages.com <mail.baxtergmail.com> wrote:
>
> Here's a simple truncatechars filter:

[snip]
Thanks!

unfortunately this only splits it into half, witch may be
not enough
if someone tries to wandalise  site with very long comments,
so I
created my custom filter.
Maybe I should put it where everyone can use it?

#----------------------------------------------
def splitwords(value,arg):

    "splits words from text which is longer than arg
count"

    # split words

    text_list=value.split(" ")

    try:
        length = int(arg)
    except ValueError: # invalid literal for int()
        return value # Fail silently.


    for word in text_list:

        """for every word longer than arg,
split it into arg chars pieces

        """

        if len(word)>length:

            text_list[text_list.index(word)]=("
").join(

                [word[i:i+length] for i in range(0,
len(word), length)])

    return " ".join(text_list)

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )