Hello,

today I (finally) assembled a script to cycle through links in my document
(think "select next link"). A huge part of my daily use cases cover the
work with HTML and Markdown documents. With the latter I extensively use
´[[Wikilinks]]´ to connect notes. After wishing for a “jumpt to next link”
functionality for some time, I just found the time to set it up for BBEdit
and I’d like to share it in case other people have similar needs.

The steps are quite simple:

1. Put together regular expressions that match whatever you consider a link
2. Record that search with Apple’s Scripteditor
3. Assign shortcuts to the search.

Result: with a simple shortcut (in my case ctrl+n) I can select and cylce
through all links of a document.

Some elaboration:

ad 1. Finding the right regex pattern is an art in itself. Here is mine:

(?x:
(?P<Wikilink>\[\[.+?\]\]) |
(?P<Markdown_normal>!*\[[^[]+?\]\(.+?\)) |
(?P<Markdown_short>\[.+?\]\[.+?\]) |
(?P<Markdown_footnote>^\[.+?\]:) |
(?P<HTML><a.+?>.+?</a>) |
(?P<WWW>www\.\S+) |
(?P<Mail>\S+?@\S+) |
(?P<httm>http\S+)
)

the `(?x:)` part tells the search to ignore whitespace, hence you can make
your patterns a little more legible. Each line defines a pattern for what
should be considered “a link”. `(?P<name>xyz)` just defines names for the
pattern xyz in this line.
So in my case, I wanted [[Wikilinks]], Markdown-Links, HTML’s <a
href>-Links, email adresses and everything that starts with “http” or
“www.” to be considered a link. Of course you could change and add the
patterns to fit your needs.

ad 2.
- Copy the pattern into the Find Window (adapt and tweak the lines to your
desire)
- Fire up Scripteditor. In a new script hit “record”. Execute the Find
Command in BBEdit. Stop the recording and save the resulting script. You
might want to tweak with the options of the resulting Applescript (eg. add
options `{…, backwards:true, wrap around:true}`) if you also want a “find
previous link” version or if you want to continue the search after you
reached the top/bottom of your file.

ad 3. I won’t recommend shortcuts – you’ll have to figure them out yourself
:-)

Hope, this might be helpful,
Roland

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/CABybPXYXezZgxCQ-558WYqi5mbuHtgOdaDMkaVAdG50jCmSyEA%40mail.gmail.com.

Reply via email to