Module:Make list: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
(Created page with "local p = {} local text_util = require('Module:Text Utility') function p.split(splitstr, separator) local b = text_util.split(splitstr, separator) return b end function...")
 
mNo edit summary
 
Line 38: Line 38:
end
end


function p.makelinks(frame)
function p.makelist(frame)
   return p.parse(frame.args, 'ul')
   return p.parse(frame.args, 'ul')
end
end


function p.makelinksordered(frame)
function p.makelistordered(frame)
   return p.parse(frame.args, 'ol')
   return p.parse(frame.args, 'ol')
end
end

Latest revision as of 20:31, 19 December 2020


local p = {}
local text_util = require('Module:Text Utility')

function p.split(splitstr, separator)
  local b = text_util.split(splitstr, separator)
  return b
end

function p.parse(args, type)
	frame = mw.getCurrentFrame()
	if args.args ~= nil then
	  args = args.args
	end
	local type = type or 'ul'
	local separator = '%s*' .. (args[2] or ',') .. '%s*'
	local style = args[3] or ''
	local class = args[4] or ''
	if style ~= '' then
		style = ' style="' .. style .. '"'
	end
	if class ~= '' then
		class = ' class="' .. class .. '"'
	end
	local prefix = '<' .. type .. class .. style .. '>'
	local postfix = '</' .. type .. '>'
	local b = p.split(args[1], separator)
	local returnstr = ''
	local returnstrformat
	
	returnstrformat = function(segment)
		return '<li>' .. segment .. '</li>'
	    end
	
	for i, piece in ipairs(b) do
	  returnstr = returnstr .. returnstrformat(piece)
	end
	return prefix .. returnstr .. postfix
end

function p.makelist(frame)
  return p.parse(frame.args, 'ul')
end

function p.makelistordered(frame)
  return p.parse(frame.args, 'ol')
end


return p