Module:Mctxt

local getArgs = require('Module:Arguments').getArgs

local p = {}

function p.raw( frame ) local args = getArgs(frame) return p._raw(args[1], args.size or args[2], args.style) end

function p._raw( str, size, style ) str = str:gsub('\n', '/'):gsub(' ', '/') size = tonumber(size) and (size .. 'px') or size or '12px' local s = str:gsub('\\\\', '%%%%BACKSLASH%%%%'):gsub('\\/', '%%%%FORSLASH%%%%'):gsub('\\&', '%%%%AMPERSAND%%%%') local t = mw.text.split(s, '/') for i, l in ipairs(t) do		-- handle modifiers and add trailing &r local availableMods = 'cr' -- put all available modifiers here local pttn, lineclass = '^$%([' .. availableMods .. ']+%)', nil local modifiers = l:match(pttn) or '' if modifiers then if modifiers:match('c') then lineclass = 'centertxt' end if modifiers:match('r') then lineclass = 'righttxt' end l = l:gsub(pttn, '') end l = lineclass and (' ' .. l .. '&r ') or (l .. '&r') -- handle colors and formatting while (l:match('&[0-9a-fk-o]')) do			l = l:gsub('&([0-9a-fk-o])(.-)(&[0-9a-fr])', '%2&r %3') end t[i] = l	end s = table.concat(t, ' ') s = s:gsub('&r', ''):gsub('%%%%BACKSLASH%%%%', '\\\\'):gsub('%%%%FORSLASH%%%%', '\\/'):gsub('%%%%AMPERSAND%%%%', '\\&'):gsub('\\(.)', '%1') s = ' ' .. s .. ' '	return (' %s '):format(size, style or '', s) end

function p.dialogue( frame ) local args = getArgs(frame) return p._dialogue(args[1], args.size or args[2], args.style) end

function p._dialogue( str, size, style ) return '' .. p._raw(str, size or 11) .. ' ' end

return p