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) return mw.getCurrentFrame:extensionTag(tag, content, args) end end

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

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

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

function p.class(class, content) return tag("span", {		class = class,	})(content) 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