HTML removal

"Trever L. Adams" <[email protected]>
Newsgroups gmane.mail.spam.crm114
Message-ID <[email protected]>
Well, I think I have fix my code up fairly well. Bill, I am using just
bits and pieces of what you provided me. I hope you don't mind me
licensing it under the GPL v2 (possibly changing to v2+ later). If you
do, please let me know.

This code removes all HTML tags, all javascript, all style sheet
information, but keeps ALT tags, Title Tags, and description/keywords
meta tag information. This is the only information that may be useful
for processing it for content. I will probably be working on the
ALT/TITLE from img tags so they are saved and put at the end of the new
file. This is so they can't be used to screw up processing, but still
are used in processing.

I provide the file below my name for anyone interested.

Trever Adams

#    Copyright (C) 2008 Trever L. Adams; licensed under the
#    GNU Public License (GPL) version 2.  A copy of this license is included
#    in the distribution media, or obtain one from www.fsf.org .

{
}
return

# Turn all of the content of META tags into inline text
:find_meta:
{
isolate (:meta_txt: :good:)
alter (:meta_txt:) //
alter (:good:) //
     match <nocase> /<meta ([^>]*)>/ (:whole_meta_tag: :meta_txt:)
     {
         {
             match <nocase> [:whole_meta_tag:] /description"?([^>]*)>/
(:meta_txt: :good:)
             call /:keep_good_meta:/ [:*:good:] (:meta_txt:)
         }
         alius
         {
             match <nocase> [:whole_meta_tag:] /keywords"?([^>]*)>/
(:meta_txt: :good:)
             call /:keep_good_meta:/ [:*:good:] (:meta_txt:)
         }
         alius
         {
             alter (:meta_txt:) //
         }
     }
     alter (:whole_meta_tag:) /:*:meta_txt:/
     liaf
}
return

# Keep the good meta tags
:keep_good_meta: (:kgm_input:)
{
isolate (:kgm_meta_txt:)
     match <nocase> [:kgm_input:] /content\="?([^"]*)"?/ (:kgm_meta_txt:
:kgm_good:)
     alter (:kgm_meta_txt:) /:*:kgm_good:/
     return /:*:kgm_meta_txt: /
}

:de_html: (:show:)
{
     #  Remove all comments
     {
     match /<!--([^-]|-[^-]|--[^>])*-->/ (:whole_comment:)
     alter (:whole_comment:) //
     liaf
     }
     # Remove scripts
     {
     match /<[ \n\r]*script[^>]*>[^<]*<[ \n\r]*\/script[^>]*>/
(:whole_script:)
     alter (:whole_script:) //
     liaf
     }
     # Remove style tags
     {
     match /<[ \n\r]*style[^>]*>[^<]*<[ \n\r]*\/style[^>]*>/ (:whole_style:)
     alter (:whole_style:) //
     liaf
     }
     # Keep keywords and descriptions, kill all other meta tags
     call /:find_meta:/
     #  Keep only the alt and title sections of an IMG tag
     {
     isolate (:title_txt: :alt_txt:)
     match <nocase>  /<img ([^>]*)>/ (:whole_img_tag:)
     {
         {
             match <nocase> [:whole_img_tag:] /title="([^"]*)"/ (:trash:
:title_txt:)
         }
         alius
         {
             match <nocase> [:whole_img_tag:] /title='([^']*)'/ (:trash:
:title_txt:)
         }
         {
             match <nocase> [:whole_img_tag:] /title=[[:graph:]]*)/
(:trash: :title_txt:)
         }

         {
             match <nocase> [:whole_img_tag:] /alt="([^"]*)"/ (:trash:
:alt_txt:)
         }
         alius
         {
             match <nocase> [:whole_img_tag:] /alt='([^']*)'/ (:trash:
:alt_txt:)
         }
         {
             match <nocase> [:whole_img_tag:] /alt=[[:graph:]]*)/
(:trash: :alt_txt:)
         }
     }
       alter (:whole_img_tag:) / :*:alt_txt: :*:title_txt: /
     liaf
     }
     #   Get rid of every other tag, without mercy!
     {
     match <nocase> /<[^>]*>/ (:some_tag:)
     alter (:some_tag:) //
     liaf
     }
#    accept
}
return

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

_______________________________________________
Crm114-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/crm114-general
signature.asc (application/pgp-signature, 260 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iEYEARECAAYFAkhAFrsACgkQTmpiivh5HXNgwwCgq08QOMPb+x0HelaBg1uVqSX/
+XIAnj5/lINaT3+OTSILQNEgPUMjIYNA
=dNAT
-----END PGP SIGNATURE-----
signature.asc (application/pgp-signature, 259 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iEYEARECAAYFAkhAF2EACgkQTmpiivh5HXOY6wCeJmRaWC7P/EqZEZ0ZUpv9TYrE
EL8An38p49jtVsSA/h2zPTIhjDu2PtfK
=7h1d
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.