メニューを切り替える
Toggle preferences menu
個人設定を切り替える
ログインしていません
編集を行うと、IPアドレスが公開されます。

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

提供:MONACA Wiki
ページの作成:「-- -- This module implements {{Navbox}} -- local p = {} local navbar = require('Module:Navbar')._navbar local getArgs -- lazily initialized local args local border local listnums local ODD_EVEN_MARKER = '\127_ODDEVEN_\127' local RESTART_MARKER = '\127_ODDEVEN0_\127' local REGEX_MARKER = '\127_ODDEVEN(%d?)_\127' local function striped(wikitext) -- Return wikitext with markers replaced for odd/even striping. -- Child (subgroup) navboxes are flagged with a catego…」
 
編集の要約なし
 
1行目: 1行目:
--
local p = {}
-- This module implements {{Navbox}}
--


local p = {}
--[[
Template:Tnavbar
]]
function p.tnavbar(frame)
local r = mw.html.create() --出力用
local args = frame.args
if not args[1] then return ' ' 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)
args.fontstyle = args.fontcolor ~= '' and ((args.fontstyle or '') .. ';color:' .. args.fontcolor .. ';') or args.fontstyle or ''
local divTag = r:tag('div')
:addClass('noprint')
:addClass('plainlinks')
:addClass('navbar')
:addClass('hlist')
:css('white-space', 'nowrap')
:css('font-size', '60%')
:css('font-weight', 'normal')
if args.nodiv then
divTag:css('display', 'inline')
:css('padding', '0 0.5em')
else
divTag:css('background-color', 'transparent')
:css('padding', '0')
:css('color', '#000')
end
divTag:cssText(args.fontstyle)
:cssText(args.style)
if not (args.plain or args.mini or args.viewplain) then
divTag:tag('span')
:css('font-size', '125%')
:node('このテンプレートを: ')
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
local ulTag = divTag:tag('ul')
:css('display', 'inline')
for i = 1, i_end do
local liTag = ulTag:tag('li')
local l = {open = '', link = '', close = ''}
if query[i] then
l.open = '['
l.link = tostring(mw.uri.canonicalUrl(ns[i] .. args[1], query[i])) .. ' '
l.close = ']'
else
l.open = '[['
l.link = ns[i] .. args[1] .. '|'
l.close = ']]'
end
liTag:wikitext(l.open .. l.link)
:tag('span')
:attr('title', title[i])
:css('font-size', '125%')
:cssText(color[i])
:cssText(args.fontstyle)
:node(disp[i])
:done()
:wikitext(l.close)
end
return tostring(r)
end


local navbar = require('Module:Navbar')._navbar
local getArgs -- lazily initialized


local args
--[[
Define Arguments
]]
local getArgs
local args = {}
local border
local border
local listnums
local child, none = false, false
local ODD_EVEN_MARKER = '\127_ODDEVEN_\127'
local rowspan = 0
local RESTART_MARKER = '\127_ODDEVEN0_\127'
local basestyle = ''
local REGEX_MARKER = '\127_ODDEVEN(%d?)_\127'
local odd, even = 'odd', 'even'


local function striped(wikitext)
local list, liststyle = {}, {}
-- Return wikitext with markers replaced for odd/even striping.
local group, groupstyle = {}, {}
-- Child (subgroup) navboxes are flagged with a category that is removed
local colheader, colheadercolspan, colheaderstyle = {}, {}, {}
-- by parent navboxes. The result is that the category shows all pages
local col, colstyle, colwidth = {}, {}, {}
-- where a child navbox is not contained in a parent navbox.
local colfooter, colfootercolspan, colfooterstyle = {}, {}, {}
local orphanCat = '[[Category:孤立したナビゲーションテンプレート]]'
local abbr, state = {}, {}
if border == 'subgroup' and args.orphan ~= 'yes' then
local sect, section = {}, {}
-- No change; striping occurs in outermost navbox.
local secttitlestyle = {}
return wikitext .. orphanCat
local content, contentstyle = {}
local image, imageleft = {}, {}
 
