Machines should work, people should think

I considered it a good idea to add icons to links to make them noticeable. [internal link icon] for internal links and [external link icon] for external ones.
At first we should draw pictures and add classes to style sheet

.linkext {
    background:transparent url(/files/images/linkext.png) no-repeat scroll right center;
    padding:2px 15px 2px 0px;
}

.linkint {
    background:transparent url(/files/images/linkint.png) no-repeat scroll right center;
    padding:2px 15px 2px 0px;
}

But then we must walk around all the links and add appropriate classes… Why? “Machines should work, people should think”! This motto becomes especially pleasant when somebody has already thought before you 😉 and created plugin for WordPress which replaces text on the fly during page generation using regular expressions.
I made all the internal links relative without http:// so the thing is just to install re.place plugin and add two simple rules. The first inserts class="linkext" into external links replacing

<a *href=("http[^>]*)>

by

<a class="linkext" href=\1>

and the second inserts class="linkint" into internl links replacing

<a *href=([^>]*)>

by

<a class="linkint" href=\1>

The second rule order must be greater then the first to make this replacements work properly.
According to the first rule the string class="linkext" will be inserted into external links and they will not be recognized by <a *href=([^>]*)> pattern.
The patterns contain < and > symbols so do not forget to set “Escape HTML characters” option in re.place “List view options” for proper displaying of re.place rule list.

Leave a Reply

[flagcounter image]