Module:Navbox or wikitable
| This module is rated as beta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected. |
| Editing of this module by new or unregistered users is currently disabled. See the protection policy and protection log for more details. If you cannot edit this module and you wish to make a change, you can submit an edit request, discuss changes on the talk page, request unprotection, log in, or create an account. |
| This module depends on the following other modules: |
This module can be used to create a navbox which can be optionally rendered as a wikitable. This is useful when one would like to have the content of a navbox rendered in the middle of an article as a regular table.
Usage
Take any navbox and replace
{{navbox
with
{{#invoke:navbox or wikitable|main|navbox={{{navbox|}}}
By default, the navbox will render as a navbox, but if |navbox=no then it will render as a wikitable.
require('strict')
local p = {}
local function isnotempty(s)
return s and s:match( '^%s*(.-)%s*$' ) ~= ''
end
-- this function was copied from [[Module:Navbox]]
local function processItem(item, nowrapitems)
if item:sub(1, 2) == '{|' then
-- 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.
return '\n' .. item .. '\n'
end
if nowrapitems == 'yes' then
local lines = {}
for line in (item .. '\n'):gmatch('([^\n]*)\n') do
local prefix, content = line:match('^([*:;#]+)%s*(.*)')
if prefix and not content:match('^<span class="nowrap">') then
line = string.format('%s<span class="nowrap">%s</span>', prefix, content)
end
table.insert(lines, line)
end
item = table.concat(lines, '\n')
end
if item:match('^[*:;#]') then
return '\n' .. item .. '\n'
end
return item
end
function p.main(frame)
local yesno = require('Module:Yesno')
local is_navbox = yesno(frame.args['navbox'] or 'yes', true)
-- If this is not a table, then jump straight over to the navbox module
if ( is_navbox ) then
return require('Module:Navbox').navbox(frame, 'navbox')
end
local args = frame.args
-- get the group and list numbers
local groups, lists, nums = {}, {}, {}
for k,v in pairs(args) do
if type(k) == 'string' and k:match('^list[0-9][0-9]*$') then
local i = mw.ustring.gsub(k,'^list([0-9][0-9]*)$', '%1')
i = tonumber(i)
if lists[i] == nil and groups[i] == nil then
table.insert(nums, i)
end
lists[i] = v
elseif type(k) == 'string' and k:match('^group[0-9][0-9]*$') then
local i = mw.ustring.gsub(k,'^group([0-9][0-9]*)$', '%1')
i = tonumber(i)
if groups[i] == nil and lists[i] == nil then
table.insert(nums, i)
end
groups[i] = v
end
end
-- sort the group and list numbers
table.sort(nums)
-- generate the table
local tbl = mw.html.create('table')
:addClass('wikitable')
:addClass('args.bodyclass')
local navbar = require('Module:Navbar')._navbar
tbl:tag('caption')
:wikitext(args.title or '')
:wikitext(navbar{
['name'] = args.name,
['mini'] = 1,
['brackets'] = 1,
['style'] = 'float:right'
})
if isnotempty(args['above']) then
local row = tbl:tag('tr')
row:tag('td')
:attr('colspan', 2)
:css('text-align', 'center')
:wikitext(args['above'])
end
for ni = 1, #nums do
local i = nums[ni]
if isnotempty(args['group' .. i]) and isnotempty(args['list' .. i]) then
local row = tbl:tag('tr'):css('vertical-align', 'top')
row:tag('th')
:attr('scope', 'row')
:css('font-weight', 'normal')
:css('white-space', 'nowrap')
:wikitext(args['group' .. i])
row:tag('td')
:tag('div')
:addClass(args.listclass)
:wikitext(processItem(args['list' .. i], args['nowrapitems']))
elseif isnotempty(args['list' .. i]) then
local row = tbl:tag('tr')
row:tag('td')
:attr('colspan', 2)
:css('text-align', 'center')
:tag('div')
:addClass(args.listclass)
:wikitext(processItem(args['list' .. i], args['nowrapitems']))
end
end
if isnotempty(args['below']) then
local row = tbl:tag('tr')
row:tag('td')
:attr('colspan', 2)
:css('text-align', 'center')
:wikitext(args['below'])
end
return tbl
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.