Module:Hatnote

local p = {} local getArgs = require('Module:Arguments').getArgs

local i18n = { -- Prefixes see_also_prefix = 'See also', main_article_prefix_singular = 'Main Article', main_article_prefix_plural = 'Main Articles', -- Separators prefix_separator = ': ', -- Errors error_no_text = 'No text given', }

function p.hatnote(frame) -- Implements Template:Hatnote. local args = getArgs(frame, {   wrappers = {      'Template:Hatnote'    }  }) assert(args[1], i18n.error_no_text) return p._main(args[1], args['style']) end

function p.main_article(frame) -- Implements Template:Main. local args = getArgs(frame, {   wrappers = {      'Template:Main'    }  }) assert(args[1], i18n.error_no_text)

local text = i18n.main_article_prefix_singular if args[2] then text = i18n.main_article_prefix_plural end text = text .. i18n.prefix_separator

local articles, n = {}, 1 while args[n] do   table.insert(articles,  .. (args['l' .. n] or args[n]) .. ) n = n + 1 end

local text = text .. mw.text.listToText(articles)

return p._main(text) end

function p.see_also(frame) -- Implements Template:See also. local args = getArgs(frame, {   wrappers = {      'Template:See also'    }  }) assert(args[1], i18n.error_no_text)

local articles, n = {}, 1 while args[n] do   local title = args['l' .. n] or args[n] table.insert(articles,  .. title .. ) n = n + 1 end

local text = i18n.see_also_prefix .. i18n.prefix_separator .. mw.text.listToText(articles)

return p._main(text) end

function p._main(text, style) return mw.html.create('div') :css('font-style', 'italic') :css('font-size', '15px') :css('padding-left', '2em') :css('margin-bottom', '0.5em') :cssText(style) :wikitext(text) end

return p