Module:OnshokoeseScript: Difference between revisions

From Constructed Worlds Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 10: Line 10:
     if (size == nil or size == '') then size='14' end
     if (size == nil or size == '') then size='14' end
     local i=1
     local i=1
     repeat
     local j=string.len(humanwords)
         local replacement = CharData["OnshokoeseChar"][humanwords:sub(i,i + 2)]
    while (i <= j) do
         local replacement = CharData[humanwords:sub(i,i + 2)]
         if replacement ~= nil then
         if replacement ~= nil then
             table.insert(output_string,'[[File:'..replacement..'|x'..size..'px|link=]]')
             table.insert(output_string,'[[File:'..replacement..'|x'..size..'px|link=]]')
             i = i + 3
             i = i + 3
         else
         else
             local replacement = CharData["OnshokoeseChar"][humanwords:sub(i,i + 1)]
             local replacement = CharData[humanwords:sub(i,i + 1)]
         if replacement ~= nil then
         if replacement ~= nil then
             table.insert(output_string,'[[File:'..replacement..'|x'..size..'px|link=]]')
             table.insert(output_string,'[[File:'..replacement..'|x'..size..'px|link=]]')
             i = i + 2
             i = i + 2
         else
         else
             local replacement = CharData["OnshokoeseChar"][humanwords:sub(i,i)]
             local replacement = CharData[humanwords:sub(i,i)]
         if replacement ~= nil then
         if replacement ~= nil then
             table.insert(output_string,'[[File:'..replacement..'|x'..size..'px|link=]]')
             table.insert(output_string,'[[File:'..replacement..'|x'..size..'px|link=]]')
            i = i + 1
         else
         else
             table.insert(output_string,'&nbsp;&nbsp;')
             table.insert(output_string,'&nbsp;&nbsp;')
Line 30: Line 32:
         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) )

Latest revision as of 22:59, 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
    local i=1
    local j=string.len(humanwords)
    while (i <= j) 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=]]')
            i = i + 1
        else
            table.insert(output_string,'&nbsp;&nbsp;')
            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