D
Dr John Stockton
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.
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.