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
Created page with "-- Function: Removes dollar-sign based formatting codes from a string. local p = {} function p.run(frame) -- Get the input text from the first argument of the template call. -- Defaults to an empty string if no argument is provided. local text = frame.args[1] or '' -- Pattern: \$(?:(\$)|[0-9a-fA-F]{2,3}|[lh]\[.*?\]|[lh]\[|.) local pattern = '\\$(?:(\\$)|\\[0-9a-fA-F]{2,3}|\\[lh]\\[.*?\\]|\\[lh]\\[|.)' -- Replace every match of the pattern..."
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
-- Function: Removes dollar-sign based formatting codes from a string.
-- Module:Deformat
 
-- Removes dollar-sign based formatting codes from a string.
local p = {}
local p = {}


function p.run(frame)
function p.run(frame)
    -- Get the input text from the first argument of the template call.
    -- Defaults to an empty string if no argument is provided.
     local text = frame.args[1] or ''
     local text = frame.args[1] or ''
    if text == '' then return '' end
    local s = text


     -- Pattern: \$(?:(\$)|[0-9a-fA-F]{2,3}|[lh]\[.*?\]|[lh]\[|.)
     s = mw.ustring.gsub(s, '%$%$', '$')
     local pattern = '\\$(?:(\\$)|\\[0-9a-fA-F]{2,3}|\\[lh]\\[.*?\\]|\\[lh]\\[|.)'
     s = mw.ustring.gsub(s, '%$%x%x%x?', '')
   
    s = mw.ustring.gsub(s, '%$[lh]%[[^%]]*%]', '')
    -- Replace every match of the pattern with an empty string.
    s = mw.ustring.gsub(s, '%$[lh]%[', '')
     local deformattedText = mw.ustring.gsub(text, pattern, '')
     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