「モジュール:Navbox/former」の版間の差分

削除された内容 追加された内容
Waiesu (会話 | 投稿記録)
Template:Navbox with columnsにおいてcol指定が不連続な場合にエラーが表示される不具合を修正; 不具合の報告による
Waiesu (会話 | 投稿記録)
91行目: 91行目:
if args.basestyle then basestyle = args.basestyle .. ';' end
if args.basestyle then basestyle = args.basestyle .. ';' end
local sortable_mt = {
__lt = function(a, b) return a.index < b.index end,
__concat = function(a, b)
local strA = (type(a) == 'table') and a.content or a or ''
local strB = (type(b) == 'table') and b.content or b or ''
return strA .. strB
end
}
local function sortable_args(tbl, index, content)
table.insert(tbl, {index = index, content = content})
setmetatable(tbl[#tbl], sortable_mt)
end
local switch = {
local switch = {
--common
--common
list = function(num, v) list[num] = '\n' .. v end,
list = function(num, v) sortable_args(list, num, '\n' .. v) end,
liststyle = function(num, v) liststyle[num] = v end,
liststyle = function(num, v) liststyle[num] = v end,
group = function(num, v) group[num] = v end,
group = function(num, v) group[num] = v end,
101行目: 113行目:
colheadercolspan = function(num,v) colheadercolspan[num] = v end,
colheadercolspan = function(num,v) colheadercolspan[num] = v end,
colheaderstyle = function(num,v) colheaderstyle[num] = v end,
colheaderstyle = function(num,v) colheaderstyle[num] = v end,
col = function(num,v) col[num] = '\n' .. v end,
col = function(num, v) sortable_args(col, num, '\n' .. v) end,
colstyle = function(num,v) colstyle[num] = v end,
colstyle = function(num,v) colstyle[num] = v end,
colwidth = function(num,v) colwidth[num] = v end,
colwidth = function(num,v) colwidth[num] = v end,
113行目: 125行目:
section = function(num, v) group[num] = v end,
section = function(num, v) group[num] = v end,
secttitlestyle = function(num, v) groupstyle[num] = v end,
secttitlestyle = function(num, v) groupstyle[num] = v end,
content = function(num, v) list[num] = '\n' .. v end,
content = function(num, v) sortable_args(content, num, '\n' .. v) end,
contentstyle = function(num, v) liststyle[num] = v end,
contentstyle = function(num, v) liststyle[num] = v end,
image = function(num, v) image[num] = v end,
image = function(num, v) image[num] = v end,
imageleft = function(num, v) imageleft[num] = v end,
imageleft = function(num, v) imageleft[num] = v end,
}
}
for k, v in pairs(args) do
for k, v in pairs(args) do
local str1, num, str2 = string.match(k, '(%D+)(%d+)(%D*)')
local str1, num, str2 = string.match(k, '(%D+)(%d+)(%D*)')
124行目: 137行目:
end
end
table.sort(list)
local num = 0
for i in pairs(list) do
rowspan = #list
num = num + 1
end
rowspan = num
end
end


165行目: 175行目:
result = result .. basestyle .. (args.titlestyle or '') .. '" colspan=' .. (colspan - (args.titlegroup and 1 or 0)) .. ' class="navbox-title">'
result = result .. basestyle .. (args.titlestyle or '') .. '" colspan=' .. (colspan - (args.titlegroup and 1 or 0)) .. ' class="navbox-title">'
if (args.navbar == 'plain' or args.navbar == 'off') or (not args.name and (child or none)) then
if (args.navbar == 'plain') or (not args.name and (child or none)) then
result = result .. '<div style="float:left;width:6em;">&nbsp;</div>'
result = result .. '<div style="float:left;width:6em;">&nbsp;</div>'
elseif args.navbar ~= 'off' then
else
local tbl = {args = {args.name, mini = '1', fontstyle = basestyle .. (args.titlestyle or '') .. ';border:none;', fontcolor = ''}}
local tbl = {args = {args.name, mini = '1', fontstyle = basestyle .. (args.titlestyle or '') .. ';border:none;', fontcolor = ''}}
result = result .. '<div style="float:left;width:6em;text-align:left;">' .. p.tnavbar(tbl) .. '</div>'
result = result .. '<div style="float:left;width:6em;text-align:left;">' .. p.tnavbar(tbl) .. '</div>'
179行目: 189行目:
result = result .. '<span ' .. args.titleclass .. ' style="font-size:' .. ((child or none) and '100' or '110') .. '%;">' .. args.title .. '</span>'
result = result .. '<span ' .. args.titleclass .. ' style="font-size:' .. ((child or none) and '100' or '110') .. '%;">' .. args.title .. '</span>'
if args.state == 'plain' or args.state == 'off' then
if args.state == 'plain' then
result = result .. '<div style="float:right;width:6em;">&nbsp;</div>'
result = result .. '<div style="float:right;width:6em;">&nbsp;</div>'
end
end
201行目: 211行目:
result = result .. '<td style="width:0;' .. (args.imageleftstyle or '') .. '" rowspan=' .. rowspan .. '>' .. args.imageleft .. '</td>'
result = result .. '<td style="width:0;' .. (args.imageleftstyle or '') .. '" rowspan=' .. rowspan .. '>' .. args.imageleft .. '</td>'
end
end
if group[1] then
local j = list[1].index
if group[j] then
result = result .. '<td class="navbox-group ' .. (args.groupclass or '') .. '" style="' .. basestyle .. (args.groupwidth and ('width:' .. args.groupwidth .. ';') or '') .. (args.groupstyle or '') .. ';' .. (groupstyle[1] or '') .. '">' .. group[1] .. '</td><td style="text-align:left;'
result = result .. '<td class="navbox-group ' .. (args.groupclass or '') .. '" style="' .. basestyle .. (args.groupwidth and ('width:' .. args.groupwidth .. ';') or '') .. (args.groupstyle or '') .. ';' .. (groupstyle[j] or '') .. '">' .. group[j] .. '</td><td style="text-align:left;'
else
else
result = result .. '<td colspan=2 style="'
result = result .. '<td colspan=2 style="'
end
end
result = result .. (args.groupwidth and '' or 'width:100%;') .. 'padding:0;' .. (args.liststyle or '') .. ';' .. (odd == 'odd' and (args.oddstyle or '') or (args.evenstyle or '')) .. ';' .. (liststyle[1] or '') .. '" class="navbox-list navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd) .. ' ' .. (args.listclass or '') .. '"><div style="padding:' .. (args.list1padding or args.listpadding or '0 0.25em') .. '">' .. list[1] .. '</div></td>'
result = result .. (args.groupwidth and '' or 'width:100%;') .. 'padding:0;' .. (args.liststyle or '') .. ';' .. (odd == 'odd' and (args.oddstyle or '') or (args.evenstyle or '')) .. ';' .. (liststyle[j] or '') .. '" class="navbox-list navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd) .. ' ' .. (args.listclass or '') .. '"><div style="padding:' .. (args.list1padding or args.listpadding or '0 0.25em') .. '">' .. list[1] .. '</div></td>'
if args.image then
if args.image then
result = result .. '<td style="width:0;' .. (args.imagestyle or '') .. '" rowspan=' .. rowspan .. '>' .. args.image .. '</td>'
result = result .. '<td style="width:0;' .. (args.imagestyle or '') .. '" rowspan=' .. rowspan .. '>' .. args.image .. '</td>'
215行目: 226行目:
--remaining groups/lists
--remaining groups/lists
local function body2()
local function body2()
for i = 2, #list do
list[1] = nil
for i in pairs(list) do
odd, even = even, odd
odd, even = even, odd
if group[i] then
local j = list[i].index
if group[j] then
result = result .. '<tr><td class="navbox-group ' .. (args.groupclass or '') .. '" style="' .. basestyle .. (args.groupwidth and ('width:' .. args.groupwidth .. ';') or '') .. (args.groupstyle or '') .. ';' .. (groupstyle[i] or '') .. '">' .. group[i] .. '</td><td style="text-align:left;'
result = result .. '<tr><td class="navbox-group ' .. (args.groupclass or '') .. '" style="' .. basestyle .. (args.groupwidth and ('width:' .. args.groupwidth .. ';') or '') .. (args.groupstyle or '') .. ';' .. (groupstyle[j] or '') .. '">' .. group[j] .. '</td><td style="text-align:left;'
else
else
result = result .. '<tr><td colspan=2 style="'
result = result .. '<tr><td colspan=2 style="'
end
end
result = result .. (args.groupwidth and '' or 'width:100%;') .. 'padding:0;' .. (args.liststyle or '') .. ';' .. (odd == 'odd' and (args.oddstyle or '') or (args.evenstyle or '')) .. ';' .. (liststyle[i] or '') .. '" class="navbox-list navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd) .. ' ' .. (args.listclass or '') .. '"><div style="padding:' .. (args.listpadding or '0 0.25em') .. '">' .. list[i] .. '</div></td></tr>'
result = result .. (args.groupwidth and '' or 'width:100%;') .. 'padding:0;' .. (args.liststyle or '') .. ';' .. (odd == 'odd' and (args.oddstyle or '') or (args.evenstyle or '')) .. ';' .. (liststyle[j] or '') .. '" class="navbox-list navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd) .. ' ' .. (args.listclass or '') .. '"><div style="padding:' .. (args.listpadding or '0 0.25em') .. '">' .. list[i] .. '</div></td></tr>'
end
end
end
end
284行目: 295行目:
function p.with_columns(frame)
function p.with_columns(frame)
defArgs(frame)
defArgs(frame)
table.sort(col)
mw.log(#col)
top()
top()
if args.title then title() end
if args.title then title() end
if args.above then above() end
if args.above then above() end
if col[1] then
local coltbl = {}
local j = col[1].index
for i in pairs(col) do
local cols = '</div><table class="navbox-columns-table" style="border-spacing:2px;border-collapse:separate;text-align:left;margin:-2px;' .. ((colheader[j] or args.fullwidth) and 'width:100%;width:calc(100% + 4px);' or 'margin:0 auto;') .. (args.coltablestyle or '') .. '">'
coltbl[i] = {index = i, content = col[i], style = colstyle[i], width = colwidth[i]}
--Header row
if colheader[i] then
coltbl[i].header = colheader[i]
if colheader[j] then
cols = cols .. '<tr class="navbox-abovebelow" style="font-weight:bold;' .. (args.colheaderstyle or '') .. '">'
coltbl[i].headercolspan = colheadercolspan[i]
for i = 1, #col do
coltbl[i].headerstyle = colheaderstyle[i]
local j = col[i].index
end
if colfooter[i] then
if colheader[j] then
cols = cols .. '<td colspan=' .. (colheadercolspan[j] or '1') .. ' style="' .. (colheaderstyle[j] or '') .. '">' .. colheader[j] .. '</td>'
coltbl[i].footer = colfooter[i]
end
coltbl[i].footercolspan = colfootercolspan[i]
coltbl[i].footerstyle = colfooterstyle[i]
end
end
table.sort(coltbl, function(a, b)
if a and b then
return a.index < b.index
else
return a
end
end)
local cols = '</div><table class="navbox-columns-table" style="border-spacing:2px;border-collapse:separate;text-align:left;margin:-2px;' .. ((colheader[1] or args.fullwidth) and 'width:100%;width:calc(100% + 4px);' or 'margin:0 auto;') .. (args.coltablestyle or '') .. '">'
--Header row
if colheader[1] then
cols = cols .. '<tr class="navbox-abovebelow" style="font-weight:bold;' .. (args.colheaderstyle or '') .. '">'
for i, v in ipairs(coltbl) do
if v.header then
cols = cols .. '<td colspan=' .. (v.headercolspan or '1') .. ' style="' .. (v.headerstyle or '') .. '">' .. v.header .. '</td>'
end
end
cols = cols .. '</tr>'
end
end
--Main columns
cols = cols .. '</tr>'
end
--Main columns
if col[1] then
cols = cols .. '<tr style="vertical-align:top;' .. (args.colstyle or '') .. '">'
cols = cols .. '<tr style="vertical-align:top;' .. (args.colstyle or '') .. '">'
if colheader[1] or colfooter[1] or args.fullwidth then
if not (colheader[j] or colfooter[j] or args.fullwidth) then
if args.padding then args.padding = string.gsub(args.padding, '^0[ep]?[mx]?%?;?', 'off') end
local paddingoff = args.padding and string.find(args.padding, '^0[ep]?[mx]?%?;?')
if args.padding == 'off' then
if not paddingoff then
cols = cols .. '<td style="width:' .. (args.padding or '5em;') .. '">&nbsp;&nbsp;&nbsp;</td>'
cols = cols .. '<td style="width:' .. (args.padding or '5em;') .. '">&nbsp;&nbsp;&nbsp;</td>'
end
end
end
end
for i, v in ipairs(coltbl) do
for i = 1, #col do
local j = col[i].index
cols = cols .. '<td style="padding:0;' .. (args.oddcolstyle or '') .. ';' .. (v.style or '') .. ';width:' .. (v.width or args.colwidth or '10em;') .. '"><div>' .. v.content .. '</div></td>'
cols = cols .. '<td style="padding:0;' .. (args.oddcolstyle or '') .. ';' .. (colstyle[j] or '') .. ';width:' .. (colwidth[j] or args.colwidth or '10em;') .. '">' .. col[i] .. '</td>'
args.oddcolstyle, args.evencolstyle = args.evencolstyle, args.oddcolstyle
args.oddcolstyle, args.evencolstyle = args.evencolstyle, args.oddcolstyle
end
end
cols = cols .. '</tr>'
cols = cols .. '</tr>'
--Footer row
end
if colfooter[j] then
--Footer row
cols = cols .. '<tr class="navbox-abovebelow" style="font-weight:bold;' .. (args.colfooterstyle or '') .. '">'
if colfooter[1] then
for i = 1, #col do
cols = cols .. '<tr class="navbox-abovebelow" style="font-weight:bold;' .. (args.colfooterstyle or '') .. '">'
local j = col[i].index
for i, v in ipairs(coltbl) do
if v.footer then
if colfooter[j] then
cols = cols .. '<td colspan=' .. (v.footercolspan or '1') .. ' style="' .. (v.footerstyle or '') .. '">' .. v.footer .. '</td>'
cols = cols .. '<td colspan=' .. (colfootercolspan[j] or '1') .. ' style="' .. (colfooterstyle[j] or '') .. '">' .. colfooter[j] .. '</td>'
end
end
end
cols = cols .. '</tr>'
end
end
cols = cols .. '</tr>'
cols = cols .. '</table><div>'
table.insert(list, 1, cols)
table.insert(liststyle, 1, nil)
table.insert(group, 1, nil)
table.insert(groupstyle, 1, nil)
rowspan = rowspan + 1
end
end
cols = cols .. '</table><div>'
table.insert(list, 1, cols)
table.insert(liststyle, 1, nil)
table.insert(group, 1, nil)
table.insert(groupstyle, 1, nil)
rowspan = rowspan + 1
body1()
body1()
365行目: 360行目:
function p.with_collapsible_groups(frame)
function p.with_collapsible_groups(frame)
defArgs(frame)
defArgs(frame)
table.sort(content)
top()
top()
if args.title then title() end
if args.title then title() end
371行目: 367行目:
local i = 1
local i = 1
local function funcList()
local function funcList()
collapsible = (args.selected and (args.selected == abbr[i] or args.selected == group[i]) or state[i] == 'plain' or state[i] == 'off') and '' or 'collapsible '
list[i] = list[i] or content[i]
local j = list[i].index
collapsible = (args.selected and (args.selected == abbr[j] or args.selected == group[j]) or state[j] == 'plain' or state[j] == 'off') and '' or 'collapsible '
args.state = state[i] or 'collapsed'
args.state = state[j] or 'collapsed'
args.name = nil
args.name = nil
args.titlestyle = basestyle .. (args.groupstyle or '') .. ';' .. (args.secttitlestyle or '') .. ';' .. (groupstyle[i] or '')
args.titlestyle = basestyle .. (args.groupstyle or '') .. ';' .. (args.secttitlestyle or '') .. ';' .. (groupstyle[j] or '')
args.liststyle = (args.liststyle or '') .. ';' .. (args.contentstyle or '') .. ';' .. (liststyle[i] or '')
args.liststyle = (args.liststyle or '') .. ';' .. (args.contentstyle or '') .. ';' .. (liststyle[j] or '')
args.title, group[i] = group[i], nil
args.title, group[j] = group[j], nil
args.image = image[i]
args.image = image[j]
args.imageleft = imageleft[i]
args.imageleft = imageleft[j]
colspan = 2 + (args.imageleft and 1 or 0) + (args.image and 1 or 0)
colspan = 2 + (args.imageleft and 1 or 0) + (args.image and 1 or 0)
rowspan = 1
rowspan = 1
result = result .. '<td style="' .. (args.groupwidth and '' or 'width:100%;') .. 'padding:0;' .. (args.liststyle or '') .. ';' .. (odd == 'odd' and (args.oddstyle or '') or (args.evenstyle or '')) .. ';' .. (liststyle[i] or '') .. '" class="navbox-list navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd) .. ' ' .. (args.listclass or '') .. '"><div>'
result = result .. '<td style="' .. (args.groupwidth and '' or 'width:100%;') .. 'padding:0;' .. (args.liststyle or '') .. ';' .. (odd == 'odd' and (args.oddstyle or '') or (args.evenstyle or '')) .. ';' .. (liststyle[j] or '') .. '" class="navbox-list navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd) .. ' ' .. (args.listclass or '') .. '"><div>'
if args.title then
if args.title then
none = true
none = true
403行目: 401行目:
result = result .. '<td style="width:0%;padding:0 0 0 2px;' .. (args.imagestyle or '') .. '" rowspan=' .. rowspan .. '>' .. args.image .. '</td>'
result = result .. '<td style="width:0%;padding:0 0 0 2px;' .. (args.imagestyle or '') .. '" rowspan=' .. rowspan .. '>' .. args.image .. '</td>'
end
end
list[1] = nil
--i > 2
--i > 2
for j in pairs(list) do
for i = 2, #list do
result = result .. '<tr>'
result = result .. '<tr>'
list[1] = list[j]
list[1] = list[i]
i = j
funcList()
funcList()
list[1], list[j] = nil, nil
end
end

2016年10月17日 (月) 11:53時点における版

モジュールの解説[表示] [編集] [履歴] [キャッシュを破棄]

{{Navbox}}を実装するモジュールです。詳しい使い方は当該テンプレートの説明文を参照してください。

local p = {}

--[[
Template:Tnavbar
]]
function p.tnavbar(frame)
	local args = frame.args
	if not args[1] then return '&nbsp;' end
	
	local function tf(x)
		return x == '1' and true or false
	end
	args.plain = tf(args.plain)
	args.div = tf(args.div)
	args.nodiv = tf(args.nodiv)
	args.mini = tf(args.mini)
	args.viewplain = tf(args.viewplain)
	if args.miniv == '1' then args.mini, args.viewplain = true, true end
	args.fontstyle = args.fontcolor ~= '' and ((args.fontstyle or '') .. ';color:' .. args.fontcolor .. ';') or args.fontstyle or ''
	
	local r = {open = '<div class="noprint plainlinks navbar hlist" style="white-space:nowrap;font-size:60%;font-weight:normal;', content = '', close = '</div>'} --出力用
	if args.nodiv then
		r.open = r.open .. 'display:inline;padding:0 0.5em;'
	else
		r.open = r.open .. 'background-color:transparent;padding:0;color:#000;'
	end
	r.open = r.open .. args.fontstyle .. (args.style or '') .. '">'
	
	if not (args.plain or args.mini or args.viewplain) then
		r.content = '<span style="font-size:125%;">このテンプレートを:&nbsp;</span>'
	end
	
	local disp = args.mini and {'表', '話', '編', '歴'} or {'表示', 'ノート', '編集', '履歴'}
	local ns = {'Template:', 'Template‐ノート:', 'Template:', 'Template:'}
	local query = {nil, nil, 'action=edit', 'action=history'}
	local title = {'このテンプレートを表示します', 'このテンプレートのノートを表示します', 'このテンプレートを編集します。保存の前にプレビューを忘れずに。', 'このテンプレートの過去の版を表示します'}
	local color = {'', 'color:#002bb8;', 'color:#002bb8;', 'color:#002bb8;'}
	local i = 0
	local i_end = args.viewplain and 1 or 4
	r.content = r.content .. '<ul style="display:inline;">'
	for i = 1, i_end do
		local l = {open = '', link = '', close = ''}
		if query[i] then
			l.open = '['
			l.link = mw.uri.decode(tostring(mw.uri.canonicalUrl(ns[i] .. args[1], query[i]))) .. ' '
			l.close = ']'
		else
			l.open = '[['
			l.link = ns[i] .. args[1] .. '|'
			l.close = ']]'
		end
		r.content = r.content .. '<li>' .. l.open .. l.link .. '<span title="' .. title[i] .. '" style="font-size:125%;' .. color[i] .. args.fontstyle .. '">' .. disp[i] .. '</span>' .. l.close
	end
	r.content = r.content .. '</ul>'
	
	return r.open .. r.content .. r.close
end


--[[
Define Arguments
]]
local args = {}
local border
local child, none = false, false
local collapsible = ''
local colspan, rowspan = 0, 0
local basestyle = ''
local odd, even = 'odd', 'even'

local list, liststyle = {}, {}
local group, groupstyle = {}, {}
local colheader, colheadercolspan, colheaderstyle = {}, {}, {}
local col, colstyle, colwidth = {}, {}, {}
local colfooter, colfootercolspan, colfooterstyle = {}, {}, {}
local abbr, state = {}, {}
local sect, section = {}, {}
local secttitlestyle = {}
local content, contentstyle = {}
local image, imageleft = {}, {}

local result = ''	--出力用

local function defArgs(frame)
	args = require('Module:Arguments').getArgs(frame, {parentOnly = true})
	border = args.border or args[1]
	child, none = (border == 'subgroup' or border == 'child'), (border == 'none')
	collapsible = (args.state == 'plain' or args.state == 'off') and '' or 'collapsible '
	colspan = 2 + (args.imageleft and 1 or 0) + (args.image and 1 or 0)
	
	if args.basestyle then basestyle = args.basestyle .. ';' end
	
	local sortable_mt = {
		__lt = function(a, b) return a.index < b.index end,
		__concat = function(a, b)
			local strA = (type(a) == 'table') and a.content or a or ''
			local strB = (type(b) == 'table') and b.content or b or ''
			return strA .. strB
		end
	}
	local function sortable_args(tbl, index, content)
		table.insert(tbl, {index = index, content = content})
		setmetatable(tbl[#tbl], sortable_mt)
	end
	local switch = {
		--common
		list = function(num, v) sortable_args(list, num, '\n' .. v) end,
		liststyle = function(num, v) liststyle[num] = v end,
		group = function(num, v) group[num] = v end,
		groupstyle = function(num, v) groupstyle[num] = v end,
		--for with_columns
		colheader = function(num,v) colheader[num] = v end,
		colheadercolspan = function(num,v) colheadercolspan[num] = v end,
		colheaderstyle = function(num,v) colheaderstyle[num] = v end,
		col = function(num, v) sortable_args(col, num, '\n' .. v) end,
		colstyle = function(num,v) colstyle[num] = v end,
		colwidth = function(num,v) colwidth[num] = v end,
		colfooter = function(num,v) colfooter[num] = v end,
		colfootercolspan = function(num,v) colfootercolspan[num] = v end,
		colfooterstyle = function(num,v) colfooterstyle[num] = v end,
		--for with_collapsible_groups
		abbr = function(num, v) abbr[num] = v end,
		state = function(num, v) state[num] = v end,
		sect = function(num, v) group[num] = v end,
		section = function(num, v) group[num] = v end,
		secttitlestyle = function(num, v) groupstyle[num] = v end,
		content = function(num, v) sortable_args(content, num, '\n' .. v) end,
		contentstyle = function(num, v) liststyle[num] = v end,
		image = function(num, v) image[num] = v end,
		imageleft = function(num, v) imageleft[num] = v end,
	}
	
	for k, v in pairs(args) do
		local str1, num, str2 = string.match(k, '(%D+)(%d+)(%D*)')
		str1, num, str2 = str1 or '', tonumber(num), str2 or ''
		if switch[str1 .. str2] and num then switch[str1 .. str2](num, v) end
	end
	
	table.sort(list)
	rowspan = #list
end

--[[
top
]]
local function top()
	if child then
		result = result .. '</div>'
	elseif not none then
		result = result .. '<table class="navbox" style="border-collapse:collapse;' .. (args.bodystyle or '') .. ';' .. (args.style or '') .. '"><tr><td>'
	end
	
	result = result .. '<table class="nowraplinks ' .. (args.bodyclass or '')
	if args.title then
		result = result .. ' ' .. collapsible .. (args.state or ' autocollapse')
	end
	if child or none then
		result = result .. ' navbox-subgroup" style="margin:-2px;width:100%;width:calc(100% + 4px);' .. (args.bodystyle or '') .. (args.style or '')
	else
		result = result .. '" style="background:transparent;color:inherit;'
	end
	
	result = result .. ';min-width:100%;border-spacing:2px;border-collapse:separate;' .. (args.innerstyle or '') .. '">'
end

--[[
title and navbar
]]
local function title()
	if args.titlegroup then
		result = result .. '<tr><td class="navbox-group ' .. (args.titlegroupclass or '') .. '" style="' .. basestyle  .. (args.groupstyle or '') .. ';' .. (args.titlegroupstyle or '') .. '">' .. args.titlegroup .. '</td><th style="width:100%;'
	else
		result = result .. '<tr><th style="'
	end
	result = result .. basestyle .. (args.titlestyle or '') .. '" colspan=' .. (colspan - (args.titlegroup and 1 or 0)) .. ' class="navbox-title">'
	
	if (args.navbar == 'plain') or (not args.name and (child or none)) then
		result = result .. '<div style="float:left;width:6em;">&nbsp;</div>'
	elseif args.navbar ~= 'off' then
		local tbl = {args = {args.name, mini = '1', fontstyle = basestyle .. (args.titlestyle or '') .. ';border:none;', fontcolor = ''}}
		result = result .. '<div style="float:left;width:6em;text-align:left;">' .. p.tnavbar(tbl) .. '</div>'
	end
	
	if args.titleclass then
		args.titleclass = ' class="' .. args.titleclass .. '"'
	else
		args.titleclass = ''
	end
	result = result .. '<span ' .. args.titleclass .. ' style="font-size:' .. ((child or none) and '100' or '110') .. '%;">' .. args.title .. '</span>'
	
	if args.state == 'plain' then
		result = result .. '<div style="float:right;width:6em;">&nbsp;</div>'
	end
	result = result .. '</th></tr>'
end
	
--[[
above
]]
local function above()
	result = result .. '<tr><td class="navbox-abovebelow ' .. (args.aboveclass or '') .. '" style="' .. basestyle .. (args.abovestyle or '') .. '" colspan=' .. colspan .. '>\n' .. args.above .. '</td></tr>'
end
	
--[[
body
]]
--first group/list and images
local function body1()
	result = result .. '<tr>'
	if args.imageleft then
		result = result .. '<td style="width:0;' .. (args.imageleftstyle or '') .. '" rowspan=' .. rowspan .. '>' .. args.imageleft .. '</td>'
	end
	local j = list[1].index
	if group[j] then
		result = result .. '<td class="navbox-group ' .. (args.groupclass or '') .. '" style="' .. basestyle .. (args.groupwidth and ('width:' .. args.groupwidth .. ';') or '') .. (args.groupstyle or '') .. ';' .. (groupstyle[j] or '') .. '">' .. group[j] .. '</td><td style="text-align:left;'
	else
		result = result .. '<td colspan=2 style="'
	end
	result = result .. (args.groupwidth and '' or 'width:100%;') .. 'padding:0;' .. (args.liststyle or '') .. ';' .. (odd == 'odd' and (args.oddstyle or '') or (args.evenstyle or '')) .. ';' .. (liststyle[j] or '') .. '" class="navbox-list navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd) .. ' ' .. (args.listclass or '') .. '"><div style="padding:' .. (args.list1padding or args.listpadding or '0 0.25em') .. '">' .. list[1] .. '</div></td>'
	if args.image then
		result = result .. '<td style="width:0;' .. (args.imagestyle or '') .. '" rowspan=' .. rowspan .. '>' .. args.image .. '</td>'
	end
	result = result .. '</tr>'
end

--remaining groups/lists
local function body2()
	for i = 2, #list do
		odd, even = even, odd
		local j = list[i].index
		if group[j] then
			result = result .. '<tr><td class="navbox-group ' .. (args.groupclass or '') .. '" style="' .. basestyle .. (args.groupwidth and ('width:' .. args.groupwidth .. ';') or '') .. (args.groupstyle or '') .. ';' .. (groupstyle[j] or '') .. '">' .. group[j] .. '</td><td style="text-align:left;'
		else
			result = result .. '<tr><td colspan=2 style="'
		end
		result = result .. (args.groupwidth and '' or 'width:100%;') .. 'padding:0;' .. (args.liststyle or '') .. ';' .. (odd == 'odd' and (args.oddstyle or '') or (args.evenstyle or '')) .. ';' .. (liststyle[j] or '') .. '" class="navbox-list navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd) .. ' ' .. (args.listclass or '') .. '"><div style="padding:' .. (args.listpadding or '0 0.25em') .. '">' .. list[i] .. '</div></td></tr>'
	end
end

--[[
below
]]
local function below()
	result = result .. '<tr><td class="navbox-abovebelow ' .. (args.belowclass or '') .. '" style="' .. basestyle .. (args.belowstyle or '') .. '" colspan=' .. colspan .. '>\n' .. args.below .. '</td></tr>'
end
	
--[[
close
]]
local function close()
	result = result .. '</table>'
	
	if child then
		result = result .. '<div>'
	elseif not none then
		result = result .. '</table>'
	end
end

--[[
Template:Navbox
]]
function p.navbox(frame)
	defArgs(frame)
	top()
	if args.title then title() end
	if args.above then above() end
	if list[1] then body1() end
	body2()
	if args.below then below() end
	close()
	return result
end

--[[
Template:Navbox subgroup
]]
function p.subgroup(frame)
	defArgs(frame)
	if not border then child = true end
	args.groupstyle = 'padding:' .. (args.grouppadding or '0 0.75em') .. ';' .. (args.groupstyle or '')
	top()
	if args.title then title() end
	if args.above then above() end
	if list[1] then body1() end
	body2()
	if args.below then below() end
	close()
	return result
end

--[[
Template:Navbox with columns
]]
function p.with_columns(frame)
	defArgs(frame)
	table.sort(col)
	mw.log(#col)
	top()
	if args.title then title() end
	if args.above then above() end
	
	if col[1] then
		local j = col[1].index
		local cols = '</div><table class="navbox-columns-table" style="border-spacing:2px;border-collapse:separate;text-align:left;margin:-2px;' .. ((colheader[j] or args.fullwidth) and 'width:100%;width:calc(100% + 4px);' or 'margin:0 auto;') .. (args.coltablestyle or '') .. '">'
		--Header row
		if colheader[j] then
			cols = cols .. '<tr class="navbox-abovebelow" style="font-weight:bold;' .. (args.colheaderstyle or '') .. '">'
			for i = 1, #col do
				local j = col[i].index
				if colheader[j] then
					cols = cols .. '<td colspan=' .. (colheadercolspan[j] or '1') .. ' style="' .. (colheaderstyle[j] or '') .. '">' .. colheader[j] .. '</td>'
				end
			end
			cols = cols .. '</tr>'
		end
		--Main columns
		cols = cols .. '<tr style="vertical-align:top;' .. (args.colstyle or '') .. '">'
		if not (colheader[j] or colfooter[j] or args.fullwidth) then
			local paddingoff = args.padding and string.find(args.padding, '^0[ep]?[mx]?%?;?')
			if not paddingoff then
				cols = cols .. '<td style="width:' .. (args.padding or '5em;') .. '">&nbsp;&nbsp;&nbsp;</td>'
			end
		end
		for i = 1, #col do
			local j = col[i].index
			cols = cols .. '<td style="padding:0;' .. (args.oddcolstyle or '') .. ';' .. (colstyle[j] or '') .. ';width:' .. (colwidth[j] or args.colwidth or '10em;') .. '">' .. col[i] .. '</td>'
			args.oddcolstyle, args.evencolstyle = args.evencolstyle, args.oddcolstyle
		end
		cols = cols .. '</tr>'
		--Footer row
		if colfooter[j] then
			cols = cols .. '<tr class="navbox-abovebelow" style="font-weight:bold;' .. (args.colfooterstyle or '') .. '">'
			for i = 1, #col do
				local j = col[i].index
				if colfooter[j] then
					cols = cols .. '<td colspan=' .. (colfootercolspan[j] or '1') .. ' style="' .. (colfooterstyle[j] or '') .. '">' .. colfooter[j] .. '</td>'
				end
			end
			cols = cols .. '</tr>'
		end
		cols = cols .. '</table><div>'
		table.insert(list, 1, cols)
		table.insert(liststyle, 1, nil)
		table.insert(group, 1, nil)
		table.insert(groupstyle, 1, nil)
		rowspan = rowspan + 1
	end
	
	body1()
	body2()
	if args.below then below() end
	close()
	return result
end

--[[
Template:Navbox with collapsible groups
]]
function p.with_collapsible_groups(frame)
	defArgs(frame)
	table.sort(content)
	top()
	if args.title then title() end
	if args.above then above() end
	
	local i = 1
	local function funcList()
		list[i] = list[i] or content[i]
		local j = list[i].index
		collapsible = (args.selected and (args.selected == abbr[j] or args.selected == group[j]) or state[j] == 'plain' or state[j] == 'off') and '' or 'collapsible '
		args.state = state[j] or 'collapsed'
		args.name = nil
		args.titlestyle = basestyle .. (args.groupstyle or '') .. ';' .. (args.secttitlestyle or '') .. ';' .. (groupstyle[j] or '')
		args.liststyle = (args.liststyle or '') .. ';' .. (args.contentstyle or '') .. ';' .. (liststyle[j] or '')
		args.title, group[j] = group[j], nil
		args.image = image[j]
		args.imageleft = imageleft[j]
		colspan = 2 + (args.imageleft and 1 or 0) + (args.image and 1 or 0)
		rowspan = 1
		result = result .. '<td style="' .. (args.groupwidth and '' or 'width:100%;') .. 'padding:0;' .. (args.liststyle or '') .. ';' .. (odd == 'odd' and (args.oddstyle or '') or (args.evenstyle or '')) .. ';' .. (liststyle[j] or '') .. '" class="navbox-list navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd) .. ' ' .. (args.listclass or '') .. '"><div>'
		if args.title then
			none = true
			top()
			title()
			body1()
			close()
		else
			result = result .. (list[i] or '')
		end
		result = result .. '</div></td></tr>'
	end
	
	--i = 1
	result = result .. '<tr>'
	if args.imageleft then
		result = result .. '<td style="width:0;padding:0 2px 0 0;' .. (args.imageleftstyle or '') .. '" rowspan=' .. rowspan .. '>' .. args.imageleft .. '</td>'
	end
	funcList()
	if args.image then
		result = result .. '<td style="width:0%;padding:0 0 0 2px;' .. (args.imagestyle or '') .. '" rowspan=' .. rowspan .. '>' .. args.image .. '</td>'
	end
	--i > 2
	for i = 2, #list do
		result = result .. '<tr>'
		list[1] = list[i]
		funcList()
	end
	
	if args.below then below() end
	child, none = (border == 'subgroup' or border == 'child'), (border == 'none') --再定義
	close()
	return result
end

--[[
Template:NavboxYears
Template:NavboxYears2
]]
local function calc_years(args, fmtLink)
	local numtab = tonumber(args.tab) or 0
	local numstart = tonumber(args.start)
	local numend = tonumber(args['end'])
	local numstep = tonumber(args.step) or 1
	if numstart and numend then
		if numtab > 0 then
			for i = 2, numtab + 1 do
				args[i] = nil
			end
		end
		local numD = numend - numstart + 1
		for i = 1, numD, numstep do
			args[i + numtab + 1] = numstart + i - 1
		end
	end
	local result = '<table style="width:100%;border-spacing:2px;border-collapse:separate;text-align:center;">' 
	local h = 1
	repeat
		h = h + 1
		result = result .. '<tr>'
		for i = 2, 11 do
			result = result .. '<td style="width:10%;">'
			if (tonumber(args[i]) or -1) > 0 then
				result = result .. ('[[' .. fmtLink(args[1], args[i]) .. '|' .. args[i] .. ']]')
			else
				result = result .. (args[i] or '')
			end
			result = result .. '</td>'
			args[i], args[i + 10] = args[i + 10], args[i + h * 10]
		end
		result = result .. '</tr>'
	until not args[2]
	result = result .. '</table>'
	return result
end

local function years(frame, fmtLink)
	defArgs(frame)
	if args.var then fmtLink = function(str, num) return str:gsub(args.var, num) end end
	if args.name then
		args.style = 'width:' .. (args.width or '38em') .. ';' .. (args.style or '')
		top()
		if args.title then title() end
		if args.above then above() end
		if not list[1] and args[1] then list[1] = calc_years(args, fmtLink) end
		if list[1] then body1() end
		body2()
		if args.below then below() end
		close()
		return result
	else
		return calc_years(args, fmtLink)
	end
end

function p.years(frame)
	local fmtLink = function(str, num) return str .. num end
	return years(frame, fmtLink)
end

function p.years2(frame)
	local fmtLink = function(str, num) return num .. str end
	return years(frame, fmtLink)
end

return p