Thank you Ronald.

I will give this a try and let you know of my results! Thanks SO much for helping me out with this!! That's really nice of you.

Cheers,
Todd

On Jun 14, 2007, at 12:31 PM, BBEdit-Scripting List wrote:

From: Todd Howard <[EMAIL PROTECTED]>
Date: June 14, 2007 7:50:14 AM EDT
Subject: BBEdit Scripting Noob With Task Sends Up Flare For Help!

I am a registered BBEdit user, on version 8.2.6.

I am new to scripting, so I might need a little hand-holding on this one...

I have a BBEdit document (roster-links.php) that has line after line of people's names, and surrounding each name is a unique A HREF tag. with a\r line break at the end of each string.

Example
<a href="display_artist.php?id=13" class="textlink">Tom Jones</a>
<a href="display_artist.php?id=33" class="textlink">Molly Anderson</a>

I have a second document (index.php), inside of which, THERE MAY BE SOME SUBSET of these people's names which appear throughout the text. These names appear with <b>...</b> tags around them, but no links.

My mission (I have no choice but to accept it!) is to ask BBEdit to "LOCATE names in roster-links.php (which will be the string of text between the opening A tag and the closing A tag WHICH APPEAR IN THE INDEX.PHP"), and in cases where the name appears in index.php, copy the entire matching A HREF tag from roster-links.php (which will, of course, include the person's name as well, which will be come the new, linked text in index.php) and locate the names in index.php that match and replace the name with <a href="unique- link.php">Firstname Lastname</a>

 here's the example again:

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?

Thank you so much in advance!!

Todd Howard
[EMAIL PROTECTED]

From: Ronald J Kimball <[EMAIL PROTECTED]>
Date: June 14, 2007 10:45:30 AM EDT
Subject: Re: BBEdit Scripting Noob With Task Sends Up Flare For Help!


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

Reply via email to