More actions
Skycrafter (talk | contribs) 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..." |
Skycrafter (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
-- | -- Module:Deformat | ||
-- 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 | |||
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 | 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