Module:Morse/sandbox

local export = {}

local sc = require("Module:scripts").getByCode("Morse")

local charList = { ["A"] = ".-", ["B"] = "-...", ["C"] = "-.-.", ["D"] = "-..", ["E"] = ".", ["F"] = "..-.", ["G"] = "--.", ["H"] = "....", ["I"] = "..", ["J"] = ".---", ["K"] = "-.-", ["L"] = ".-..", ["M"] = "--", ["N"] = "-.", ["O"] = "---", ["P"] = ".--.", ["Q"] = "--.-", ["R"] = ".-.", ["S"] = "...", ["T"] = "-", ["U"] = "..-", ["V"] = "...-", ["W"] = ".--", ["X"] = "-..-", ["Y"] = "-.--", ["Z"] = "--..", }

local headwordMap = { ["."] = "",	["-"] = "",	[" "] = "", }

local inlineMap = { ["."] = "",	["-"] = "",	[" "] = "", }

function export.convertToMorse(text) local result = mw.ustring.gsub(text, ".", charList)

return result end

function export.textToHeadword(text) return mw.ustring.gsub(text, "[-. ]", headwordMap) end

function export.textToInline(text) return mw.ustring.gsub(text, "[-. ]", inlineMap) end

function export.link(frame) local text = frame:getParent.args[1] local textUpper = mw.ustring.upper(text) local morseValues = export.convertToMorse(textUpper) local morseFinal = export.textToInline(morseValues)

local result = morseFinal return result end

local types = { ["letter"] = "letters", ["number"] = "numbers", ["punctuation mark"] = "punctuation marks", ["symbol"] = "symbols", ["interjection"] = "interjections", }

function export.headword(frame)

local m_head = require("Module:headword")

local type = frame.args["1"] ~= "" and frame.args["1"] local head = frame:getParent.args["head"] if not head or head == "" then head = mw.title.getCurrentTitle.subpageText end local langCode = frame.args["lang"] or "mul" local lang = require("Module:languages").getByCode(langCode)

local display = ' ' .. export.textToHeadword(head) .. ' '	local data = {lang = lang, sc = sc, categories = {}, sort_key = head, heads = {display}, translits = {"-"}} if types[type] then data.pos_category = types[type] end

return m_head.full_headword(data)

end

return export