« Module:TableColors » : différence entre les versions
De Nefald
Autres actions
Auto détection tableau / texte en ligne |
amélioration |
||
Ligne 47 : | Ligne 47 : | ||
end | end | ||
-- Fonction principale unifiée avec auto-détection AMÉLIORÉE | |||
-- Fonction principale unifiée avec auto-détection | |||
function p.cell(frame) | function p.cell(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
Ligne 83 : | Ligne 64 : | ||
local color = colors[colorName] or colors.light | local color = colors[colorName] or colors.light | ||
-- DÉTECTION AUTOMATIQUE | -- DÉTECTION AUTOMATIQUE STRICTE | ||
local useTableMode = false | local useTableMode = false | ||
local trimmedContent = mw.text.trim(content) | |||
-- Indicateurs de contexte TABLEAU | |||
local hasTableSyntax = content:match("%|%|") or content:match("!!") or content:match("%|-") | |||
local startsWithCode = trimmedContent:match("^<code>") | |||
local isShortLabel = mw.ustring.len(trimmedContent) <= 20 and not trimmedContent:match("%s%s") | |||
-- Indicateurs de contexte TEXTE (badge inline) | |||
local hasEmoji = trimmedContent:match("[💡⚠️🔥ℹ️✓✗🎯📌❌✅⭐🎨]") | |||
local hasBoldWithColon = trimmedContent:match("'''[^']+'''%s*:") | |||
local hasLongText = mw.ustring.len(trimmedContent) > 40 | |||
local hasPunctuation = trimmedContent:match("[%.%,%;%!%?]") and mw.ustring.len(trimmedContent) > 15 | |||
-- | -- DÉCISION : MODE TABLEAU si critères stricts | ||
if | if hasTableSyntax or startsWithCode then | ||
useTableMode = true | useTableMode = true | ||
elseif trimmedContent == "" then | |||
elseif | |||
useTableMode = true | useTableMode = true | ||
elseif isShortLabel and not hasEmoji and not hasBoldWithColon then | |||
elseif | |||
useTableMode = true | useTableMode = true | ||
end | |||
-- | -- FORCER MODE TEXTE si indicateurs clairs | ||
if hasEmoji or hasBoldWithColon or hasLongText or hasPunctuation then | |||
useTableMode = | useTableMode = false | ||
end | end | ||
Ligne 120 : | Ligne 110 : | ||
-- MODE TABLEAU | -- MODE TABLEAU | ||
if useTableMode then | if useTableMode then | ||
if | if trimmedContent == "" then | ||
return 'style="' .. cellStyle .. '" | ' | return 'style="' .. cellStyle .. '" | ' | ||
end | end | ||
Ligne 127 : | Ligne 117 : | ||
-- MODE TEXTE (badge) | -- MODE TEXTE (badge) | ||
if | if trimmedContent == "" then | ||
return '' | return '' | ||
end | end | ||
Ligne 154 : | Ligne 144 : | ||
color.fg, | color.fg, | ||
borderColor, | borderColor, | ||
color.label | |||
) | |||
-- Cellule exemple | |||
local cell = string.format( | |||
'style="background-color:%s; color:%s; padding:8px 12px;" | %s', | |||
color.bg, | |||
color.fg, | |||
color.label | color.label | ||
) | ) | ||
table.insert(rows, string.format( | table.insert(rows, string.format( | ||
'|-\n| %s || %s || <code>{{Couleur|%s| | '|-\n| %s || %s || %s || <code>{{Couleur|%s|...}}</code>', | ||
color.label, | color.label, | ||
badge, | badge, | ||
cell, | |||
name | name | ||
)) | )) | ||
end | end | ||
local wikitext = '{| class="wikitable sortable"\n! Nom !! | local wikitext = '{| class="wikitable sortable"\n! Nom !! Badge (texte) !! Cellule (tableau) !! Code\n' | ||
.. table.concat(rows, '\n') | .. table.concat(rows, '\n') | ||
.. '\n|}' | .. '\n|}' |