Paragraph Packing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dr John Stockton

    Paragraph Packing

    Page <URL:http://www.merlyn.demo n.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").repla ce(/(\r?\n)/g, " ")
    S = S.replace(/\s+/g, " ").split("\u000 0")
    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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
    <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
  • RobG

    #2
    Re: Paragraph Packing

    Dr John Stockton wrote:
    [...][color=blue]
    > It works in my IE4 ; any comment, particularly in respect of recognising
    > line-ends in non-Windows systems ?[/color]

    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

    Comment

    • Dr John Stockton

      #3
      Re: Paragraph Packing

      JRS: In article <439e9bbb$0$367 2$5a62ac22@per-qv1-newsreader-
      01.iinet.net.au >, dated Tue, 13 Dec 2005 20:00:27 local, seen in
      news:comp.lang. javascript, RobG <rgqld@iinet.ne t.auau> posted :[color=blue]
      >Dr John Stockton wrote:
      >[...][color=green]
      >> It works in my IE4 ; any comment, particularly in respect of recognising
      >> line-ends in non-Windows systems ?[/color]
      >
      >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.[/color]

      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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
      <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

      Comment

      Working...