Module:Lalis/sandbox

require('strict')

local p = {}

local getArgs = require('Module:Arguments').getArgs local lalisabr = require('Module:Lalisabr')._abbreviation local lalislink = require('Module:Lalislink')._link

function p.lalis_format(frame) local args = getArgs(frame) local wikitext = args[1] or "" local abr = mw.loadData('Module:Lalisabr/data') local keys = {} for index, value in ipairs(abr) do		keys[index] = value[1] end table.sort(keys, function (a, b) return #a > #b end) for index, key in ipairs(keys) do local k = "([ %(])" .. mw.ustring.gsub(key, "%.", "%%.")		wikitext = mw.ustring.gsub(wikitext, k, "%1" .. lalisabr({key}))	end	wikitext = "\n" .. wikitext	wikitext = mw.ustring.gsub(wikitext, "!!", "‖")	local multicol_break = frame:expandTemplate {title = "multicol-break", args = {}}	wikitext = mw.ustring.gsub(wikitext, "%-%-%-%-", multicol_break)	wikitext = mw.ustring.gsub(wikitext, "\n[^\n]*wst%-rule[^\n]*\n", "\n" .. multicol_break .. "\n")	wikitext = mw.ustring.gsub(wikitext, "%<<(.-)%>>", lalislink("%1"))	local function nowrap(text)		return frame:expandTemplate {title = "nowrap", args = {text}}	end	wikitext = mw.ustring.gsub(wikitext, "%(%-(%a+), %-(%a+), %-(%a+)%)", "(" .. nowrap("-%1") .. ", " .. nowrap("-%2") .. ", " .. nowrap("-%3") .. ")")	wikitext = mw.ustring.gsub(wikitext, " ([-–])(%a+)", " '''" .. nowrap("%1%2") .. "")	wikitext = mw.ustring.gsub(wikitext, "\n(%u%a-) %(", "\n<%1> (")	wikitext = mw.ustring.gsub(wikitext, "\n(%u[^\n]-),", "\n<%1>,")	local function anchor(text)		return frame:expandTemplate {title = "anchor+", args = {text}}	end	wikitext = mw.ustring.gsub(wikitext, "%<(%u.-)%>, %-(%a+)", "" .. anchor("%1") .. ", -%2")	wikitext = mw.ustring.gsub(wikitext, "%<(%u.-)%>", "" .. anchor("%1") .. "'''")	wikitext = mw.ustring.sub(wikitext, 2)	return frame:preprocess(wikitext) end

return p