Module:OnshokoeseScript: Difference between revisions

From Constructed Worlds Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 9: Line 9:
     local span = mw.html.create( 'span' )
     local span = mw.html.create( 'span' )
     if (size == nil or size == '') then size='14' end
     if (size == nil or size == '') then size='14' end
     local i=1
     for i=1, string.len(humanwords) do
    repeat
         local replacement = CharData[humanwords:sub(i,i + 2)]
         local replacement = CharData[humanwords:sub(i,i + 2)]
         if replacement ~= nil then
         if replacement ~= nil then
Line 30: Line 29:
         end
         end
         end
         end
     until i > string.len(humanwords)
     end
     span    :css( 'font-size', size..'px' )
     span    :css( 'font-size', size..'px' )
             :wikitext( table.concat(output_string) )
             :wikitext( table.concat(output_string) )

Revision as of 22:56, 25 April 2024

Documentation for this module may be created at Module:OnshokoeseScript/doc

local getArgs = require('Module:Arguments').getArgs
local p = {}

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

function p._onshokoese( humanwords, size )
    local output_string = {}
    local humanwords = string.lower(humanwords)
    local span = mw.html.create( 'span' )
    if (size == nil or size == '') then size='14' end
    for i=1, string.len(humanwords) do
        local replacement = CharData[humanwords:sub(i,i + 2)]
        if replacement ~= nil then
            table.insert(output_string,'[[File:'..replacement..'|x'..size..'px|link=]]')
            i = i + 3
        else
            local replacement = CharData[humanwords:sub(i,i + 1)]
        if replacement ~= nil then
            table.insert(output_string,'[[File:'..replacement..'|x'..size..'px|link=]]')
            i = i + 2
        else
            local replacement = CharData[humanwords:sub(i,i)]
        if replacement ~= nil then
            table.insert(output_string,'[[File:'..replacement..'|x'..size..'px|link=]]')
        else
            table.insert(output_string,'  ')
            i = i + 1
        end
        end
        end
    end
    span    :css( 'font-size', size..'px' )
            :wikitext( table.concat(output_string) )
    return tostring(span)
end

function p.main(frame)
    local string_input = frame.args[1]
    local num_input = frame.args[2]
    return p._onshokoese(string_input, num_input)
   
end

function p._main(args)
	local first = args[1] or ''
	local second = args[2] or ''
	return first .. ' ' .. second
end

return p