Module:Get short description

From English Wikipedia @ Freddythechick

This is the current revision of this page, as edited by imported>Qwerfjkl at 19:55, 8 February 2023 ([Factotum]). The present address (URL) is a permanent link to this version.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

local p = {}

local function getContent(title)
	local success, titleObj = pcall(mw.title.new, title)
	if not success then return nil end
	return titleObj:getContent()
end

function p.main(frame, title)
	local title = frame.args[1]
    local wikitext = getContent(title)
	if wikitext == nil then return "" end
	wikitext = frame:preprocess(wikitext)
    local startIndex, endIndex = string.find(wikitext, "<div class=\"shortdescription nomobile noexcerpt noprint searchaux\" style=\"display:none\">")
    if startIndex == nil then
        return nil
    end
    local descriptionStart = endIndex + 1
    local descriptionEnd = string.find(wikitext, "</div>", descriptionStart)
    if descriptionEnd == nil then
        return nil
    end
    return string.sub(wikitext, descriptionStart, descriptionEnd - 1)
end

return p