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

De Wikiromandie.org
Aller à la navigation Aller à la recherche
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 10 : Ligne 10 :


     local function htmlEncode(s)
     local function htmlEncode(s)
         return s:gsub('&', '&')
         return s:gsub('\194\160', ' ')          -- Normalize non-breaking spaces
                 :gsub('"', '"')
                :gsub('&', '&')             -- Escape &
                 :gsub('<', '&lt;')
                 :gsub('"', '&quot;')             -- Escape "
                 :gsub('>', '&gt;')
                 :gsub('<', '&lt;')               -- Escape <
                 :gsub('>', '&gt;')               -- Escape >
                :gsub('\r?\n', ' ')              -- Collapse multi-line queries onto one line
                :gsub('%s+', ' ')                -- Clean up multiple consecutive spaces
     end
     end


     return '<div class="wikidata-sparql-table"'
     return string.format(
        .. ' data-sparql="' .. htmlEncode(sparql) .. '"'
        '<div class="wikidata-sparql-table" data-sparql="%s" data-title="%s"></div>',
        .. ' data-title="'  .. htmlEncode(title)  .. '">'
        htmlEncode(sparql),
        .. '</div>'
        htmlEncode(title)
    )
end
end


return p
return p

Version du 21 septembre 2026 à 12:34

La documentation pour ce module peut être créée à Module:WikidataTable/doc

local p = {}

function p.render(frame)
    local sparql = frame.args.sparql or ""
    local title  = frame.args.title  or ""

    if sparql == "" then
        return "⚠️ No SPARQL query provided."
    end

    local function htmlEncode(s)
        return s:gsub('\194\160', ' ')           -- Normalize non-breaking spaces
                :gsub('&', '&amp;')              -- Escape &
                :gsub('"', '&quot;')             -- Escape "
                :gsub('<', '&lt;')               -- Escape <
                :gsub('>', '&gt;')               -- Escape >
                :gsub('\r?\n', ' ')              -- Collapse multi-line queries onto one line
                :gsub('%s+', ' ')                -- Clean up multiple consecutive spaces
    end

    return string.format(
        '<div class="wikidata-sparql-table" data-sparql="%s" data-title="%s"></div>',
        htmlEncode(sparql),
        htmlEncode(title)
    )
end

return p