Module:TOCyears
Appearance
This module implements {{TOCyears}}
Usage
From wikitext
From wikitext this module should usually be used through {{TOCyears}}. However, it is also possible to use it with the following syntax:
{{#invoke:TOC|years|args}}
See the documentation of {{TOCyears}} for available parameters.
From Lua
Load the module like this:
local mTOCyears = require('Module:TOCyears')
You can then use it with the following syntax:
mTOCyears._years(args)
args variable is a table of arguments to be passed to the function. Please see {{TOCyears}} for available arguments.
-- This module implements various templates that create custom tables of
-- contents.
-- Load necessary modules
local yesno = require('Module:Yesno')
local checkType = require('libraryUtil').checkType
local p = {}
local function makeToc(s, args)
-- Make a TOC box from a string and from the given table of arguments.
checkType('makeToc', 1, s, 'string')
checkType('makeToc', 2, args, 'table', true)
args = args or {}
-- Root
local root = mw.html.create()
local isPrimary = yesno(args.primary) ~= false
if isPrimary then
root:wikitext('__NOTOC__')
end
-- Top div tag
local top = root:tag('div')
top:addClass('toc plainlinks hlist')
if isPrimary then
top:attr('id', 'toc')
end
local align = args.align and args.align:lower()
if align == 'left' then
top
:css('float', 'left')
:css('clear', args.clear or 'left')
elseif align == 'right' then
top
:css('float', 'right')
:css('clear', args.clear or 'right')
elseif align == 'center' then
top
:css('margin', 'auto')
:css('clear', args.clear or 'none')
else
top
:css('clear', args.clear or 'left')
end
top:newline()
-- Title div tag
local title = args.title or mw.message.new('Toc'):plain()
local titleDiv = top:tag('div')
titleDiv:attr('id', 'toctitle')
if isPrimary then
titleDiv:tag('h2'):wikitext(title)
else
titleDiv:tag('strong'):wikitext(title)
end
-- Content
top:wikitext(s)
return tostring(root)
end
p.makeToc = makeToc
return p