On Thu, Jan 17, 2013 at 11:10:05AM -0500, Adam Engst wrote:
> Thanks, John! I've never learned any perl, so I can't really parse
> what your script is doing, but it's not doing quite what I need. Take
> a look at these two files for a before and after view:
> 
> https://dl.dropbox.com/u/574336/AutoRip-original.md
> 
> and
> 
> https://dl.dropbox.com/u/574336/AutoRip-numbered.md
> 
> Basically, for the first Markdown source/destination pair (the source
> in the text, the destination with a URL after the paragraph), the
> asterisks need to be replace by 1, and then for the next pair, 2, and
> so on, sequentially.

Like John, I write Perl, but not AppleScript, so I'll offer this:

#!perl

my $src_counter = my $dest_counter = 0;

while (<>) {
  # replace source references
  s/\]\[\*\]/ '][' . ++$src_counter . ']' /eg;

  # replace destination references
  s/^\s*\[\*\]:/ '[' . ++$dest_counter . ']:' /e;

  print;
}

The first substitution finds the source references, which always look like
'][*]', and replaces each one with an incremented counter.

The second substitution finds the destination references, which always look
like '[*]:' at the beginning of a line, and replaces each one with another
incremented counter.

\s* allows for optional whitespace, in case you decide to indent the
destination references.

/e tells Perl to execute the replacement as Perl code.

/g tells Perl to repeat the substitution until it stops matching.  There
are never two destination references on the same line, so /g is unnecessary
on the second substitution.

HTH,
Ronald

P.S.  Thank you for all you do with TidBITS!

-- 
-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, 
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>



Reply via email to