Module:UtilsMarkup/Format

local p = {} local h = {}

local utilsFunction = require("Module:UtilsFunction") local utilsTable = require("Module:UtilsTable")

function tag(tag, attributes) return function(content) return tostring(mw.html.create(tag)			:attr(attributes or {})			:wikitext(content)) end end function extensionTag(tag, defaultArgs) return function(content, overrideArgs) local args = utilsTable.merge(defaultArgs, overrideArgs or {}) return mw.getCurrentFrame:extensionTag(tag, content, args) end end

p.pre = extensionTag("pre") p.nowiki = extensionTag("nowiki") p.code = extensionTag("code") p.bold = tag("b") p.italic = tag("i")

function p.syntaxHighlight(lang, args) local args = utilsTable.merge(args or {}, {		lang = lang	}) return extensionTag("syntaxHighlight", args) end

function p.lua(content) if type(content) ~= "string" then content = utilsTable.print(content) end return p.syntaxHighlight("lua")(content) end

function p.fontSize(fontSize, content) return tag("span", {		fontSize = fontSize	})(content) end

function p.explain(caption) return tag("span", {		class = "explain",		title = caption,	}) end

function p.class(class, content) return tag("span", {		class = class,	})(content) end

function p.header(level) local headerTag = string.rep("=", level) return function(content) return headerTag .. content .. headerTag end end

function p.format(text, args) if not args then return text end local noop = utilsFunction.noop return utilsFunction.pipe(		args.pre and p.pre or noop,		args.syntaxHighlight and extensionTag("syntaxHighlight", {lang = args.syntaxHighlight}) or noop,		args.code and p.code or noop,		args.nowiki and p.nowiki or noop,		args.class and tag("span", {class= args.class}) or noop,		args.explain and p.explain or noop,		args.bold and p.bold or noop,		args.italic and p.italic or noop,		args.fontSize and p.fontSize or noop	)(text) end

return p