anxara has asked for the wisdom of the Perl Monks concerning the following question:
I have a perl script that is given HTML (say in $html) and needs to parse $html into formatting appropriate for a .js (JavaScript) file that will be called via a <script type="text/javascript" src="myfile.js"> tag. My problem is that if $html contains JavaScript code instead of plain HTML, that JavaScript code does NOT need to be formatted (since it is already JavaScript). For instance, if I wanted to display a Google AdSense ad via this .js file, my script would have to parse the following (contained in $html):
<script type="text/javascript"><!-- google_ad_client = "0123456789"; google_alternate_color = "FFFFFF"; google_ad_width = 120; google_ad_height = 90; google_ad_format = "120x90_0ads_al_s"; //2007-05-16: adsense4u google_ad_channel = "1328300801"; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "000000"; google_color_text = "000000"; google_color_url = "78B749"; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.c +om/pagead/show_ads.js"> </script>
I want my script to be able to completely remove the first <script> and </script> tags (but not the code inbetween) since what is contained inbetween is pure JavaScript and should be kept intact/unparsed. However, the second <script> tag contains a "src" and so I want this tag to be parsed into a format suitable for a document.write(); JS statement. So it should look something like this after being parsed:
In the end, my goal is to be able to take the original HTML/JavaScript mix and parse it, via perl, into a form suitable for a .js file. I am not sure where to start and would appreciate any help provided. Thanks!<!-- google_ad_client = "0123456789"; google_alternate_color = "FFFFFF"; google_ad_width = 120; google_ad_height = 90; google_ad_format = "120x90_0ads_al_s"; //2007-05-16: adsense4u google_ad_channel = "1328300801"; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "000000"; google_color_text = "000000"; google_color_url = "78B749"; //--> document.write('<'+'script type="text/javascript" src="http://pagead2. +googlesyndication.com/pagead/show_ads.js">'); document.write('<'+'/script>');
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parsing HTML code for formatting into JavaScript
by jasonk (Parson) on Feb 10, 2009 at 16:48 UTC | |
Re: Parsing HTML code for formatting into JavaScript
by moritz (Cardinal) on Feb 10, 2009 at 16:51 UTC | |
by anxara (Initiate) on Feb 10, 2009 at 17:00 UTC | |
by moritz (Cardinal) on Feb 10, 2009 at 17:05 UTC | |
by anxara (Initiate) on Feb 10, 2009 at 17:33 UTC |
Back to
Seekers of Perl Wisdom