Module:ColorParse: Difference between revisions

Jump to navigation Jump to search
6 bytes removed ,  15:00, 14 November 2019
newline charas are turned into actual newlines regardless of parse type
imported>Teamtotobot
((by SublimeText.Mediawiker))
(newline charas are turned into actual newlines regardless of parse type)
Line 7: Line 7:


function normalize(string, type)
function normalize(string, type)
   type = type or ''
   type = type or 'xml'
   local b = string.gsub(string,"(~J211)", "")
   local b = string.gsub(string,"(~J211)", "")
   b = b:gsub("(%*)", "*")
   b = b:gsub("(%*)", "*")
   if type == '' then
   if type == 'xml' then
     b = string.gsub(b,"([{}])", "")
     b = string.gsub(b,"([{}])", "")
  elseif type == 'notxml' then
    b = string.gsub(b,"(\\n)","\n")
   end
   end
  b = string.gsub(b,"(\\n)","\n")
   return b
   return b
end
end
Line 28: Line 27:


function p.parse(frame, regextype)
function p.parse(frame, regextype)
   args = frame.args or {[1] = frame}
   args = frame.args or mw.getCurrentFrame().args
   regextype = regextype
   regextype = regextype
   if regextype == nil then
   if regextype == nil then
     if args[1]:match('&') ~= nil then
     if args[1]:match('&') ~= nil then
       regextype = ''
       regextype = 'xml'
     else
     else
       regextype = 'notxml'
       regextype = 'notxml'
Line 60: Line 59:


function p.main(frame)
function p.main(frame)
local isnotxml = nil
 
local parsetype = 'xml'
   local unbolded = false
   local unbolded = false
   local tildes = false
   local tildes = false
Line 67: Line 67:
  for _, arg in ipairs(args) do
  for _, arg in ipairs(args) do
     if arg == 'notxml' then
     if arg == 'notxml' then
         isnotxml = 'notxml'
         parsetype = 'notxml'
       elseif arg == 'unbolded' then
       elseif arg == 'unbolded' then
         unbolded = true
         unbolded = true
Line 77: Line 77:
   end
   end
      
      
   local returntext = p.parse(text, isnotxml)
   local returntext = p.parse(text, parsetype)
   if tildes  == true then  
   if tildes  == true then  
     returntext = p.linebreaks(returntext)
     returntext = p.linebreaks(returntext)

Navigation menu