Module:User:Erutuon/10

local export = {}

local Array = require "Module:array"

local function superscript_edit_link(title) return "&lbrack;edit&rbrack;" end

local function template_to_wikitext(name, parameters) local printed = { name } local i = 0 for _, param in ipairs(parameters) do       local k, v = unpack(param) local k_number = tonumber(k) if k_number and k_number == i + 1 then table.insert(printed, v)           i = k_number else table.insert(printed, k .. "=" .. v)       end end return "" end

local function format_bad_characters(bad_characters) local bad_character_text = Array if type(bad_characters) == "string" then for character in mw.ustring.gmatch(bad_characters, ".") do			local code_point = mw.ustring.codepoint(character) local text = " " if not (0x21 <= code_point and code_point <= 0x7E) then text = text .. " ("				.. require "Module:Unicode data".lookup_name(code_point)				.. ")" end bad_character_text:insert(text) end else for _, str in ipairs(bad_characters) do			if str:find("[^\33-\126]") then for character in mw.ustring.gmatch(str, ".") do					local code_point = mw.ustring.codepoint(character) local text = " " if not (0x21 <= code_point and code_point <= 0x7E) then text = text .. " ("						.. require "Module:Unicode data".lookup_name(code_point)						.. ")" end bad_character_text:insert(text) end else bad_character_text:insert(" ") end end end return bad_character_text:concat ", " end

function export.show(frame) local content = frame.args[1] and mw.text.trim(mw.text.unstripNoWiki(frame.args[1])) or mw.title.new(mw.title.getCurrentTitle.fullText .. "/data") :getContent:match("^%s* %s*$") local output = Array local script_tag_link = require "Module:script tag link".tag_link local titles = Array for line in mw.text.gsplit(content, "\n") do		local ok, data = pcall(mw.text.jsonDecode, line) if not (ok and data) then mw.log("The line " .. tostring(line) .. " couldn't be decoded or did not yield a table.") break end titles:insert(data.title) output:insert("; " .. script_tag_link(data.title) .. " " .. superscript_edit_link(data.title) .. "\n") if data.templates then for _, template in ipairs(data.templates) do				-- [ "" ] if type(template) == "string" then output:insert(frame:extensionTag("pre", mw.text.nowiki(template))) -- [ { "template": [ ["1", "en"], ["2", "term"] ], link: { ... }, ... } ]				elseif type(template) == "table" then local original_name, redirected_name, parameters = unpack(template.template) local wikitext = template_to_wikitext(original_name, parameters) local line = '* ' if template.bad_characters then line = line .. ": " .. format_bad_characters(template.bad_characters) end output:insert(line) end end elseif data.templates_and_bad_characters then for i, item in ipairs(data.templates_and_bad_characters) do				local bad_character_text = format_bad_characters(item.bad_characters) output:insert(					"* : "					.. bad_character_text				) end end end return ' \n' .. output:concat "\n" .. "\n \n; All titles:\n " .. titles:concat "\n" .. " " end

return export