Module:ColorParse: Difference between revisions

Jump to navigation Jump to search
(fixed bug with colored spaces not showing up properly)
(put space back in span style)
Line 46: Line 46:
   regextype = regextype or ''
   regextype = regextype or ''
   --[Determine regex type]
   --[Determine regex type]
   local regex = "(&)(%w)(%s*)([^&\n]*)"
   local regex = "(&)(%w)([^&\n]*)"
   if regextype == 'notxml' then
   if regextype == 'notxml' then
     regex = "(&)(%w)(%s*)([^&\n]*)"
     regex = "(&)(%w)([^&\n]*)"
   end
   end


   local b = normalize(frame.args[1],regextype)
   local b = normalize(frame.args[1],regextype)
   local a = string.gsub(b, regex, function(_,color,space1,text)
   local a = string.gsub(b, regex, function(_,color,text)
        space1 = space1 or ""
      if text ~= nil or text ~= "" then
        if text ~= nil and text ~= '' then
           local hexcolor = luatable[color]
           local hexcolor = luatable[color]
           if hexcolor == nil then
           if hexcolor == nil then
Line 60: Line 59:
           end
           end
           text = text or ""
           text = text or ""
           return space1 .. "<span style=\"color: " .. hexcolor .. ";\">"  .. text .. "</span>"
           return "<span style=\"color: " .. hexcolor .. ";\">"  .. text .. "</span>"
        else  
      else
           return space1
           return ""
        end
      end
   end)
   end)
return a
return a