Modulo:Font to span: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m typo
Aggiunto trattino ai character set per attributi composti, + verifica che nei due style non ci siano ulteriori attributi identici e relativa rimozione da quello esterno.
Riga 3:
--funzione di estrazione per utilizzo multiplo
local function extract(x)
face=string.match(x, "face%s*=%s*(%a+)") or string.match(x, 'face%s*=%s*"([%a, -]+)"')
size=string.match(x, 'size%s*=%s*"?([-+]?%d+[pxem%%]*)"?')
color=string.match(x, 'color%s*=%s*"?(rgb%([^)]+%))"?') or string.match(x, 'color%s*=%s*"?(#?%w+)"?')
Riga 14:
--Mette insieme lo style
if d==nil then d="" end
if string.match(d, "[%a -]+[^;]$") then d = d .. ";" end
 
if a~=nil then d=d .. "color:" .. a .. ";" end
Riga 163:
s1=string.match(x[4], 'font%-size:([^;"]+)')
f1=string.match(x[4], 'font%-family:([^;"]+)')
x[4]=string.gsub(string.gsub(string.gsub(x[4], 'font%-family:([^;"]+)', ""), 'font%-size:([^;"]+)', ""), 'color:([^;"]+)', "")
end
--estrazione parametri dal secondo style
Line 169 ⟶ 170:
s2=string.match(y[4], 'font%-size:([^;"]+)')
f2=string.match(y[4], 'font%-family:([^;"]+)')
y[4]=string.gsub(string.gsub(string.gsub(y[4], 'font%-family:([^;"]+)', ""), 'font%-size:([^;"]+)', ""), 'color:([^;"]+)', "")
end
--Parametro univoco, ordine di priorità: style dentro, tag dentro, style fuori, tag fuori
Line 182 ⟶ 184:
--conversione color ed eventuale aggiustamento cancelletto
if c~=nil then c = convert(c, "color") end
--Scorre i due style per trovare parametri uguali
if x[4]~=nil and y[4]~=nil then
--liste di attributi
r= string.gmatch(x[4], "([%a-]+:)")
s= string.gmatch(y[4], "([%a-]+:)")
corr={}; --table vuota di corrispondenze
for i in r do
for j in s do
if i==j then table.insert(corr, i) end --aggiunge il match alle corrispondenze
end
s= string.gmatch(y[4], "([%a-]+:)") --ripristina iteratore per altri giri
end
--elimina le corrispondenze e relativo valore dal tag esterno
for i,v in ipairs(corr) do
x[4]=string.gsub(x[4], v.."[^;]+;*", "");
end
--formatta i due style eliminando spazi e punti e virgola superflui
x[4]=string.gsub(string.gsub(x[4], ";[ ;]+", ";"), "^[ ;]+", "")
y[4]=string.gsub(string.gsub(y[4], ";[ ;]+", ";"), "^[ ;]+", "")
--unisce ciò che rimane dei due style
if string.match(x[4], "[%a -]+[^;]$") then x[4] = x[4] .. ";" end
stile=x[4]..y[4]
elseif x[4]~=nil then
stile=string.gsub(string.gsub(x[4], ";[ ;]+", ";"), "^[ ;]+", "")
elseif y[4]~=nil then
stile=string.gsub(string.gsub(y[4], ";[ ;]+", ";"), "^[ ;]+", "")
end
--Ottiene uno style singolo con tutti e soli i parametri da mantenere
sty=build(c,s,f,stile)
--Seconda uscita di sicurezza