Module:Aurebesh

local p = {}

local data = mw.loadData('Module:Aurebesh/data')

local yesno = require('Module:Yesno')

local imagelink = ''

local function makeWikitextError(msg) return string.format(		' Aurebesh error: %s. %s',		msg,       makeCategoryLink('Pages with invalid Aurebesh templates')	) end

local function escapePattern(str) return mw.ustring.gsub(str, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1") end

local function singlechars(args) local style = args.style local link = args.link or '' local ret = {} for _, arg in ipairs(args) do       char = mw.ustring.lower(arg) if data.chars[char] then ret[#ret + 1] = imagelink:format(               data.chars[char][style],                link,                ,                            ) else return makeWikitextError(string.format( 'unrecognized character "%s"', char ))       end end local spacer = imagelink:format('1pixelspace.png', link, , ) return table.concat(ret, spacer) end

function p._main(args) local style = args.style if not style then style = 'regular' end if not data.sets.style[style] then return makeWikitextError('invalid argument to "style"') end local digraphs = args.digraphs if digraphs then digraphs = yesno(digraphs, 'error') if digraphs == 'error' then return makeWikitextError('invalid argument to "digraphs"') end else digraphs = true end local link = args.link or '' local ret = {} for _, arg in ipairs(args) do       arg = mw.ustring.lower(arg) local pos = 0 while pos < mw.ustring.len(arg) do           pos = pos + 1 local char = mw.ustring.sub(arg, pos, pos) local lookup = char if char == "'" or char == '"' then               local prevchar = mw.ustring.sub(arg, pos - 1, pos - 1)                if prevchar == ' ' or prevchar == '\n' or prevchar == '' then                    lookup = char .. 'l'                else                    lookup = char .. 'r'                end            end            if digraphs and data.sets.digraphstarts[char] then                local nextchar = mw.ustring.sub(arg, pos + 1, pos + 1)                if data.sets.digraphs[prevchar..nextchar] then                    char = prevchar .. nextchar                    lookup = char                    pos = pos + 1                end            end            if char == ' ' or char == '\n' then                ret[#ret + 1] = char            elseif data.chars[lookup] then                ret[#ret + 1] = imagelink:format(                    data.chars[lookup][style],                    link, char, char )           else                return makeWikitextError(string.format(                    'unrecognized character "%s"',                    char                ))            end        end    end    local spacer = imagelink:format('1pixelspace.png', link, , )    output = table.concat(ret, spacer)    output = mw.ustring.gsub(output, '\n' .. escapePattern(spacer), '\n')   return output end

local function processArgs(frame) local args = {} for k, v in pairs(frame:getParent.args) do		v = v:match('^%s*(.-)%s*$') -- trim whitespace if v ~= '' then args[k] = v		end end return args end

-- called from deprecated Template:Aur function p.regular(frame) local args = processArgs(frame) args.style = 'regular' return singlechars(args) end

-- called from deprecated Template:AurB function p.bold(frame) local args = processArgs(frame) args.style = 'bold' return singlechars(args) end

-- called from new Template:AurText function p.main(frame) local args = processArgs(frame) return p._main(args) end

return p