local function defArgs(frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
end
local first, second = 'odd', 'even'
args = getArgs(frame, {parentOnly = true})
if args.evenodd then
border = args.border or args[1]
if args.evenodd == 'swap' then
child, none = (border == 'subgroup' or border == 'child'), (border == 'none')
first, second = second, first
collapsible = (args.state == 'plain' or args.state == 'off') and '' or 'mw-collapsible '
else
first = args.evenodd
if args.basestyle then basestyle = args.basestyle .. ';' end
second = first
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
end
}
local function sortable_args(tbl, index, content)
table.insert(tbl, {index = index, content = content})
setmetatable(tbl[#tbl], sortable_mt)
end
end
local changer
local switch = {
if first == second then
--common
changer = first
list = function(num, v) sortable_args(list, num, '\n' .. v) end,
else
liststyle = function(num, v) liststyle[num] = v end,
local index = 0
group = function(num, v) group[num] = v end,
changer = function (code)
groupstyle = function(num, v) groupstyle[num] = v end,
if code == '0' then
--for with_columns
-- Current occurrence is for a group before a nested table.
colheader = function(num,v) colheader[num] = v end,
-- Set it to first as a valid although pointless class.
colheadercolspan = function(num,v) colheadercolspan[num] = v end,
-- The next occurrence will be the first row after a title
colheaderstyle = function(num,v) colheaderstyle[num] = v end,
-- in a subgroup and will also be first.
col = function(num, v) sortable_args(col, num, '\n' .. v) end,
index = 0
colstyle = function(num,v) colstyle[num] = v end,
return first
colwidth = function(num,v) colwidth[num] = v end,
end
colfooter = function(num,v) colfooter[num] = v end,
index = index + 1
colfootercolspan = function(num,v) colfootercolspan[num] = v end,
return index % 2 == 1 and first or second
colfooterstyle = function(num,v) colfooterstyle[num] = v end,
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
end
local regex = orphanCat:gsub('([%[%]])', '%%%1')
return (wikitext:gsub(regex, ''):gsub(REGEX_MARKER, changer))  -- () omits gsub count
table.sort(list)
rowspan = #list
end
end


local function processItem(item, nowrapitems)
--[[
if item:sub(1, 2) == '{|' then
top
-- Applying nowrap to lines in a table does not make sense.
]]
-- Add newlines to compensate for trim of x in |parm=x in a template.
local function top(baseTag)
return '\n' .. item ..'\n'
local nav
local bodyTable
if baseTag == nil or baseTag == '' then
baseTag = mw.html.create()
end
end
if nowrapitems == 'yes' then
if child then
local lines = {}
baseTag:wikitext('</div>')
for line in (item .. '\n'):gmatch('([^\n]*)\n') do
nav = baseTag
local prefix, content = line:match('^([*:;#]+)%s*(.*)')
elseif not none then
if prefix and not content:match('^<span class="nowrap">') then
nav = baseTag:tag('div')
line = prefix .. '<span class="nowrap">' .. content .. '</span>'
:addClass('navbox')
end
:addClass(args.navboxclass)
table.insert(lines, line)
:css('border-collapse', 'collapse')
:cssText(args.bodystyle)
:cssText(args.style)
:css('padding', '3px')
if args.title or args.above then
nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title or args.above))
else
nav:attr('aria-label', 'Navbox')
end
end
item = table.concat(lines, '\n')
else
nav = baseTag
end
end
if item:match('^[*:;#]') then
return '\n' .. item ..'\n'
bodyTable = nav:tag('table')
:addClass('nowraplinks')
:addClass(args.bodyclass)
 
if args.title and (args.state ~= 'plain' and args.state ~= 'off') then
if args.state == 'collapsed' then args.state = 'mw-collapsed' end
bodyTable
:addClass('mw-collapsible')
:addClass(args.state or 'autocollapse')
end
end
return item
end


local function renderNavBar(titleCell)
if child or border == 'none' then
 
bodyTable
if args.navbar ~= 'off' and args.navbar ~= 'plain' and not (not args.name and mw.getCurrentFrame():getParent():getTitle():gsub('/sandbox$', '') == 'Template:Navbox') then
:addClass('navbox-subgroup')
titleCell:wikitext(navbar{
:cssText(args.bodystyle)
args.name,
:cssText(args.style)
mini = 1,
else  -- regular navbox - bodystyle and style will be applied to the wrapper table
fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') .. ';background:none transparent;border:none;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none; padding:0;'
bodyTable
})
:addClass('navbox-inner')
:css('background', 'transparent')
:css('color', 'inherit')
end
end
 
bodyTable:css('min-width', '100%')
:css('border-spacing', '0px')
:css('border-collapse', 'separate')
:cssText(args.innerstyle)
return baseTag, bodyTable
end
end


--
--[[
--  Title row
title and navbar
--
]]
local function renderTitleRow(tbl)
local function title(tbl)
if not args.title then return end
if not args.title then return tbl end
 
local titleRow = tbl:tag('tr')
local titleRow = tbl:tag('tr')
 
if args.titlegroup then
if args.titlegroup then
titleRow
titleRow
115行目: 246行目:
if args.titlegroup then
if args.titlegroup then
titleCell
titleCell
:css('border-left', '2px solid #fdfdfd')
:css('width', '100%')
:css('width', '100%')
end
end
 
local titleColspan = 2
local titleColspan = 2
if args.imageleft then titleColspan = titleColspan + 1 end
if args.imageleft then titleColspan = titleColspan + 1 end
129行目: 259行目:
:addClass('navbox-title')
:addClass('navbox-title')
:attr('colspan', titleColspan)
:attr('colspan', titleColspan)
if (args.navbar == 'plain') or (not args.name and (child or none)) then
titleCell
:tag('div')
:css('float', 'left')
:css('width', '6em')
:node('&nbsp;')
elseif args.navbar ~= 'off' then
local tbl = {args = {args.name, mini = '1', fontstyle = basestyle .. (args.titlestyle or '') .. ';border:none;', fontcolor = ''}}
titleCell
:tag('div')
:css('float', 'left')
:css('width', '6em')
:css('text-align', 'left')
:node(p.tnavbar(tbl))
end
if child or border == 'none' then
titleCell
:tag('div')
:attr('id', mw.uri.anchorEncode(args.title))
:addClass(args.titleclass)
:css('font-size', '100%')
:css('margin', '0 6em')
:node(args.title)
else
titleCell
:tag('div')
:attr('id', mw.uri.anchorEncode(args.title))
:addClass(args.titleclass)
:css('font-size', '110%')
:css('margin', '0 6em')
:node(args.title)
end


renderNavBar(titleCell)
return tbl
 
titleCell
:tag('div')
-- id for aria-labelledby attribute
:attr('id', mw.uri.anchorEncode(args.title))
:addClass(args.titleclass)
:css('font-size', '110%')
:css('margin', '0 4em')
:wikitext(processItem(args.title))
end
end
--
--  Above/Below rows
--


local function getAboveBelowColspan()
local function getAboveBelowColspan()
153行目: 304行目:
end
end


local function renderAboveRow(tbl)
--[[
if not args.above then return end
above
]]
local function above(tbl)
if not args.above then return tbl end


tbl:tag('tr')
tbl:tag('tr')
163行目: 317行目:
:cssText(args.abovestyle)
:cssText(args.abovestyle)
:attr('colspan', getAboveBelowColspan())
:attr('colspan', getAboveBelowColspan())
:tag('div')
:newline()
-- id for aria-labelledby attribute, if no title
:node(args.above)
:attr('id', args.title and nil or mw.uri.anchorEncode(args.above))
return tbl
:wikitext(processItem(args.above, args.nowrapitems))
end
 
local function renderBelowRow(tbl)
if not args.below then return end
 
tbl:tag('tr')
:tag('td')
:addClass('navbox-abovebelow')
:addClass(args.belowclass)
:cssText(args.basestyle)
:cssText(args.belowstyle)
:attr('colspan', getAboveBelowColspan())
:tag('div')
:wikitext(processItem(args.below, args.nowrapitems))
end
end
 
--
--[[
--  List rows
body
--
]]
local function renderListRow(tbl, index, listnum)
--first group/list and images
local function body1(tbl)
local row = tbl:tag('tr')
local row = tbl:tag('tr')
 
if args.imageleft then
if index == 1 and args.imageleft then
row
row
:tag('td')
:tag('td')
:addClass('navbox-image')
:addClass('navbox-image')
:addClass(args.imageclass)
:addClass(args.imageclass)
:css('width', '1px')               -- Minimize width
:css('width', '1px')
:css('padding', '0px 2px 0px 0px')
:css('padding', '0px 2px 0px 0px')
:cssText(args.imageleftstyle)
:cssText(args.imageleftstyle)
:attr('rowspan', #listnums)
:attr('rowspan', rowspan)
:tag('div')
:tag('div')
:wikitext(processItem(args.imageleft))
:node(args.imageleft)
end
end
 
local j = list[1].index
if args['group' .. listnum] then
if group[j] then
local groupCell = row:tag('th')
local groupCell = row:tag('th')
-- id for aria-labelledby attribute, if lone group with no title or above
if listnum == 1 and not (args.title or args.above or args.group2) then
groupCell
:attr('id', mw.uri.anchorEncode(args.group1))
end


groupCell
groupCell
216行目: 349行目:
:addClass(args.groupclass)
:addClass(args.groupclass)
:cssText(args.basestyle)
:cssText(args.basestyle)
            :css('width', args.groupwidth or '1%') -- If groupwidth not specified, minimize width
:css('width', args.groupwidth or '1%')


groupCell
groupCell
:cssText(args.groupstyle)
:cssText(args.groupstyle)
:cssText(args['group' .. listnum .. 'style'])
:cssText(groupstyle[j])
:wikitext(args['group' .. listnum])
:wikitext(group[j])
end
end


local listCell = row:tag('td')
local listCell = row:tag('td')


if args['group' .. listnum] then
if group[j] then
listCell
listCell
:css('text-align', 'left')
:css('text-align', 'left')
239行目: 372行目:
end
end


local rowstyle -- usually nil so cssText(rowstyle) usually adds nothing
local rowstyle
if index % 2 == 1 then
if odd == 'odd' then
rowstyle = args.oddstyle
rowstyle = args.oddstyle
else
else
246行目: 379行目:
end
end


local listText = args['list' .. listnum]
local oddEven = ODD_EVEN_MARKER
if listText:sub(1, 12) == '</div><table' then
-- Assume list text is for a subgroup navbox so no automatic striping for this row.
oddEven = listText:find('<th[^>]*"navbox%-title"') and RESTART_MARKER or 'odd'
end
listCell
listCell
:css('padding', '0px')
:css('padding', '0px')
:cssText(args.liststyle)
:cssText(args.liststyle)
:cssText(rowstyle)
:cssText(rowstyle)
:cssText(args['list' .. listnum .. 'style'])
:cssText(liststyle[j])
:addClass('navbox-list')
:addClass('navbox-list')
:addClass('navbox-' .. oddEven)
:addClass('navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd))
:addClass(args.listclass)
:addClass(args.listclass)
:addClass(args['list' .. listnum .. 'class'])
:tag('div')
:tag('div')
:css('padding', (index == 1 and args.list1padding) or args.listpadding or '0em 0.25em')
:css('padding', (args.list1padding or args.listpadding or '0em 0.25em'))
:wikitext(processItem(listText, args.nowrapitems))
:node(list[1].content)
 
:newline()
if index == 1 and args.image then
if args.image then
row
row
:tag('td')
:tag('td')
:addClass('navbox-image')
:addClass('navbox-image')
:addClass(args.imageclass)
:addClass(args.imageclass)
:css('width', '1px')               -- Minimize width
:css('width', '1px')
:css('padding', '0px 0px 0px 2px')
:css('padding', '0px 0px 0px 2px')
:cssText(args.imagestyle)
:cssText(args.imagestyle)
:attr('rowspan', #listnums)
:attr('rowspan', rowspan)
:tag('div')
:tag('div')
:wikitext(processItem(args.image))
:node(args.image)
end
end
return tbl
end
end


--remaining groups/lists
local function body2(tbl)
for i = 2, #list do
odd, even = even, odd
local j = list[i].index
local row = tbl:tag('tr')
if group[j] then
local groupCell = row:tag('th')
groupCell
:attr('scope', 'row')
:addClass('navbox-group')
:addClass(args.groupclass)
:cssText(args.basestyle)
:css('width', args.groupwidth or '1%')


--
groupCell
--  Tracking categories
:cssText(args.groupstyle)
--
:cssText(groupstyle[j])
:node(group[j])
end


local function needsHorizontalLists()
local listCell = row:tag('td')
if border == 'subgroup' or args.tracking == 'no' then
return false
end
local listClasses = {
['plainlist'] = true, ['hlist'] = true, ['hlist hnum'] = true,
['hlist hwrap'] = true, ['hlist vcard'] = true, ['vcard hlist'] = true,
['hlist vevent'] = true,
}
return not (listClasses[args.listclass] or listClasses[args.bodyclass])
end


local function hasBackgroundColors()
if group[j] then
for _, key in ipairs({'titlestyle', 'groupstyle', 'basestyle', 'abovestyle', 'belowstyle'}) do
listCell
if tostring(args[key]):find('background', 1, true) then
:css('text-align', 'left')
return true
:css('border-left-width', '2px')
:css('border-left-style', 'solid')
else
listCell:attr('colspan', 2)
end
end
end
end


local function hasBorders()
if not args.groupwidth then
for _, key in ipairs({'groupstyle', 'basestyle', 'abovestyle', 'belowstyle'}) do
listCell:css('width', '100%')
if tostring(args[key]):find('border', 1, true) then
return true
end
end
end
end


local function isIllegible()
local rowstyle
local styleratio = require('Module:Color contrast')._styleratio
if odd == 'odd' then
 
rowstyle = args.oddstyle
for key, style in pairs(args) do
else
if tostring(key):match("style$") then
rowstyle = args.evenstyle
if styleratio{mw.text.unstripNoWiki(style)} < 4.5 then
return true
end
end
end
listCell
:css('padding', '0px')
:cssText(args.liststyle)
:cssText(rowstyle)
:cssText(liststyle[j])
:addClass('navbox-list')
:addClass('navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd))
:addClass(args.listclass)
:tag('div')
:css('padding', (args.listpadding or '0em 0.25em'))
:node(list[i].content)
:newline()
end
end
return false
return tbl
end
end


local function getTrackingCategories()
--[[
local cats = {}
below
    if needsHorizontalLists() then table.insert(cats, 'Hlistを指定していないナビゲーションテンプレート') end
]]
    if hasBackgroundColors() then table.insert(cats, '背景色を指定しているナビゲーションテンプレート') end
local function below(tbl)
    if isIllegible() then table.insert(cats, '読みにくい可能性があるナビゲーションテンプレート') end
if not args.below then return tbl end
if hasBorders() then table.insert(cats, 'ボーダーを指定しているナビゲーションテンプレート') end
 
return cats
tbl:tag('tr')
:tag('td')
:addClass('navbox-abovebelow')
:addClass(args.belowclass)
:cssText(args.basestyle)
:cssText(args.belowstyle)
:attr('colspan', getAboveBelowColspan())
:newline()
:node(args.below)
return tbl
end
end


local function renderTrackingCategories(builder)
--[[
local title = mw.title.getCurrentTitle()
Template:Navbox
if title.namespace ~= 10 then return end -- not in template space
]]
local subpage = title.subpageText
function p.navbox(frame)
if subpage == 'doc' or subpage == 'sandbox' or subpage == 'testcases' then return end
defArgs(frame)
 
local res
for _, cat in ipairs(getTrackingCategories()) do
local firstTableTag
builder:wikitext('[[Category:' .. cat .. ']]')
res, firstTableTag = top()
firstTableTag = title(firstTableTag)
firstTableTag = above(firstTableTag)
if list[1] then
firstTableTag = body1(firstTableTag)
end
firstTableTag = body2(firstTableTag)
firstTableTag = below(firstTableTag)
if child then
res:wikitext('<div>')
end
end
return tostring(res)
end
end


--
--[[
--  Main navbox tables
Template:Navbox subgroup
--
]]
local function renderMainTable()
function p.subgroup(frame)
local tbl = mw.html.create('table')
defArgs(frame)
:addClass('nowraplinks')
if not border then child = true end
:addClass(args.bodyclass)
args.groupstyle = 'padding:' .. (args.grouppadding or '0 0.75em') .. ';' .. (args.groupstyle or '')
 
if args.title and (args.state ~= 'plain' and args.state ~= 'off') then
local res
if args.state == 'collapsed' then args.state = 'mw-collapsed' end
local firstTableTag
tbl
res, firstTableTag = top()
:addClass('mw-collapsible')
firstTableTag = title(firstTableTag)
:addClass(args.state or 'autocollapse')
firstTableTag = above(firstTableTag)
if list[1] then
firstTableTag = body1(firstTableTag)
end
end
firstTableTag = body2(firstTableTag)
firstTableTag = below(firstTableTag)
if not border then res:wikitext('<div>') end
return tostring(res)
end


tbl:css('border-spacing', 0)
--[[
if border == 'subgroup' or border == 'none' then
Template:Navbox with columns
tbl
]]
:addClass('navbox-subgroup')
function p.with_columns(frame)
:cssText(args.bodystyle)
defArgs(frame)
:cssText(args.style)
table.sort(col)
else  -- regular navbox - bodystyle and style will be applied to the wrapper table
local res
tbl
local firstTableTag
:addClass('navbox-inner')
res, firstTableTag = top()
:css('background', 'transparent')
:css('color', 'inherit')
firstTableTag = title(firstTableTag)
end
firstTableTag = above(firstTableTag)
tbl:cssText(args.innerstyle)
 
if col[1] then
renderTitleRow(tbl)
local j = col[1].index
renderAboveRow(tbl)
local cols = mw.html.create('table')
for i, listnum in ipairs(listnums) do
:addClass('navbox-columns-table')
renderListRow(tbl, i, listnum)
:css('border-spacing', '0px')
:css('border-collapse', 'separate')
:css('text-align', 'left')
:cssText((colheader[j] or args.fullwidth) and 'width:100%;' or 'margin:0 auto;')
:cssText(args.coltablestyle)
--Header row
if colheader[j] then
local headerRow = cols:tag('tr')
:addClass('navbox-abovebelow')
:css('font-weight', 'bold')
:cssText(args.colheaderstyle)
for i = 1, #col do
local j = col[i].index
if colheader[j] then
headerRow:tag('td')
:attr('colspan', colheadercolspan[j] or '1')
:cssText(colheaderstyle[j])
:node(colheader[j])
end
end
end
--Main columns
local row = cols:tag('tr')
:css('vertical-align', 'top')
:cssText(args.colstyle)
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
row:tag('td')
:css('width', args.padding or '5em')
:wikitext('&nbsp;&nbsp;&nbsp;')
end
end
for i = 1, #col do
local j = col[i].index
row:tag('td')
:css('padding', '0')
:cssText(args.oddcolstyle)
:cssText(colstyle[j])
:css('width', colwidth[j] or args.colwidth or '10em')
:node(col[i].content)
args.oddcolstyle, args.evencolstyle = args.evencolstyle, args.oddcolstyle
end
--Footer row
if colfooter[j] then
row = cols:tag('tr')
:addClass('navbox-abovebelow')
:css('font-weight', 'bold')
:cssText(args.colfooterstyle)
for i = 1, #col do
local j = col[i].index
if colfooter[j] then
row:tag('td')
:attr('colspan', colfootercolspan[j] or '1')
:cssText(colfooterstyle[j])
:node(colfooter[j])
end
end
end
cols = mw.html.create():wikitext('</div>'):wikitext(tostring(cols)):wikitext('<div>')
table.insert(list, {index=1, content=cols})
rowspan = rowspan + 1
end
end
renderBelowRow(tbl)
 
firstTableTag = body1(firstTableTag)
return tbl
firstTableTag = body2(firstTableTag)
firstTableTag = below(firstTableTag)
return tostring(res)
end
end


function p._navbox(navboxArgs)
--[[
args = navboxArgs
Template:Navbox with collapsible groups
listnums = {}
]]
 
function p.with_collapsible_groups(frame)
for k, _ in pairs(args) do
local res
if type(k) == 'string' then
local firstTableTag
local listnum = k:match('^list(%d+)$')
defArgs(frame)
if listnum then table.insert(listnums, tonumber(listnum)) end
table.sort(content)
res, firstTableTag = top()
firstTableTag = title(firstTableTag)
firstTableTag = above(firstTableTag)
local i = 1
local function funcList(rowTag)
list[i] = list[i] or content[i]
local j = list[i].index
args.state = state[j] or args.selected and (args.selected == abbr[j] or args.selected == group[j]) and '' or 'mw-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]
rowspan = 1
local baseTag = rowTag:tag('td')
:cssText(args.groupwidth and '' or 'width:100%;')
:css('padding', '0px')
:cssText(args.liststyle)
:cssText(odd == 'odd' and (args.oddstyle or '') or (args.evenstyle or ''))
:cssText(liststyle[j])
:addClass('navbox-list')
:addClass('navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd))
:addClass(args.listclass)
:tag('div')
if args.title then
local tableTag
none = true
baseTag, tableTag = top(baseTag)
tableTag = title(tableTag)
tableTag = body1(tableTag)
      if child then
        baseTag:wikitext('<div>')
      end
else
baseTag:node(list[i].content)
end
end
end
end
table.sort(listnums)
 
--i = 1
border = mw.text.trim(args.border or args[1] or '')
local row = firstTableTag:tag('tr')
if border == 'child' then
if args.imageleft then
border = 'subgroup'
row:tag('td')
:addClass('navbox-image')
:addClass(args.imageclass)
:css('width', '0')
:css('padding', '0 2px 0 0')
:cssText(args.imageleftstyle)
:attr('rowspan', rowspan)
:node(args.imageleft)
end
funcList(row)
if args.image then
row:tag('td')
:css('width', '0%')
:css('padding', '0 0 0 2px')
:cssText(args.imagestyle)
:attr('rowspan', rowspan)
:node(args.image)
end
--i > 2
for i = 2, #list do
row = firstTableTag:tag('tr')
list[1] = list[i]
funcList(row)
end
firstTableTag = below(firstTableTag)
  if child then
res:wikitext('<div>')
end
end
child, none = (border == 'subgroup' or border == 'child'), (border == 'none') --再定義
return tostring(res)
end


-- render the main body of the navbox
--[[
local tbl = renderMainTable()
Template:NavboxYears
 
Template:NavboxYears2
-- render the appropriate wrapper around the navbox, depending on the border param
]]
local res = mw.html.create()
local function calc_years(args, fmtLink)
if border == 'none' then
local numtab = tonumber(args.tab) or 0
local nav = res:tag('div')
local numstart = tonumber(args.start)
:attr('role', 'navigation')
local numend = tonumber(args['end'])
:node(tbl)
local numstep = tonumber(args.step) or 1
-- aria-labelledby title, otherwise above, otherwise lone group
if numstart and numend then
if args.title or args.above or (args.group1 and not args.group2) then
if numtab > 0 then
nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title or args.above or args.group1))
for i = 2, numtab + 1 do
else
args[i] = nil
nav:attr('aria-label', 'Navbox')
end
end
end
elseif border == 'subgroup' then
local numD = numend - numstart + 1
-- We assume that this navbox is being rendered in a list cell of a parent navbox, and is
for i = 1, numD, numstep do
-- therefore inside a div with padding:0em 0.25em. We start with a </div> to avoid the
args[i + numtab + 1] = numstart + i - 1
-- padding being applied, and at the end add a <div> to balance out the parent's </div>
res
:wikitext('</div>')
:node(tbl)
:wikitext('<div>')
else
local nav = res:tag('div')
:attr('role', 'navigation')
:addClass('navbox')
:addClass(args.navboxclass)
:cssText(args.bodystyle)
:cssText(args.style)
:css('padding', '3px')
:node(tbl)
-- aria-labelledby title, otherwise above, otherwise lone group
if args.title or args.above or (args.group1 and not args.group2) then
nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title or args.above or args.group1))
else
nav:attr('aria-label', 'Navbox')
end
end
end
end
local res = mw.html.create('table')
res
:css('width', '100%')
:css('border-spacing', '0px')
:css('border-collapse', 'separate')
:css('text-align', 'center')
local h = 1
repeat
h = h + 1
local row = res:tag('tr')
for i = 2, 11 do
local tdTag = row:tag('td')
:css('width', '10%')
if (tonumber(args[i]) or -1) > 0 then
tdTag:wikitext('[[' .. fmtLink(args[1], args[i]) .. '|' .. args[i] .. ']]')
else
tdTag:wikitext(args[i])
end
args[i], args[i + 10] = args[i + 10], args[i + h * 10]
end
until not args[2]
return tostring(res)
end


if (args.nocat or 'false'):lower() == 'false' then
local function years(frame, fmtLink)
renderTrackingCategories(res)
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 '')
local res
local firstTableTag
res, firstTableTag = top()
if args.title then
firstTableTag = title(firstTableTag)
end
if args.above then
firstTableTag = above(firstTableTag)
end
if not list[1] and args[1] then list[1] = {index = 1, content = calc_years(args, fmtLink)} end
if list[1] then
firstTableTag = body1(firstTableTag)
end
firstTableTag = body2(firstTableTag)
if args.below then
firstTableTag = below(firstTableTag)
end
return tostring(res)
else
return calc_years(args, fmtLink)
end
end
end


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


function p.navbox(frame)
function p.years2(frame)
if not getArgs then
local fmtLink = function(str, num) return num .. str end
getArgs = require('Module:Arguments').getArgs
return years(frame, fmtLink)
end
args = getArgs(frame, {wrappers = {'Template:Navbox', 'Template:Navbox subgroup'}})
if frame.args.border then
-- This allows Template:Navbox_subgroup to use {{#invoke:Navbox|navbox|border=...}}.
args.border = frame.args.border
end
 
-- Read the arguments in the order they'll be output in, to make references number in the right order.
local _
_ = args.title
_ = args.above
for i = 1, 20 do
_ = args["group" .. tostring(i)]
_ = args["list" .. tostring(i)]
end
_ = args.below
 
return p._navbox(args)
end
end


return p
return p

2024年2月8日 (木) 15:32時点における最新版

このモジュールについての説明文ページを モジュール:Navbox/doc に作成できます

local p = {}

--[[
Template:Tnavbar
]]
function p.tnavbar(frame)
	local r = mw.html.create()													--出力用
	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)
	args.fontstyle = args.fontcolor ~= '' and ((args.fontstyle or '') .. ';color:' .. args.fontcolor .. ';') or args.fontstyle or ''
	
	local divTag = r:tag('div')
		:addClass('noprint')
		:addClass('plainlinks')
		:addClass('navbar')
		:addClass('hlist')
		:css('white-space', 'nowrap')
		:css('font-size', '60%')
		:css('font-weight', 'normal')
	
	if args.nodiv then
		divTag:css('display', 'inline')
			:css('padding', '0 0.5em')
	else
		divTag:css('background-color', 'transparent')
			:css('padding', '0')
			:css('color', '#000')
	end
	divTag:cssText(args.fontstyle)
		:cssText(args.style)
	
	if not (args.plain or args.mini or args.viewplain) then
		divTag:tag('span')
			:css('font-size', '125%')
			:node('このテンプレートを:&nbsp;')
	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
	local ulTag = divTag:tag('ul')
		:css('display', 'inline')
	for i = 1, i_end do
		local liTag = ulTag:tag('li')
		local l = {open = '', link = '', close = ''}
		if query[i] then
			l.open = '['
			l.link = tostring(mw.uri.canonicalUrl(ns[i] .. args[1], query[i])) .. ' '
			l.close = ']'
		else
			l.open = '[['
			l.link = ns[i] .. args[1] .. '|'
			l.close = ']]'
		end
		liTag:wikitext(l.open .. l.link)
			:tag('span')
				:attr('title', title[i])
				:css('font-size', '125%')
				:cssText(color[i])
				:cssText(args.fontstyle)
				:node(disp[i])
				:done()
			:wikitext(l.close)
	end
	
	return tostring(r)
end


--[[
Define Arguments
]]
local getArgs
local args = {}
local border
local child, none = false, false
local rowspan = 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 function defArgs(frame)
	if not getArgs then
		getArgs = require('Module:Arguments').getArgs
	end
	args = 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 'mw-collapsible '
	
	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(baseTag)
	local nav
	local bodyTable
	if baseTag == nil or baseTag == '' then
		baseTag = mw.html.create()
	end
	if child then
		baseTag:wikitext('</div>')
		nav = baseTag
	elseif not none then
		nav = baseTag:tag('div')
			:addClass('navbox')
			:addClass(args.navboxclass)
			:css('border-collapse', 'collapse')
			:cssText(args.bodystyle)
			:cssText(args.style)
			:css('padding', '3px')
		if args.title or args.above then
			nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title or args.above))
		else
			nav:attr('aria-label', 'Navbox')
		end
	else
		nav = baseTag
	end
	
	bodyTable = nav:tag('table')
		:addClass('nowraplinks')
		:addClass(args.bodyclass)

	if args.title and (args.state ~= 'plain' and args.state ~= 'off') then
		if args.state == 'collapsed' then args.state = 'mw-collapsed' end
		bodyTable
			:addClass('mw-collapsible')
			:addClass(args.state or 'autocollapse')
	end

	if child or border == 'none' then
		bodyTable
			:addClass('navbox-subgroup')
			:cssText(args.bodystyle)
			:cssText(args.style)
	else  -- regular navbox - bodystyle and style will be applied to the wrapper table
		bodyTable
			:addClass('navbox-inner')
			:css('background', 'transparent')
			:css('color', 'inherit')
	end
	bodyTable:css('min-width', '100%')
		:css('border-spacing', '0px')
		:css('border-collapse', 'separate')
		:cssText(args.innerstyle)
	
	return baseTag, bodyTable
