Module:ColorParse: Difference between revisions

16 bytes added ,  23:20, 20 September 2019
fixed bug with colored spaces not showing up properly
(if text is empty return just blank)
(fixed bug with colored spaces not showing up properly)
Line 53: Line 53:
   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,space1,text)
        if text ~=nil and text ~= '' then
        local hexcolor = luatable[color]
        if hexcolor == nil then
          error ("There was no specified color for color code: " .. color)
        end
         space1 = space1 or ""
         space1 = space1 or ""
         text = text or ""
         if text ~= nil and text ~= '' then
        return space1 .. "<span style=\"color: " .. hexcolor .. ";\">"  .. text .. "</span>"
          local hexcolor = luatable[color]
          if hexcolor == nil then
            error ("There was no specified color for color code: " .. color)
          end
          text = text or ""
          return space1 .. "<span style=\"color: " .. hexcolor .. ";\">"  .. text .. "</span>"
         else  
         else  
          return ''
          return space1
         end
         end
   end)
   end)