https://sudoroom.org/mediawiki/index.php?title=Module:Unbulleted_list&feed=atom&action=history
Module:Unbulleted list - Revision history
2024-03-29T01:32:53Z
Revision history for this page on the wiki
MediaWiki 1.37.2
https://sudoroom.org/mediawiki/index.php?title=Module:Unbulleted_list&diff=8073&oldid=prev
Matt: adds module based on https://en.wikipedia.org/w/index.php?title=Module:Unbulleted_list&action=edit
2014-05-19T19:07:10Z
<p>adds module based on https://en.wikipedia.org/w/index.php?title=Module:Unbulleted_list&action=edit</p>
<p><b>New page</b></p><div>-- This module implements {{unbulleted list}} and {{hlist}}.<br />
<br />
local function getListItem( data, style, itemStyle )<br />
if not data then<br />
return nil<br />
end<br />
if style or itemStyle then<br />
style = style or ''<br />
itemStyle = itemStyle or ''<br />
return mw.ustring.format(<br />
'<li style="%s%s">%s</li>',<br />
style, itemStyle, data<br />
)<br />
else<br />
return mw.ustring.format(<br />
'<li>%s</li>',<br />
data<br />
)<br />
end<br />
end<br />
<br />
local function getArgNums( args )<br />
-- Returns an array containing the keys of all positional arguments<br />
-- that contain data (i.e. non-whitespace values).<br />
local nums = {}<br />
for k, v in pairs( args ) do<br />
if type( k ) == 'number' and <br />
k >= 1 and <br />
math.floor( k ) == k and <br />
mw.ustring.match( v, '%S' ) then<br />
table.insert( nums, k )<br />
end<br />
end<br />
table.sort( nums )<br />
return nums<br />
end<br />
<br />
local function getClass( listType, class )<br />
local classes = {}<br />
if listType == 'hlist' then<br />
table.insert( classes, 'hlist' )<br />
else<br />
table.insert( classes, 'plainlist' )<br />
end<br />
table.insert( classes, class )<br />
local ret<br />
if #classes == 0 then<br />
return nil<br />
end<br />
return mw.ustring.format( ' class="%s"', table.concat( classes, ' ' ) )<br />
end<br />
<br />
local function getStyle( listType, indent, style )<br />
local styles = {}<br />
if listType == 'hlist' then<br />
indent = indent and tonumber( indent )<br />
indent = tostring( ( indent and indent * 1.6 ) or 0 )<br />
table.insert( styles, 'margin-left: ' .. indent .. 'em;' )<br />
end<br />
table.insert( styles, style )<br />
if #styles == 0 then<br />
return nil<br />
end<br />
return mw.ustring.format( ' style="%s"', table.concat( styles, ' ' ) )<br />
end<br />
<br />
local function buildList( args, listType )<br />
local listItems = {}<br />
local argNums = getArgNums( args )<br />
for i, num in ipairs( argNums ) do<br />
local item = getListItem(<br />
args[ num ],<br />
args.li_style,<br />
args[ 'li_style' .. tostring( num ) ]<br />
)<br />
table.insert( listItems, item )<br />
end<br />
if #listItems == 0 then<br />
return ''<br />
end<br />
local class = getClass( listType, args.class ) or ''<br />
local style = getStyle( listType, args.indent, args.style ) or ''<br />
local ulStyle = ( args.ul_style and ( ' style="' .. args.ul_style .. '"' ) ) or ''<br />
return mw.ustring.format( <br />
'<div%s%s><ul%s>%s</ul></div>',<br />
class, style, ulStyle, table.concat( listItems )<br />
)<br />
end<br />
<br />
local function makeWrapper( listType )<br />
return function( frame )<br />
local origArgs<br />
if frame == mw.getCurrentFrame() then<br />
origArgs = frame:getParent().args<br />
for k, v in pairs( frame.args ) do<br />
origArgs = frame.args<br />
break<br />
end<br />
else<br />
origArgs = frame<br />
end<br />
<br />
local args = {}<br />
for k, v in pairs( origArgs ) do<br />
if type( k ) == 'number' or v ~= '' then<br />
args[ k ] = v<br />
end<br />
end<br />
return buildList( args, listType )<br />
end<br />
end<br />
<br />
return {<br />
hlist = makeWrapper( 'hlist' ),<br />
unbulleted = makeWrapper( 'unbulleted' )<br />
}</div>
Matt