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
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 not text or text == '' then
        return ''
    end


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


     return deformattedText
     return deformattedText

Revision as of 22:12, 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 not text or text == '' then
        return ''
    end

    local deformattedText = text

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

    return deformattedText
end

return p