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 |
||
(One intermediate revision by the same user not shown) | |||
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 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 | 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