Module:Documentation/Template

local p = {} local h = {}

local i18n = require("Module:I18n") local s = i18n.getString local utilsMarkup = require("Module:UtilsMarkup")

function p.Examples(frame) local args = frame:getParent.args return p.examples(args) end

function p.examples(templateExamples) if not templateExamples.vertical then local tableData = { hideEmptyColumns = true, rows = { { s("input"), s("output"), s("categoriesAdded"), header = true } }		}		for _, example in ipairs(templateExamples) do			local input, output, categoryList = h.example(example) input = utilsMarkup.code(input) table.insert(tableData.rows, {input, output, categoryList}) end return utilsMarkup.wikitable(tableData) end local result = "" for _, example in ipairs(templateExamples) do		local input, output, categoryList = h.example(example) input = utilsMarkup.pre(input) local headerStyles = { ["width"] = "5rem" -- for alignment. See Template:Letter/Documentation for an example of why this is needed }		result = result .. utilsMarkup.wikitable({			hideEmptyRows = true,			rows = {				{					{ header = true, content= s("input"), styles = headerStyles}, 					input,				},				{					{ header = true, content = s("output"), styles = headerStyles}, 					output				},				{					{ header = true, content = s("categoriesAdded"), styles = headerStyles },					categoryList				},			}		}) .. "\n" end return result end

function h.example(example) local input = mw.text.unstripNoWiki(example) local output = mw.getCurrentFrame:preprocess(input) input = mw.text.trim(input) input = mw.text.nowiki(input) local output, categories = utilsMarkup.stripCategories(output) local output = utilsMarkup.killBacklinks(output) local categoryList = utilsMarkup.bulletList(categories) return input, output, categoryList end

i18n.loadStrings({	en = {		input = "Input",		output = "Output",		categoriesAdded = "Categories added",	} })

return p