Mark, Your problem is a presentation problem and not a character problem, so testing for the presence of characters like new line characters will not work. Unfortunately, a reusable solution to this problem cannot be achieved. Logically we can presume that if text wraps the containing element becomes taller, so if we had a baseline height for a line of text in the same context as the containing element we can know if there is wrapping. Unfortunately without more information about your code this solution will not work. The reason is that the containing element may have unique presentation applied that prevents the accurate application of any baseline. This CSS may include padding, a border, or child elements that have float or position relative/absolute. This is further complicated in that text may wrap at different points cross browser even if everything else renders identically. Even if such unknown barriers were certain to not be present this is still a good bit of effort to apply a risky solution for a problem that appears to be entirely trivial to begin with.
Since this problem is purely presentational I would recommend using only CSS or XSL for your solution. Style the incoming text properly to fit the limitations of the layout instance or rethink the limitations of your layout. Thanks, Austin Cheney, CISSP From: [email protected] [mailto:[email protected]] On Behalf Of Mark McDonnell Sent: Tuesday, January 10, 2012 11:17 AM To: [email protected] Subject: [JSMentors] Finding which group of words have been rendered on a separate line Hi, Does any one know how to check when a single line of text has been rendered on two lines? An example can be seen here: http://jsfiddle.net/HSAj3/ Notice the text is just one line "My very seriously long sentence here" but when rendered the words break at "sentence here" and so they are placed on a separate line. I need to try and wrap each hypothetical 'line' in a span and thought I would do this with a regular expression but it wasn't that easy because although checking for a \r\n is easy, there is no line-break in the text, it's just *rendered* that way. I've seen suggestions already for wrapping first word of sentence in a span and checking its height but that only tell me whether a single sentence was forced (due to width constraints) onto one line and not which word(s) are on the second line. Any ideas appreciated. Kind regards, Mark -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected] -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
