Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Paragraph Packing

Reply
Thread Tools

Paragraph Packing

 
 
Dr John Stockton
Guest
Posts: n/a
 
      12-11-2005
Page <URL:http://www.merlyn.demon.co.uk/js-quick.htm> now contains code
to pack text into multiple paragraphs of given right margin (the nominal
range is from 1 to nearly Infinity).


function Pak(F) { var S = F.Code.value, L = +F.Len.value, J, Re
S = S.replace(/(\r?\n){2,}/g, "\u0000").replace(/(\r?\n)/g, " ")
S = S.replace(/\s+/g, " ").split("\u0000")
if (L<1) L = F.Len.value = 1
Re = new RegExp("(.{1," + L + "}) ", "g")
J = S.length ; while (J--)
S[J] = (S[J].replace(/^\s+/, "")+" ").replace(Re, "$1\n")
F.Code.value = S.join("\n") }


F.Code is the I/O textarea; Code.L gives the margin.

The input paragraph separator is an empty line or lines.

It works in my IE4 ; any comment, particularly in respect of recognising
line-ends in non-Windows systems ?

Also - is anything wrong with using \u0000 as a marker?


The feature can be used to normalise badly-posted plain text, for more
comfortable reading.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      12-13-2005
Dr John Stockton wrote:
[...]
> It works in my IE4 ; any comment, particularly in respect of recognising
> line-ends in non-Windows systems ?


Seems to work fine in Safari 1.0.3, it does not recognise new lines in
IE 5.2 (Mac). I'll mess around with and see if I can find the
appropriate character - maybe \u0000 is the issue.


[...]


--
Rob
 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      12-13-2005
JRS: In article <439e9bbb$0$3672$5a62ac22@per-qv1-newsreader-
01.iinet.net.au>, dated Tue, 13 Dec 2005 20:00:27 local, seen in
news:comp.lang.javascript, RobG <> posted :
>Dr John Stockton wrote:
>[...]
>> It works in my IE4 ; any comment, particularly in respect of recognising
>> line-ends in non-Windows systems ?

>
>Seems to work fine in Safari 1.0.3, it does not recognise new lines in
>IE 5.2 (Mac). I'll mess around with and see if I can find the
>appropriate character - maybe \u0000 is the issue.


Could be; for test purposes one can use the uncontentious but rare #
instead; literally or as \u0023 (?).

But I'd look closely at the two (\r?\n) ... It may be necessary to do
them in two stages each, first for \r\n and second for \r|\n.


Thanks for looking.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why choose a paragraph element for a paragraph? dorayme HTML 112 03-30-2009 10:56 PM
How to put a HTML paragraph on a WebForm ad ASP .Net 4 02-23-2006 07:59 PM
HTML Paragraph question MW de Jager ASP .Net 9 07-06-2005 02:02 PM
Re: read a paragraph via scrit? Anno Siegel Perl 0 04-01-2004 01:25 PM
Paragraph Name Jim Heavey ASP .Net 2 12-04-2003 05:00 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57