Revision of Twine: <<autolink>> from Thu, 06/20/2013 - 10:44

This macro, when surrounding a span of text, will search through the text, finds words that are also names of passages in the story, and converts them to internal links.

* Since Twine passage names are case-sensitive, this is also case-sensitive.
* It currently only matches single ASCII words (letters and numbers) and hyphens contained, but currently not apostrophe-containing words.

(function(){version.extensions.autolinkMacro={major:1,minor:0,revision:0};
macros.autolink={handler:function(g,e,f,b){function tagcontents(starttag,endtag,k){var a=b.source.slice(k),l=0,c="";
for(var i=0;i<a.length;i++){var w=endtag.length;if(a.substr(i,w)==endtag){if(l==0){b.nextMatch=k+i+w;
return c}else{l--;c+=a.charAt(i)}}else{if(a.substr(i,starttag.length)==starttag){l++
}c+=a.charAt(i)}}return""}var k=b.source.indexOf(">>",b.matchStart)+2,d=tagcontents("<<"+e,"<<end"+e+">>",k),bs=String.fromCharCode(92),re=new RegExp("(["+bs+"w-]+)","g"),words,len;
do{words=re.exec(d);if(words&&tale.has(words[0])){len=words[0].length;
d=d.slice(0,words.index)+"[["+words[0]+"]]"+d.slice(words.index+len);
re.lastIndex+=(len)}}while(words);new Wikifier(g,d)}};macros.endautolink={handler:function(){}}
}());

Usage example:
* <<autolink>>The most popular pets are dogs and cats<<endautolink>> - Assuming the passage "dogs" exists, that becomes "dogs".

Not too sure of the name - might change it later.

Feel free to report any bugs to @webbedspace.

pensive-mosquitoes