Changeset 145

Show
Ignore:
Timestamp:
03/15/06 00:22:43 (6 years ago)
Author:
mj
Message:

Expanded the link expansion to follow more WP conventions

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • wikipedia/godmode-light/trunk/godmode-light.js

    r144 r145  
    224224// Simple MediaWiki markup expander 
    225225// ----------------------------------------------------------------------------- 
     226// [[link]] and [[link|title]] 
    226227var _mw_link = /[[]{2}([^\]|]+)(?:|\|([^\]]+))]]/; 
    227228function mw_expand(text) { 
     
    229230    var match = _mw_link.exec(text); 
    230231    var link = match[1]; 
    231     var title = match[2] || link; 
    232     link = '<a href="/wiki/' + link.replace(' ', '_') + '">' + title + '</a>' 
     232    var title = match[2]; 
     233    if (!title) { 
     234      title = link; 
     235      title.replace('\s+\([^\)]*\)', '');             // Hide parenthesized page qualifiers 
     236      title.replace('^[^:]+:', '');                   // Hide namespace 
     237    } 
     238    link = link.replace(' ', '_');                    // Replace spaces with underscores 
     239    link = link[0].toUpperCase() + link.substring(1); // Uppercase first character 
     240    link = '<a href="/wiki/' + link + '">' + title + '</a>' 
    233241    text = text.replace(_mw_link, link) 
    234242  }