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

Aucun résumé des modifications
Aucun résumé des modifications
 
(2 versions intermédiaires par le même utilisateur non affichées)
Ligne 17 : Ligne 17 :
end
end
return data.json
return data.json
end
-- Fonction utilitaire de formatage
local function htmlDecode(str)
if not str then return nil end
return str
:gsub(":", ":")
:gsub("[", "[")
:gsub("]", "]")
:gsub(""", '"')
:gsub("&", "&")
end
end


Ligne 42 : Ligne 53 :
function p.alternateLink(frame)
function p.alternateLink(frame)
local data = fetchZoteroData(frame.args[1])
local data = fetchZoteroData(frame.args[1])
if not data or not data.links or not data.links.alternate then return "" end
if data and data.links and data.links.alternate and data.links.alternate.href then
return mw.text.nowiki(data.links.alternate.href or "")
return htmlDecode(data.links.alternate.href)
end
return ""
end
end


Ligne 91 : Ligne 104 :


function p.url(frame)
function p.url(frame)
return getField(frame, { "data", "url" })
local data = fetchZoteroData(frame.args[1])
if data and data.data and data.data.url then
return htmlDecode(data.data.url)
end
return ""
end
end


Ligne 230 : Ligne 247 :
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 ""


if noteHtml ~= "" then
-- Étape 1 : supprimer tout sauf les balises autorisées
table.insert(output, mw.text.nowiki(noteHtml))
-- Autorisé : <p>, </p>, <h1>, </h1>, <a href="...">, </a>
local cleaned = rawHtml:gsub('<(.-)>', function(tag)
-- Cas <a href="...">
if tag:match('^a%s+href=') then
return "<" .. tag .. ">"
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)
 
if cleaned ~= "" then
table.insert(output, cleaned)
end
end
if url ~= "" then
if url ~= "" then
table.insert(output, mw.text.nowiki(url))
table.insert(output, url)
end
end
end
end