On Fri, 12 Sep 2008 23:30:23 +0200, "EnjoyNews" <mh********@mail.dkwrote
in <48***********************@dtext02.news.tele.dk> :
>I can see what you do in the script, but how do I get it into the
Well, I don't think you want to use 'onkeyup'. What if the user backspaces
or moves the insertion point? I would suggest using
'onblur=functionwhatever()' or even better a 'preview' button with
'onclick=functionwhatever()'.
functionwhatever should get the 'document.form.formname.textareaname.value'
and put it through the series of conversion to remove returns (/r), convert
newline(/n), white space, tab and even some special characters (what if
someone cuts and pastes with stuff like angle brackets, smart quotes and
fractions). The edited/modified/converted string is then stored as your
created element.
I used this to convert stuff --
// Cleanup extrranious characters and make html friendly
function clean(asd, sing){
asd=asd.replace(/\r/g,"") //supress 'returns' used in IE and Opera
asd=asd.replace(/\n\ \ \ /g,"\n\n") //change space indent paragraph
to double space
asd=asd.replace(/\n\t/g,"\n\n") //change tabbed indent paragraph
to double space
asd=asd.replace(/\t/g," ") //change tabs to spaces
asd=asd.replace(/\s+$/,"") //remove trailing white space
asd=asd.replace(/^\s+/,"") //remove leading white space
asd=asd.replace(/\ +\n/g,"\n") //remove trailing white space on line
asd=asd.replace(/\n\ +/g,"\n") //remove leading white space on line
i=asd.indexOf(""") //smart quotes don't work as RegExp
while (i>0){asd=asd.substring(0,i)+"\""+asd.substr(i+1); i=asd.indexOf(""")}
i=asd.indexOf(""")
while (i>0){asd=asd.substring(0,i)+"\""+asd.substr(i+1); i=asd.indexOf(""")}
i=asd.indexOf("‘")
while (i>0){asd=asd.substring(0,i)+"\'"+asd.substr(i+1); i=asd.indexOf("‘")}
asd=asd.replace(/\'/g,"\'") //single smart right quote -->
single quote
// replace common special characters
asd=asd.replace(/&/g,"&") //ampersand
asd=asd.replace(/…/g,"…") //elipsis
asd=asd.replace(/\.\.\./g,"…") //three period to elipsis
asd=asd.replace(/©/g,"©") //copy
asd=asd.replace(/½/g,"½") //fraction 1/2
asd=asd.replace(/¼/g,"¼") //fraction 1/4
asd=asd.replace(/¾/g,"¾") //fraction 3/4
asd=asd.replace(/<</g,"«") // <<
asd=asd.replace(/>>/g,"»") // >>
asd=asd.replace(/</g,"<") // <
asd=asd.replace(/>/g,">") // >
asd=asd.replace(/—/g,"—") // em dash
asd=asd.replace(/---/g,"–") // -- --emdash
asd=asd.replace(/–/g,"–") // en dash
asd=asd.replace(/--/g,"–") // -- --endash
// cleanup lines and paragraphs
asd=asd.replace(/\n{2,}/g,"½¼½") //2+ new lines --½¼½
(temporary)
asd=asd.replace(/½¼½$/g,"") //remove final paragraph
asd=asd.replace(/\n/g,sing) //new line --space or <br>
asd=asd.replace(/½¼½/g,"<\/p>\n<p>") // ½¼½ --paragraph
asd=asd.replace(/\ {2,}/g," ") //multiple space --> space
return asd }
Of course, this can just be a series of .replace(--).replace(--) except for
the swmart quotes but this is easier to read and edit. The var 'sing'
controls what to do with a single new line -- new paragraph or new line.
You also have to check that <p& </pare proper at the start and end.
Oh, it nice that you remembered your manner and said thanks. That missing
ever so often <sigh>.