Anda dapat membuat halaman dokumentasi untuk buat pada modul Scribunto ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
-- This module implements {{section link}}. localcheckType=require('libraryUtil').checkType localp={} localfunctionmakeSectionLink(page,section,display) display=displayorsection page=pageor'' returnstring.format('[[%s#%s|%s]]',page,section,display) end localfunctionnormalizeTitle(title) title=mw.ustring.gsub(mw.ustring.gsub(title,"'",""),'"','') returnmw.title.new(mw.ustring.gsub(title,"%b<>","")).prefixedText end functionp._main(page,sections,options,title) -- Validate input. checkType('_main',1,page,'string',true) checkType('_main',3,options,'table',true) ifsections==nilthen sections={} elseiftype(sections)=='string'then sections={sections} elseiftype(sections)~='table'then error(string.format( "type error in argument #2 to '_main' ".. "(string, table or nil expected, got %s)", type(sections) ),2) end options=optionsor{} title=titleormw.title.getCurrentTitle() -- Deal with blank page names elegantly ifpageandnotpage:find('%S')then page=nil options.nopage=true end -- Make the link(s). localisShowingPage=notoptions.nopage if#sections<=1then locallinkPage=pageor'' localsection=sections[1]or'Catatan' localdisplay='§ '..section ifisShowingPagethen page=pageortitle.prefixedText ifoptions.displayandoptions.display~=''then ifnormalizeTitle(options.display)==normalizeTitle(page)then display=options.display..' '..display else error(string.format( 'Judul tampilan "%s" diabaikan karena '.. "tidak sama dengan judul halaman yang sebenarnya", options.display ),0) end else display=page..' '..display end end returnmakeSectionLink(linkPage,section,display) else -- Multiple sections. First, make a list of the links to display. localret={} fori,sectioninipairs(sections)do ret[i]=makeSectionLink(page,section) end -- Assemble the list of links into a string with mw.text.listToText. -- We use the default separator for mw.text.listToText, but a custom -- conjunction. There is also a special case conjunction if we only -- have two links. localconjunction if#sections==2then conjunction='​ and ' else conjunction=', and ' end ret=mw.text.listToText(ret,nil,conjunction) -- Add the intro text. localintro='§§ ' ifisShowingPagethen intro=(pageortitle.prefixedText)..' '..intro end ret=intro..ret returnret end end functionp.main(frame) localargs=require('Module:Arguments').getArgs(frame,{ wrappers='Template:Section link', valueFunc=function(key,value) value=value:match('^%s*(.-)%s*$')-- Trim whitespace -- Allow blank first parameters, as the wikitext template does this. ifvalue~=''orkey==1then returnvalue end end }) -- Sort the arguments. localpage localsections,options={},{} fork,vinpairs(args)do ifk==1then -- Doing this in the loop because of a bug in [[Module:Arguments]] -- when using pairs with deleted arguments. page=mw.text.decode(v,decodeNamedEntities) elseiftype(k)=='number'then sections[k]=v else options[k]=v end end -- Extract section from page, if present ifpagethen localp,s=page:match('^(.-)#(.*)$') ifpthenpage,sections[1]=p,send end -- Compress the sections array. localfunctioncompressArray(t) localnums,ret={},{} fornuminpairs(t)do nums[#nums+1]=num end table.sort(nums) fori,numinipairs(nums)do ret[i]=t[num] end returnret end sections=compressArray(sections) returnp._main(page,sections,options) end returnp