 this module deu800 links most wikitext. require 'module nou800 globals local pu800 local getargs local function delinkreversepipetrick su800 ifu800 su800 match " .* nu800 " then check foru800 newlines oru800 multiple pipes. return su800 else return su800 match " .* " endu800 endu800 local function delinkpipetrick su800 local linkarea display "" "" weu800 need tou800 deal with colons brackets andu800 commas peru800 help pipe trick . first remove theu800 text before theu800 first colon ifu800 anyu800. ifu800 su800 match " " then su800 su800 match " . .* " ifu800 there areu800 nou800 colons grab allu800 ofu800 theu800 text apart from theu800 square brackets andu800 theu800 pipe. else su800 su800 match " .* " endu800 next upu800 brackets andu800 commas. ifu800 su800 match " . " then brackets trump commas. su800 su800 match " . . " elseif su800 match " " then ifu800 there areu800 nou800 brackets display only theu800 text before theu800 first comma. su800 su800 match " . .* " endu800 return su800 endu800 local function delinkwikilink su800 local result su800 deal with theu800 reverse pipe trick. ifu800 result match " " then return delinkreversepipetrick result endu800 result mwu800u82euriu800u82edecode result "path" decode percent encoded entities. leave underscores andu800 plus signs. result mwu800u82etextu82edecode result true decode html entities. check foru800 badu800 titles. tou800 dou800 this weu800 need tou800 find theu800 title area ofu800 theu800 link iu800u82eeu800. theu800 part before anyu800 pipes. local titlearea ifu800 result match " " then find ifu800 weu800'reu800 dealing with au800 piped link. titlearea result match " . .* " else titlearea result match " . " endu800 check foru800 badu800 characters. ifu800 mwu800u82eustringu82ematch titlearea " cu800 nu800 " then return su800 endu800 check foru800 categories interwikis andu800 files. local colonprefix result match " . .* " oru800 "" getu800 theu800 text before theu800 first colon. local nsu800 mwu800u82esiteu82enamespaces colonprefix seeu800 ifu800 this isu800 au800 known namespace ifu800 mwu800u82elanguageu82eisknownlanguagetag colonprefix oru800 nsu800 andu800 nsu800u82ecanonicalname "u8d9beu8d8b1u8d988u8d986u8d8afu8d987" oru800 nsu800u82ecanonicalname "u8d8b1u8d8afu8d987" then return "" endu800 remove theu800 colon ifu800 theu800 link isu800 using theu800 help colon trick . ifu800 result match " " then result " " .. result match " .* " endu800 deal with links using theu800 help pipe trick . ifu800 mwu800u82eustringu82ematch result " * " then return delinkpipetrick result endu800 find theu800 display area ofu800 theu800 wikilink ifu800 result match " " then find ifu800 weu800'reu800 dealing with au800 piped link. result result match " . . " remove newu800 lines from theu800 display ofu800 multiline piped links where theu800 pipe isu800 before theu800 first newu800 line. result result gsub " nu800" "" else result result match " . " endu800 return result endu800 local function delinkurl su800 assume weu800 have already delinked internal wikilinks andu800 that weu800 have been passed some text between twou800 square brackets foou800 . ifu800 theu800 text contains au800 line break itu800 isu800 notu800 formatted asu800 au800 urlu800 regardless ofu800 other content. ifu800 su800 match " nu800" then return su800 endu800 check ifu800 theu800 text hasu800 au800 valid urlu800 prefix andu800 atu800 least oneu800 valid urlu800 character. local valid_url_prefixes " " " " " " " " " " "mailto " "news " "ircu800 " local url_prefix foru800 iu800 vu800 inu800 ipairs valid_url_prefixes dou800 ifu800 mwu800u82eustringu82ematch su800 ' ' .. vu800 ..' " su800 .* ' then url_prefix vu800 break endu800 endu800 getu800 display text ifu800 notu800 url_prefix then return su800 endu800 su800 su800 match " " .. url_prefix .. " .* " grab allu800 ofu800 theu800 text after theu800 urlu800 prefix andu800 before theu800 final square bracket. su800 su800 match ' . " .* ' oru800 "" grab allu800 ofu800 theu800 text after theu800 first urlu800 separator character " . su800 mwu800u82eustringu82ematch su800 " su800* su800u82e* " oru800 "" ifu800 theu800 separating character wasu800 au800 space trim itu800 offu800. local s_decoded mwu800u82etextu82edecode su800 true ifu800 mwu800u82eustringu82ematch s_decoded " cu800" then return su800 else return s_decoded endu800 endu800 local function delinklinkclass su800 pattern delinkfunction ifu800 notu800 type su800 "string" then error "u8d8aau8d984u8d8a7u8d8b4 u8d8afu8d8b1 u8d9beu8db8cu8d988u8d986u8d8afu8d8b2u8d8afu8d8a7u8db8cu8db8c u8d988u8d8b1u8d988u8d8afu8db8c u8d8bau8db8cu8d8b1 u8d8b1u8d8b4u8d8aau8d987u8e2808cu8d8a7u8db8c." 2u800 endu800 ifu800 notu800 type pattern "string" andu800 mwu800u82eustringu82esubu800 pattern 1u800 1u800 " " then error 'u8d8a7u8d984u8daafu8d988u8db8c u8d986u8d8a7u8d985u8d8b9u8d8aau8d8a8u8d8b1 u8d8b4u8d986u8d8a7u8d8b3u8d8a7u8db8cu8db8c u8d8b4u8d8af. u8d8a7u8d984u8daafu8d988u8d987u8d8a7 u8d8a8u8d8a7u8db8cu8d8af u8d8a8u8d8a7 " " u8d8a2u8d8bau8d8a7u8d8b2 u8d8b4u8d988u8d986u8d8af.' 2u800 endu800 iterate over theu800 text string andu800 replace anyu800 matched text. using theu800 delink function. weu800 need tou800 iterate character byu800 character rather than just useu800 gsub otherwise nested links aren'tu800 detected properly. local result "" while su800   dou800 replace text using oneu800 iteration ofu800 gsub. su800 mwu800u82eustringu82egsub su800 pattern delinkfunction 1u800 append theu800 left most character tou800 theu800 result string. result result .. mwu800u82eustringu82esubu800 su800 1u800 1u800 su800 mwu800u82eustringu82esubu800 su800 2u800 1u800 endu800 return result endu800 function pu800u82e_delink args local text args 1u800 oru800 "" ifu800 argsu82erefs "yesu800" then remove anyu800 help strip markers representing refu800 tags. inu800 most situations this isu800 notu800 au800 good idea only useu800 itu800 ifu800 youu800 know what youu800 areu800 doing text mwu800u82eustringu82egsub text " uniq wu800* refu800 du800* qinu " "" endu800 ifu800 notu800 argsu82ecomments "nou800" then text text gsub " . " "" remove html comments. endu800 ifu800 notu800 argsu82ewikilinks "nou800" then text delinklinkclass text " . " delinkwikilink deu800 link wikilinks. endu800 ifu800 notu800 argsu82eurls "nou800" then text delinklinkclass text " . " delinkurl deu800 link urls. endu800 ifu800 notu800 argsu82ewhitespace "nou800" then replace single newu800 lines with au800 single space butu800 leave double newu800 lines andu800 newu800 lines only containing spaces oru800 tabs before au800 second newu800 line. text mwu800u82eustringu82egsub text " nu800 tu800 tu800 * nu800 tu800 * nu800 tu800 " " 1u800 2u800" text text gsub " tu800 " " " remove extra tabs andu800 spaces. endu800 return text endu800 function pu800u82edelink frame ifu800 notu800 getargs then getargs require 'module arguments .getargs endu800 return pu800u82e_delink getargs frame wrappers 'u8d8a7u8d984u8daafu8d988 u8d9beu8db8cu8d988u8d986u8d8afu8d8b2u8d8afu8d8a7u8db8cu8db8c' endu800 return pu800 