« Module:ZoteroItem » : différence entre les versions

Aucun résumé des modifications
Aucun résumé des modifications
Ligne 230 : Ligne 230 :
for _, item in ipairs(data.notes) do
for _, item in ipairs(data.notes) do
if item.data and item.data.itemType == "note" then
if item.data and item.data.itemType == "note" then
local noteHtml = item.data.note or ""
local rawHtml = item.data.note or ""
local url = (item.links and item.links.alternate and item.links.alternate.href) or ""
local url = (item.links and item.links.alternate and item.links.alternate.href) or ""


-- Nettoyage : ne garder que <p> et <h1> (supprime tout le reste)
-- Étape 1 : supprimer tout sauf les balises autorisées
noteHtml = mw.ustring.gsub(noteHtml, "</?(%w+)[^>]*>", function(tag)
-- Autorisé : <p>, </p>, <h1>, </h1>, <a href="...">, </a>
if tag == "p" or tag == "h1" then
local cleaned = rawHtml:gsub('<(.-)>', function(tag)
-- Cas <a href="...">
if tag:match('^a%s+href=') then
return "<" .. tag .. ">"
return "<" .. tag .. ">"
elseif tag == "/p" or tag == "/h1" then
return "</" .. tag:sub(2) .. ">"
else
return ""
end
end
-- Cas </a>, <p>, </p>, <h1>, </h1>
if tag == "/a" or tag == "p" or tag == "/p" or tag == "h1" or tag == "/h1" then
return "<" .. tag .. ">"
end
-- Sinon : supprimer
return ""
end)
end)


if noteHtml ~= "" then
if cleaned ~= "" then
table.insert(output, noteHtml)
table.insert(output, cleaned)
end
end
if url ~= "" then
if url ~= "" then