Module:Contents topic list
Appearance
(Redirected from Module:Sandbox/BrandonXLF/Module:Contents topic list)
Used by {{Contents topic list}}.
require('strict')localgetArgs=require('Module:Arguments').getArgslocalp={}-- Close <li> and <ul> elements enclosing deeper depthslocalfunctionclosePending(toClose,depth)localout=''while#toClose>0and(toClose[#toClose].depth>=depthordepth==0)doout=out..toClose[#toClose].closetable.remove(toClose,#toClose)endreturnoutendfunctionp.main(frame)localargs=getArgs(frame)localwikitext=frame:preprocess(args[1])localitems={}localout=''forindent,iteminwikitext:gmatch('(**) *([^\n]*)\n')dotable.insert(items,{#indent,item})end-- Match the last linelocallastIndent,lastItem=wikitext:match('(**) *([^\n]*)$')table.insert(items,{#lastIndent,lastItem})-- Elements that are currently openlocaltoClose={}-- Lowest depth of parent that forces all <li>s to be inlinelocalforcedInline=math.hugefori,iteminpairs(items)dolocallevel,text=unpack(item)out=out..closePending(toClose,level)iflevel==0then-- Just output out=out..text..'\n'else-- Create a new list if neededif#toClose==0ortoClose[#toClose].type~='ul'thenout=out..(forcedInline<=leveland'<ul class="content-inline-ul">'or'<ul>')toClose[#toClose+1]={depth=level-1,type='ul',close='</ul>'..(level==1and'\n'or'')}end-- Went up a level, discard forced inline and rest blockiflevel<=forcedInlinethenforcedInline=math.hugeendiftext:match('KEEP%-INLINE$')~=nilthen-- Line is marked by {{Inline sublist}}out=out..'<li>'..text:gsub(' *KEEP%-INLINE$','')forcedInline=math.min(level,forcedInline)elseifforcedInline<levelthen-- Inline forcedout=out..'<li>'..textelseifi<#itemsanditems[i+1][1]>levelthen-- Next item is deeper-- Remove ":" if first item is block-levelout=out:gsub(": '''''<ul>$","'''''<ul>")out=out..'<li class="content-sublist">'.."'''''"..text..": '''''"-- Treat remaining items in this list as block-leveltoClose[#toClose].restBlock=trueelseiftoClose[#toClose].restBlockthen-- Rest of list should be block levelout=out..'<li class="content-sublist">'.."'''''"..text.."'''''"else-- Normal list itemout=out..'<li>'..textendtoClose[#toClose+1]={depth=level,type='li',close='</li>'}endendout=out..closePending(toClose,0)return'<div class="content-list">\n'..out..'</div>'..frame:extensionTag{name='templatestyles',args={src='Template:Contents topic list/styles.css'}}endreturnp