Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Lead

From Teriock
Revision as of 20:12, 29 March 2025 by Gpe (talk | contribs) (Created page with "local p = {} function p.lead(frame) local title = frame.args[1] if not title then return "Error: No page title provided." end -- Fetch the raw wikitext of the page local content = mw.title.new(title):getContent() if not content then return "Error: Could not fetch content for page '" .. title .. "'." end -- Find position of the first heading (e.g., '== Something ==') local heading_start = string.find(content, "\n==+[^...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Lead/doc

local p = {}

function p.lead(frame)
    local title = frame.args[1]
    if not title then
        return "Error: No page title provided."
    end

    -- Fetch the raw wikitext of the page
    local content = mw.title.new(title):getContent()
    if not content then
        return "Error: Could not fetch content for page '" .. title .. "'."
    end

    -- Find position of the first heading (e.g., '== Something ==')
    local heading_start = string.find(content, "\n==+[^=]")
    if heading_start then
        -- Extract only up to the heading (excluding it)
        content = string.sub(content, 1, heading_start - 1)
    end

    -- Return the parsed wikitext
    return frame:preprocess(content)
end

return p