end

--[[
title and navbar
]]
local function title(tbl)
	if not args.title then return tbl end
	local titleRow = tbl:tag('tr')
	
	if args.titlegroup then
		titleRow
			:tag('th')
				:attr('scope', 'row')
				:addClass('navbox-group')
				:addClass(args.titlegroupclass)
				:cssText(args.basestyle)
				:cssText(args.groupstyle)
				:cssText(args.titlegroupstyle)
				:wikitext(args.titlegroup)
	end

	local titleCell = titleRow:tag('th'):attr('scope', 'col')

	if args.titlegroup then
		titleCell
			:css('width', '100%')
	end
	
	local titleColspan = 2
	if args.imageleft then titleColspan = titleColspan + 1 end
	if args.image then titleColspan = titleColspan + 1 end
	if args.titlegroup then titleColspan = titleColspan - 1 end

	titleCell
		:cssText(args.basestyle)
		:cssText(args.titlestyle)
		:addClass('navbox-title')
		:attr('colspan', titleColspan)
	
	if (args.navbar == 'plain') or (not args.name and (child or none)) then
		titleCell
			:tag('div')
				:css('float', 'left')
				:css('width', '6em')
				:node('&nbsp;')
	elseif args.navbar ~= 'off' then
		local tbl = {args = {args.name, mini = '1', fontstyle = basestyle .. (args.titlestyle or '') .. ';border:none;', fontcolor = ''}}
		titleCell
			:tag('div')
				:css('float', 'left')
				:css('width', '6em')
				:css('text-align', 'left')
				:node(p.tnavbar(tbl))
	end
	
	if child or border == 'none' then
		titleCell
			:tag('div')
				:attr('id', mw.uri.anchorEncode(args.title))
				:addClass(args.titleclass)
				:css('font-size', '100%')
				:css('margin', '0 6em')
				:node(args.title)
	else
		titleCell
			:tag('div')
				:attr('id', mw.uri.anchorEncode(args.title))
				:addClass(args.titleclass)
				:css('font-size', '110%')
				:css('margin', '0 6em')
				:node(args.title)
	end

	return tbl
