Zeroclanzhang(讨论 | 贡献)2024年1月21日 (日) 18:30的版本 (创建页面,内容为“local p = {} local function getListItem( data ) if not type( data ) == 'string' then return '' end return mw.ustring.format( '<li style="line-height: inherit; margin: 0">%s</li>', data ) end -- Returns an array containing the keys of all positional arguments -- that contain data (i.e. non-whitespace values). local function getArgNums( args ) local nums = {} for k, v in pairs( args ) do if type( k ) == 'number' and…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
This Lua module is used on 30,000+ pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them.
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
Lua错误 在模块:TNT的第167行:Missing Commons dataset I18n/Module:TNT.tab
This module implements {{collapsible list}}. Please see the template page for documentation.
localp={}localfunctiongetListItem(data)ifnottype(data)=='string'thenreturn''endreturnmw.ustring.format('<li style="line-height: inherit; margin: 0">%s</li>',data)end-- Returns an array containing the keys of all positional arguments-- that contain data (i.e. non-whitespace values).localfunctiongetArgNums(args)localnums={}fork,vinpairs(args)doiftype(k)=='number'andk>=1andmath.floor(k)==kandtype(v)=='string'andmw.ustring.match(v,'%S')thentable.insert(nums,k)endendtable.sort(nums)returnnumsend-- Formats a list of classes, styles or other attributes.localfunctionformatAttributes(attrType,...)localattributes={...}localnums=getArgNums(attributes)localt={}fori,numinipairs(nums)dotable.insert(t,attributes[num])endif#t==0thenreturn''-- Return the blank string so concatenation will work.endreturnmw.ustring.format(' %s="%s"',attrType,table.concat(t,' '))end-- TODO: use Module:List. Since the update for this comment is routine,-- this is blocked without a consensus discussion by-- [[MediaWiki_talk:Common.css/Archive_15#plainlist_+_hlist_indentation]]-- if we decide hlist in plainlist in this template isn't an issue, we can use-- module:list directly-- [https://en.wikipedia.org/w/index.php?title=Module:Collapsible_list/sandbox&oldid=1130172480]-- is an implementation (that will code rot slightly I expect)localfunctionbuildList(args)-- Get the list items.locallistItems={}localargNums=getArgNums(args)fori,numinipairs(argNums)dotable.insert(listItems,getListItem(args[num]))endif#listItems==0thenreturn''endlistItems=table.concat(listItems)-- hack around mw-collapsible show/hide jumpiness by looking for text-alignment-- by setting a margin if centeredlocaltextAlignmentCentered='text%-align%s*:%s*center'localcenteredTitle=(args.title_styleandargs.title_style:lower():match(textAlignmentCentered)orargs.titlestyleandargs.titlestyle:lower():match(textAlignmentCentered))localcenteredTitleSpacingifcenteredTitlethencenteredTitleSpacing='margin: 0 4em'elsecenteredTitleSpacing=''end-- Get class, style and title data.localcollapsibleContainerClass=formatAttributes('class','collapsible-list','mw-collapsible',notargs.expandand'mw-collapsed')localcollapsibleContainerStyle=formatAttributes('style',-- mostly work around .infobox-full-data defaulting to centered'text-align: left;',args.frame_style,args.framestyle)localcollapsibleTitleStyle=formatAttributes('style','line-height: 1.6em; font-weight: bold;',args.title_style,args.titlestyle)localjumpyTitleStyle=formatAttributes('style',centeredTitleSpacing)localtitle=args.titleor'List'localulclass=formatAttributes('class','mw-collapsible-content',args.hlistand'hlist')localulstyle=formatAttributes('style','margin-top: 0; margin-bottom: 0; line-height: inherit;',notargs.bulletsand'list-style: none; margin-left: 0;',args.list_style,args.liststyle)localhlist_templatestyles=''ifargs.hlistthenhlist_templatestyles=mw.getCurrentFrame():extensionTag{name='templatestyles',args={src='Hlist/styles.css'}}end-- Build the list.returnmw.ustring.format('%s<div%s%s>\n<div%s><div%s>%s</div></div>\n<ul%s%s>%s</ul>\n</div>',hlist_templatestyles,collapsibleContainerClass,collapsibleContainerStyle,collapsibleTitleStyle,jumpyTitleStyle,title,ulclass,ulstyle,listItems)endfunctionp.main(frame)localorigArgsifframe==mw.getCurrentFrame()thenorigArgs=frame:getParent().argsfork,vinpairs(frame.args)doorigArgs=frame.argsbreakendelseorigArgs=frameendlocalargs={}fork,vinpairs(origArgs)doiftype(k)=='number'orv~=''thenargs[k]=vendendreturnbuildList(args)endreturnp