« Module:Dièse couleur web » : différence entre les versions

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
 
0x010D (discussion | contributions)
autre solution : frame:extensionTag('nowiki')
Ligne 6 : Ligne 6 :


     if value:find('#') == 1 then
     if value:find('#') == 1 then
         return '<nowiki />' .. value
         return '&#35;' .. value:sub(2)
     elseif mw.ustring.match(value, '^%x%x%x%x%x%x$') or mw.ustring.match(value, '^%x%x%x$') then
     elseif mw.ustring.match(value, '^%x%x%x%x%x%x$') or mw.ustring.match(value, '^%x%x%x$') then
         return '<nowiki />#' .. value
         return '&#35;' .. value
     else
     else
         return value
         return value

Version du 20 juin 2016 à 05:56

local z = {}

function z.main(frame)

   local value = mw.text.trim(frame.args[1])
   if value:find('#') == 1 then
       return '#' .. value:sub(2)
   elseif mw.ustring.match(value, '^%x%x%x%x%x%x$') or mw.ustring.match(value, '^%x%x%x$') then
       return '#' .. value
   else
       return value
   end

end

return z