LazyWebLinks

Summary: Cause markup text beginning with "www." to be automatically converted into a link to an external site
Version: 20171011
Prerequisites:
Status:
Maintainer: Petko
Categories: Links, Editing, PHP72

Goal

Cause markup text beginning with "www." to be automatically converted into a link to an external site.

Solution

Add the following code to a local customization file:

Markup('lazyweb','<wikilink',
  "/\\bwww\\.[^\\s$UrlExcludeChars]*[^\\s.,?!$UrlExcludeChars]/",
  "LazyWebLinks");

function LazyWebLinks($m) {
  extract($GLOBALS["MarkupToHTML"]); # get $pagename
  return Keep(MakeLink($pagename, 'http://'.$m[0], $m[0]), 'L');
}

Discussion

This recipe causes any text beginning with "www.", such as www.pmwiki.org, to be automatically converted to an http-link to an external site. This recipe has been enabled on this page to allow experimentation.

Does this recipe "play nicely" with Approve URLs? Doesn't seem to be working below... --Peter Bowers July 18, 2010, at 01:55 PM

See PITS:00036 (Main.ApprovedUrls doesn't work with Cookbook.LazyWebLinks). --Petko July 18, 2010, at 03:16 PM

Contributors

  • Petko update for PHP 5.5 and 7.2.
  • jr, Jun-16-2004
  • Pm, Jun-16-2004

Sandbox

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.