On Thu, Jun 14, 2007 at 07:50:14AM -0400, Todd Howard wrote:
> Example A
> <a href="display_artist.php?id=13" class="textlink">Tom Jones</a>
> <a href="display_artist.php?id=33" class="textlink">Molly Anderson</a>
> 
> Then in index.php, there might be this currently:
> 
> Watch as <b>Tom Jones</b> and his friend <b>Molly Anderson</b>  
> deliver first rate comedy together on stage.
> 
> Once the script runs, I'd like BBEdit to figure out and execute this  
> result:
> 
> Watch as <b><a href="display_artist.php?id=13" class="textlink">Tom  
> Jones</a></b> and his friend <b><a href="display_artist.php?id=33"  
> class="textlink">Molly Anderson</a></b> deliver first rate comedy  
> together on stage.
> 
> Is there anyone who'd be willing to help me with this? I don't even  
> believe I know how to "run" a script in BBEdit (never tried), let  
> alone author it. Is this a piece of cake for anyone?

Here's a Perl filter that reads in the links from the links file and then
substitutes them into the input text.  I fold whitespace in the names so
that it will catch names that are wrapped across multiple lines.

If you save it in the Filters folder, then you can run it on an open
document as a filter, after selecting the contents of the document.

You can also run it in Terminal, e.g.
  perl roster_links.pl index.php > index2.php

It won't rewrap the text after inserting the links; you'll want to do that
yourself.


#!perl

use strict;
use warnings;


# create a hash of names to links

my $links_file = 'roster-links.php';

open(LINKS, $links_file)
  or die "Can't open '$links_file': $!\n";

my %links;

while (<LINKS>) {
  chomp;

  my($name) = m,<a .*?>([^<]+)</a>,;

  $name =~ s/\s+/ /g;

  $links{$name} = $_;
}

close(LINKS);

local $/;


# process input, replacing names (delimited by <b></b>)
# with the appropriate links

my $text = <>;

$text =~
  s{(<b>)(.*?)(</b>)}
   {
     my($t1, $orig_name, $t2) = ($1, $2, $3);
     my $clean_name = $orig_name;
     $clean_name =~ s/\s+/ /g;
     $t1 . ($links{$clean_name} || $orig_name) . $t2;
   }sige;

print $text;

__END__


Ronald

-- 
------------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_script.shtml>
List archives: <http://www.listsearch.com/bbeditscripting.lasso>
To unsubscribe, send mail to:  <[EMAIL PROTECTED]>

Reply via email to