end

local function getAboveBelowColspan()
	local ret = 2
	if args.imageleft then ret = ret + 1 end
	if args.image then ret = ret + 1 end
	return ret
end

--[[
above
]]
local function above(tbl)
	if not args.above then return tbl end

	tbl:tag('tr')
		:tag('td')
			:addClass('navbox-abovebelow')
			:addClass(args.aboveclass)
			:cssText(args.basestyle)
			:cssText(args.abovestyle)
			:attr('colspan', getAboveBelowColspan())
			:newline()
			:node(args.above)
	return tbl
end
	
--[[
body
]]
--first group/list and images
local function body1(tbl)
	local row = tbl:tag('tr')
	if args.imageleft then
		row
			:tag('td')
				:addClass('navbox-image')
				:addClass(args.imageclass)
				:css('width', '1px')
				:css('padding', '0px 2px 0px 0px')
				:cssText(args.imageleftstyle)
				:attr('rowspan', rowspan)
				:tag('div')
					:node(args.imageleft)
	end
	local j = list[1].index
	if group[j] then
		local groupCell = row:tag('th')

		groupCell
			:attr('scope', 'row')
			:addClass('navbox-group')
			:addClass(args.groupclass)
			:cssText(args.basestyle)
			:css('width', args.groupwidth or '1%')

		groupCell
			:cssText(args.groupstyle)
			:cssText(groupstyle[j])
			:wikitext(group[j])
	end

	local listCell = row:tag('td')

	if group[j] then
		listCell
			:css('text-align', 'left')
			:css('border-left-width', '2px')
			:css('border-left-style', 'solid')
	else
		listCell:attr('colspan', 2)
	end

	if not args.groupwidth then
		listCell:css('width', '100%')
	end

	local rowstyle
	if odd == 'odd' then
		rowstyle = args.oddstyle
	else
		rowstyle = args.evenstyle
	end

	listCell
		:css('padding', '0px')
		:cssText(args.liststyle)
		:cssText(rowstyle)
		:cssText(liststyle[j])
		:addClass('navbox-list')
		:addClass('navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd))
		:addClass(args.listclass)
		:tag('div')
			:css('padding', (args.list1padding or args.listpadding or '0em 0.25em'))
			:node(list[1].content)
			:newline()
	if args.image then
		row
			:tag('td')
				:addClass('navbox-image')
				:addClass(args.imageclass)
				:css('width', '1px')
				:css('padding', '0px 0px 0px 2px')
				:cssText(args.imagestyle)
				:attr('rowspan', rowspan)
				:tag('div')
					:node(args.image)
	end
	return tbl
end

--remaining groups/lists
local function body2(tbl)
	for i = 2, #list do
		odd, even = even, odd
		local j = list[i].index
		local row = tbl:tag('tr')
		if group[j] then
			local groupCell = row:tag('th')
			groupCell
				:attr('scope', 'row')
				:addClass('navbox-group')
				:addClass(args.groupclass)
				:cssText(args.basestyle)
				:css('width', args.groupwidth or '1%')

			groupCell
				:cssText(args.groupstyle)
				:cssText(groupstyle[j])
				:node(group[j])
		end

		local listCell = row:tag('td')

		if group[j] then
			listCell
				:css('text-align', 'left')
				:css('border-left-width', '2px')
				:css('border-left-style', 'solid')
		else
			listCell:attr('colspan', 2)
		end

		if not args.groupwidth then
			listCell:css('width', '100%')
		end

		local rowstyle
		if odd == 'odd' then
			rowstyle = args.oddstyle
		else
			rowstyle = args.evenstyle
		end
		listCell
			:css('padding', '0px')
			:cssText(args.liststyle)
			:cssText(rowstyle)
			:cssText(liststyle[j])
			:addClass('navbox-list')
			:addClass('navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd))
			:addClass(args.listclass)
			:tag('div')
				:css('padding', (args.listpadding or '0em 0.25em'))
				:node(list[i].content)
				:newline()
	end
	return tbl
end

--[[
below
]]
local function below(tbl)
	if not args.below then return tbl end

	tbl:tag('tr')
		:tag('td')
			:addClass('navbox-abovebelow')
			:addClass(args.belowclass)
			:cssText(args.basestyle)
			:cssText(args.belowstyle)
			:attr('colspan', getAboveBelowColspan())
			:newline()
			:node(args.below)
	return tbl
end

--[[
Template:Navbox
]]
function p.navbox(frame)
	defArgs(frame)
	local res
	local firstTableTag
	res, firstTableTag = top()
	firstTableTag = title(firstTableTag)
	firstTableTag = above(firstTableTag)
	if list[1] then
		firstTableTag = body1(firstTableTag)
	end
	firstTableTag = body2(firstTableTag)
	firstTableTag = below(firstTableTag)
	if child then
		res:wikitext('<div>')
	end
	return tostring(res)
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 '')
	
	local res
	local firstTableTag
	res, firstTableTag = top()
	firstTableTag = title(firstTableTag)
	firstTableTag = above(firstTableTag)
	if list[1] then
		firstTableTag = body1(firstTableTag)
	end
	firstTableTag = body2(firstTableTag)
	firstTableTag = below(firstTableTag)
	if not border then res:wikitext('<div>') end
	return tostring(res)
end

--[[
Template:Navbox with columns
]]
function p.with_columns(frame)
	defArgs(frame)
	table.sort(col)
	local res
	local firstTableTag
	res, firstTableTag = top()
	
	firstTableTag = title(firstTableTag)
	firstTableTag = above(firstTableTag)
	
	if col[1] then
		local j = col[1].index
		local cols = mw.html.create('table')
			:addClass('navbox-columns-table')
			:css('border-spacing', '0px')
			:css('border-collapse', 'separate')
			:css('text-align', 'left')
			:cssText((colheader[j] or args.fullwidth) and 'width:100%;' or 'margin:0 auto;')
			:cssText(args.coltablestyle)
		--Header row
		if colheader[j] then
			local headerRow = cols:tag('tr')
				:addClass('navbox-abovebelow')
				:css('font-weight', 'bold')
				:cssText(args.colheaderstyle)
			for i = 1, #col do
				local j = col[i].index
				if colheader[j] then
					headerRow:tag('td')
						:attr('colspan', colheadercolspan[j] or '1')
						:cssText(colheaderstyle[j])
						:node(colheader[j])
				end
			end
		end
		--Main columns
		local row = cols:tag('tr')
			:css('vertical-align', 'top')
			:cssText(args.colstyle)
		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
				row:tag('td')
					:css('width', args.padding or '5em')
					:wikitext('&nbsp;&nbsp;&nbsp;')
			end
		end
		for i = 1, #col do
			local j = col[i].index
			row:tag('td')
				:css('padding', '0')
				:cssText(args.oddcolstyle)
				:cssText(colstyle[j])
				:css('width', colwidth[j] or args.colwidth or '10em')
				:node(col[i].content)
			args.oddcolstyle, args.evencolstyle = args.evencolstyle, args.oddcolstyle
		end
		--Footer row
		if colfooter[j] then
			row = cols:tag('tr')
				:addClass('navbox-abovebelow')
				:css('font-weight', 'bold')
				:cssText(args.colfooterstyle)
			for i = 1, #col do
				local j = col[i].index
				if colfooter[j] then
					row:tag('td')
						:attr('colspan', colfootercolspan[j] or '1')
						:cssText(colfooterstyle[j])
						:node(colfooter[j])
				end
			end
		end
		cols = mw.html.create():wikitext('</div>'):wikitext(tostring(cols)):wikitext('<div>')
		table.insert(list, {index=1, content=cols})
		rowspan = rowspan + 1
	end
	
	firstTableTag = body1(firstTableTag)
	firstTableTag = body2(firstTableTag)
	firstTableTag = below(firstTableTag)
	return tostring(res)
end

--[[
Template:Navbox with collapsible groups
]]
function p.with_collapsible_groups(frame)
	local res
	local firstTableTag
	defArgs(frame)
	table.sort(content)
	res, firstTableTag = top()
	firstTableTag = title(firstTableTag)
	firstTableTag = above(firstTableTag)
	
	local i = 1
	local function funcList(rowTag)
		list[i] = list[i] or content[i]
		local j = list[i].index
		args.state = state[j] or args.selected and (args.selected == abbr[j] or args.selected == group[j]) and '' or 'mw-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]
		rowspan = 1
		local baseTag = rowTag:tag('td')
			:cssText(args.groupwidth and '' or 'width:100%;')
			:css('padding', '0px')
			:cssText(args.liststyle)
			:cssText(odd == 'odd' and (args.oddstyle or '') or (args.evenstyle or ''))
			:cssText(liststyle[j])
			:addClass('navbox-list')
			:addClass('navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd))
			:addClass(args.listclass)
			:tag('div')
		if args.title then
			local tableTag
			none = true
			baseTag, tableTag = top(baseTag)
			tableTag = title(tableTag)
			tableTag = body1(tableTag)
      if child then
        baseTag:wikitext('<div>')
      end
		else
			baseTag:node(list[i].content)
		end
	end
	
	--i = 1
	local row = firstTableTag:tag('tr')
	if args.imageleft then
		row:tag('td')
			:addClass('navbox-image')
			:addClass(args.imageclass)
			:css('width', '0')
			:css('padding', '0 2px 0 0')
			:cssText(args.imageleftstyle)
			:attr('rowspan', rowspan)
			:node(args.imageleft)
	end
	funcList(row)
	if args.image then
		row:tag('td')
			:css('width', '0%')
			:css('padding', '0 0 0 2px')
			:cssText(args.imagestyle)
			:attr('rowspan', rowspan)
			:node(args.image)
	end
	--i > 2
	for i = 2, #list do
		row = firstTableTag:tag('tr')
		list[1] = list[i]
		funcList(row)
	end
	
	firstTableTag = below(firstTableTag)
  if child then
		res:wikitext('<div>')
	end
	child, none = (border == 'subgroup' or border == 'child'), (border == 'none') --再定義
	return tostring(res)
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 res = mw.html.create('table')
	res
		:css('width', '100%')
		:css('border-spacing', '0px')
		:css('border-collapse', 'separate')
		:css('text-align', 'center')
	local h = 1
	repeat
		h = h + 1
		local row = res:tag('tr')
		for i = 2, 11 do
			local tdTag = row:tag('td')
				:css('width', '10%')
			if (tonumber(args[i]) or -1) > 0 then
				tdTag:wikitext('[[' .. fmtLink(args[1], args[i]) .. '|' .. args[i] .. ']]')
			else
				tdTag:wikitext(args[i])
			end
			args[i], args[i + 10] = args[i + 10], args[i + h * 10]
		end
	until not args[2]
	return tostring(res)
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 '')
		local res
		local firstTableTag
		res, firstTableTag = top()
		if args.title then 
			firstTableTag = title(firstTableTag)
		end
		if args.above then
			firstTableTag = above(firstTableTag)
		end
		if not list[1] and args[1] then list[1] = {index = 1, content = calc_years(args, fmtLink)} end
		if list[1] then
			firstTableTag = body1(firstTableTag)
		end
		firstTableTag = body2(firstTableTag)
		if args.below then
			firstTableTag = below(firstTableTag)
		end
		return tostring(res)
	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