Jump to content

Module:Multi-section link: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
create
 
remove unnecessary do ... end block
Line 14: Line 14:
return string.format('[[%s]]', displayParts[1])
return string.format('[[%s]]', displayParts[1])
else
else
local display
local display = {}
for i, s in ipairs(displayParts) do
do
display = {}
table.insert(display, s)
table.insert(display, string.rep('§', i))
for i, s in ipairs(displayParts) do
table.insert(display, s)
table.insert(display, string.rep('§', i))
end
table.remove(display) -- Remove the extra "§§" markers from the end
display = table.concat(display, ' ')
end
end
table.remove(display) -- Remove the extra "§§" markers from the end
display = table.concat(display, ' ')
local page = displayParts[1]
local page = displayParts[1]
local fragment = displayParts[nParts]
local fragment = displayParts[nParts]

Revision as of 03:13, 23 March 2015

-- This module creates a section link with multiple section names.

local p = {}

function p._main(args)
	local displayParts = {}
	for i, v in ipairs(args) do
		displayParts[i] = v
	end
	local nParts = #displayParts
	if nParts < 1 then
		error('no page name found in parameter |1=', 2)
	elseif nParts == 1 then
		return string.format('[[%s]]', displayParts[1])
	else
		local display = {}
		for i, s in ipairs(displayParts) do
			table.insert(display, s)
			table.insert(display, string.rep('§', i))
		end
		table.remove(display) -- Remove the extra "§§" markers from the end
		display = table.concat(display, ' ')
		local page = displayParts[1]
		local fragment = displayParts[nParts]
		return string.format('[[%s#%s|%s]]', page, fragment, display)
	end
end

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		wrappers = 'Template:Multi-section link'
	})
	return p._main(args)
end

return p