Stripping html tags

FlexibleLearning at aol.com FlexibleLearning at aol.com
Sat Nov 3 04:48:29 EDT 2007


This is a seriously detailed stripper, Jim!
 
Small error in syntax:

replace "<td" with  numtochar(160)&"<td" in pHtml
should be...
replace "<td"  with numtochar(160)&"td>" in pHtml
 
Also, a couple of lines were posted html2Txt-mangled. Could you  clarify:
  -----
replace " " with space in pHtml
replace "
" with return in pHtml
replace "

" with return in pHtml
-----

If you post the handler as plain text, any html formatted  text should be 
correctly handled by the emailer.
 
 
/H

-------------------------------
-------------------------------------------------
function  StripTags pHtml
local tRegex,tPrevText
get   ("é,à,ç")
get  it &  (",>,<,ê")
get  it &  (",è,©,•")
get  it &  (",',·,&")
-- add more chars if you wish,  then...
constant kHtml = it
constant kConvertedHtml =  "é,à,ç,>,<,ê,è,©"
--using contants means you cannot  accidentally
--    modify these vars and damage the  results
-----  
replace numtochar(13) with empty in  pHtml
replace tab with empty in pHtml
replace "<td" with  numtochar(160)&"<td" in pHtml
-----
put  replacetext(pHtml,"(?Usi)<SCRIPT.*</SCRIPT>","") into pHtml
put replacetext(pHtml,"(?Usi)<STYLE>.*</STYLE>","") into  pHtml
put replacetext(pHtml,"(?Usi)<\?.*\?>","") into  pHtml
-----
replace " " with space in  pHtml
replace "
" with return in pHtml
replace "

" with return in pHtml
-----
put   "<[^><]*>" into tRegex
put replacetext(pHtml,tRegex,"")  into pHtml
put replacetext(pHtml,tRegex,"") into pHtml
 
  ----- repeat replacements until there are no changes
repeat until tPrevText is pHtml
put pHtml into  tPrevText
put replacetext(pHtml," +",space) into  pHtml
put replacetext(pHtml,"^ ","") into pHtml
end repeat
-----
replace (space & return) with return in  pHtml
replace (return & space) with return in pHtml
filter pHtml without empty
replace numtochar(160) with empty in  pHtml
-----
replace """ with quote in  pHtml
repeat with i = 1 to the number of items of  kHtml
replace item i of kHtml with item i of  kConvertedHtml in pHtml
end repeat
-----
--put  pHtml into msg  --let's you see the result in the msg box
return  pHtml
end StripTags


Jim Ault
Las Vegas

------------------------------------------------
--------------------------------



   



More information about the use-livecode mailing list