Module:WikidataTable

De Wikiromandie.org
Aller à la navigation Aller à la recherche

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('&', '&')              -- Escape &
                :gsub('"', '"')             -- 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