Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Deformat: Difference between revisions

From Trackmania Wiki
No edit summary
No edit summary
 
Line 1: Line 1:
-- Module:Deformat
-- Module:Deformat
-- Removes dollar-sign based formatting codes from a string.
-- Removes dollar-sign based formatting codes from a string.
local p = {}
local p = {}


function p.run(frame)
function p.run(frame)
     local text = frame.args[1] or ''
     local text = frame.args[1] or ''
     if not text or text == '' then
     if text == '' then return '' end
        return ''
    end


     local deformattedText = text
     local s = text


     deformattedText = mw.ustring.gsub(deformattedText, '%$%$', '$')
     s = mw.ustring.gsub(s, '%$%$', '$')
     deformattedText = mw.ustring.gsub(deformattedText, '%$[lh]%[.-%]', '')
     s = mw.ustring.gsub(s, '%$%x%x%x?', '')
     deformattedText = mw.ustring.gsub(deformattedText, '%$%x%x%x?', '')
     s = mw.ustring.gsub(s, '%$[lh]%[[^%]]*%]', '')
     deformattedText = mw.ustring.gsub(deformattedText, '%$[lh]%[', '')
     s = mw.ustring.gsub(s, '%$[lh]%[', '')
     deformattedText = mw.ustring.gsub(deformattedText, '%$..', '')
     s = mw.ustring.gsub(s, '%$.', '')


     return deformattedText
     return s
end
end


return p
return p

Latest revision as of 22:27, 20 August 2025

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

-- Module:Deformat
-- Removes dollar-sign based formatting codes from a string.
local p = {}

function p.run(frame)
    local text = frame.args[1] or ''
    if text == '' then return '' end

    local s = text

    s = mw.ustring.gsub(s, '%$%$', '$')
    s = mw.ustring.gsub(s, '%$%x%x%x?', '')
    s = mw.ustring.gsub(s, '%$[lh]%[[^%]]*%]', '')
    s = mw.ustring.gsub(s, '%$[lh]%[', '')
    s = mw.ustring.gsub(s, '%$.', '')

    return s
end

return p