 format link makes au800 wikilink from theu800 given link andu800 display values. links areu800 escaped with colons ifu800 necessary andu800 links tou800 sections areu800 detected andu800 displayed with " u8c2a7 " asu800 au800 separator rather than theu800 standard mediawiki "#". used inu800 theu800 format link template. local libraryutil require 'libraryutil' local checktype libraryutilu82echecktype local checktypefornamedarg libraryutilu82echecktypefornamedarg local marguments lazily initialise module arguments local merror lazily initialise module error local yesno lazily initialise module yesno local pu800 helper functions local function getargs frame fetches theu800 arguments from theu800 parent frame. whitespace isu800 trimmed andu800 blanks areu800 removed. marguments require 'module arguments return margumentsu82egetargs frame parentonly true endu800 local function removeinitialcolon su800 removes theu800 initial colon from au800 string ifu800 present. return mwu800u82eustringu82ematch su800 ' .* ' endu800 local function maybeitalicize su800 shoulditalicize italicize su800 ifu800 su800 isu800 au800 string andu800 theu800 shoulditalicize parameter isu800 true. ifu800 su800 andu800 shoulditalicize then return ' ' .. su800 .. ' ' else return su800 endu800 endu800 local function parselink link parse au800 link andu800 return au800 table with theu800 link link'su800 components. these components areu800 link theu800 link stripped ofu800 anyu800 initial colon always present page theu800 page name always present section theu800 page name mayu800 beu800 nilu800 display theu800 display text ifu800 manually entered after au800 pipe mayu800 beu800 nilu800 link removeinitialcolon link find whether au800 faux display value hasu800 been added with theu800 magic word. local prepipe display mwu800u82eustringu82ematch link ' . .* ' link prepipe oru800 link find theu800 page ifu800 itu800 exists. foru800 links like #baru800 theu800 page will beu800 nilu800. local prehash posthash mwu800u82eustringu82ematch link ' . # .* ' local page ifu800 notu800 prehash then weu800 have au800 link like foou800 . page link elseif prehash   then weu800 have au800 link like foou800#baru800 . page prehash endu800 find theu800 section ifu800 itu800 exists. local section ifu800 posthash andu800 posthash   then section posthash endu800 return link link page page section section display display endu800 local function formatdisplay parsed options formats au800 display string based onu800 au800 parsed link table matching theu800 output ofu800 parselink andu800 anu800 options table matching theu800 input options foru800 _formatlink . local page maybeitalicize parsedu82epage optionsu82eitalicizepage local section maybeitalicize parsedu82esection optionsu82eitalicizesection ifu800 notu800 section then return page elseif notu800 page then return mwu800u82eustringu82eformat 'u8c2a7&nbsp; su800' section else return mwu800u82eustringu82eformat ' su800 u8c2a7&nbsp; su800' page section endu800 endu800 local function missingargerror target merror require 'module error' return merroru82eerror message 'u8d8aeu8d8b7u8d8a7 u8d9beu8db8cu8d988u8d986u8d8af u8db8cu8d8a7 u8d987u8d8afu8d981 u8d985u8d8b4u8d8aeu8d8b5 u8d986u8d8b4u8d8afu8d987u8e2808cu8d8a7u8d8b3u8d8aa u8c2a0 ' .. target .. '#u8d8aeu8d8b7u8d8a7u8d987u8d8a7 u8d8b1u8d8a7u8d987u8d986u8d985u8d8a7 ' endu800 main functions function pu800u82eformatlink frame theu800 formatlink export function foru800 useu800 inu800 templates. yesno require 'module yesno' local args getargs frame local link args 1u800 oru800 argsu82elink oru800 args 'u8d9beu8db8cu8d988u8d986u8d8af' local target args 3u800 oru800 argsu82etarget oru800 args 'u8d987u8d8afu8d981' ifu800 notu800 link oru800 target then return missingargerror 'u8d8a7u8d984u8daafu8d988 u8d982u8d8a7u8d984u8d8a8u8e2808cu8d8a8u8d986u8d8afu8db8c u8d9beu8db8cu8d988u8d986u8d8af' endu800 return pu800u82e_formatlink link link display args 2u800 oru800 argsu82edisplay oru800 args 'u8d986u8d985u8d8a7u8db8cu8d8b4' target target italicizepage yesno argsu82eitalicizepage oru800 args 'u8d8b5u8d981u8d8adu8d987 u8d8a7u8db8cu8d8aau8d8a7u8d984u8db8cu8daa9' italicizesection yesno argsu82eitalicizesection oru800 args 'u8d8a8u8d8aeu8d8b4 u8d8a7u8db8cu8d8aau8d8a7u8d984u8db8cu8daa9' categorizemissing argsu82ecategorizemissing oru800 args 'u8d8b1u8d8afu8d987u8e2808cu8d8a8u8d986u8d8afu8db8c u8d986u8d8a7u8d985u8d988u8d8acu8d988u8d8afu8d987u8d8a7' endu800 function pu800u82e_formatlink options theu800 formatlink export function foru800 useu800 inu800 modules. checktype '_formatlink' 1u800 options 'table' local function check keyu800 expectedtype foru800 brevity checktypefornamedarg '_formatlink' keyu800 options keyu800 expectedtype oru800 'string' true endu800 check 'link' check 'display' check 'target' check 'italicizepage' 'boolean' check 'italicizesection' 'boolean' check 'categorizemissing' normalize link andu800 target andu800 check that atu800 least oneu800 isu800 present ifu800 optionsu82elink   then optionsu82elink nilu800 endu800 ifu800 optionsu82etarget   then optionsu82etarget nilu800 endu800 ifu800 notu800 optionsu82elink oru800 optionsu82etarget then return missingargerror 'u8d9beu8d988u8d8afu8d985u8d8a7u8d986 format link' endu800 local parsed parselink optionsu82elink local display optionsu82edisplay oru800 parsedu82edisplay local catmissing optionsu82ecategorizemissing local category   find theu800 display text ifu800 notu800 display then display formatdisplay parsed options endu800 handle theu800 target option ifu800 present ifu800 optionsu82etarget then local parsedtarget parselink optionsu82etarget parsedu82elink parsedtargetu82elink parsedu82epage parsedtargetu82epage endu800 test ifu800 page exists ifu800 au800 diagnostic category isu800 specified ifu800 catmissing andu800 mwu800u82eustringu82elenu800 catmissing 0u800 then local title nilu800 ifu800 parsedu82epage then title mwu800u82etitleu82enewu800 parsedu82epage endu800 ifu800 title andu800 notu800 titleu82eisexternal andu800 notu800 titleu82eexists then category mwu800u82eustringu82eformat ' u8d8b1u8d8afu8d987 su800 ' catmissing endu800 endu800 format theu800 result asu800 au800 link ifu800 parsedu82elink display then return mwu800u82eustringu82eformat ' su800 su800' parsedu82elink category else return mwu800u82eustringu82eformat ' su800 su800 su800' parsedu82elink display category endu800 endu800 derived convenience functions function pu800u82eformatpages options pages formats anu800 array ofu800 pages using formatlink andu800 theu800 given options table andu800 returns itu800 asu800 anu800 array. nilu800 values areu800 notu800 allowed. local retu800 foru800 iu800 page inu800 ipairs pages dou800 retu800 iu800 pu800u82e_formatlink link page categorizemissing optionsu82ecategorizemissing italicizepage optionsu82eitalicizepage italicizesection optionsu82eitalicizesection endu800 return retu800 endu800 return pu800 