I think you should create a set of tags that are truncatable, like <p>, <div>, 
and <span> and focus on truncating those, and ignore <b>, <em>, etc. Just make 
sure not to truncate the closing tags of those non-truncating tags so as to 
invalidate the HTML.

----- Original Message ----
From: Giant Jam Sandwich <[EMAIL PROTECTED]>
To: jQuery (English) <jquery-en@googlegroups.com>
Sent: Friday, April 6, 2007 6:18:03 PM
Subject: [jQuery] Re: Truncate Plugin v.2.0


The issue becomes the character count. If I pull the string as HTML,
and use the max length provided, then I would have to use a regular
expression to skip html tags in the count. That part would not be so
hard, but if the truncate needs to happen in the middle of a child
tag, I would have to pull in the close tags. Consider the following:

<p>This is a string to <b>demonstrate a technical issue with <em>this</
em> plugin.</b></p>

If the truncate happens immediately after the word "this", then I have
to add back the </em> and the </b>. Is this less complicated than I am
making it sound? Any suggestions would be appreciated.

Thanks for everyone's positive feedback so far!


On Apr 5, 9:55 am, "Andy Matthews" <[EMAIL PROTECTED]> wrote:
> Well, I suppose you could search for LAST child tag (of any type) of the
> selected tag, then truncate the  text inside that to make sure you still
> keep your formatting. So given your example:
> <p><b>This is my string to truncate.</b></p>
>
> You might end up with this:
> <p><b>This is my string to tr...</b></p>
> ----------
> Starting with this:
> <div>jquery is  the <i>BOMB</i> yo. It makes <a href="somelink.html">short
> work of coding</a></div>
>
> You'd end up with this:
> <div>jquery is  the <i>BOMB</i> yo. It makes <a href="somelink.html">short
> w...</a></div>
> ----------
> And finally, if there were no child tags:
> <p>I'm plain vanilla HTML and I'll die alone because I have no children</p>
>
> You'd get this:
> <p>I'm plain vanilla HTML and I'll die alone...</p>
>
> Your thoughts?
>
> andy
>
>
>
> -----Original Message-----
> From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
>
> Behalf Of Giant Jam Sandwich
> Sent: Thursday, April 05, 2007 8:25 AM
> To: jQuery (English)
> Subject: [jQuery] Re: Truncate Plugin v.2.0
>
> Hey Andy,
>
> Sorry about that. This was an updated release of an older version (which had
> the description of what the plugin did). If you view the source, you can see
> instructions on how to use the plugin. It is not a newsreader - it is for
> string manipulation. I will probably update the demo to better explain that.
>
> As an aside, this will need a 2.1 update soon enough. Currently, if you were
> to select a parent element, and the string within that element you wanted to
> truncate had HTML (child elements), you would loose that formatting. For
> instance:
>
> <p>
>    <b>This is my string to truncate.</b> </p>
>
> If you choose the paragraph tag as the element to parse the text, it will
> grab that (sans bold tag), and then append it back to the paragraph tag
> without the bold. I need to rethink how to handle this scenario. Any
> suggestions?
>
> Brian
>
> On Apr 5, 9:11 am, "Andy Matthews" <[EMAIL PROTECTED]> wrote:
> > What's it do? You have an example without explaining it's usage or
> > what exactly it does. You have news headlines on your example page, so
> > is it a newsreader? Your headlines are cut off so does it trim down a
> > string of text to a specified length?
>
> > andy
>
> > -----Original Message-----
> > From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED]
> > On
>
> > Behalf Of Giant Jam Sandwich
> > Sent: Wednesday, April 04, 2007 6:35 PM
> > To: jQuery (English)
> > Subject: [jQuery] Truncate Plugin v.2.0
>
> > Well, I have vastly improved this script. It was my first plugin for
> > jQuery, and after creating a few others, I decided to go back and make
> > some edits on this one. You can find the demo here:
>
> >http://reindel.com/blog/src/jquery_truncate/
>
> > Feedback is always welcome.
>
> > Brian- Hide quoted text -
>
> - Show quoted text -

Reply via email to