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

Module:HeaderIncrementer

From Teriock
Revision as of 02:51, 26 December 2024 by Gpe (talk | contribs)

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

local p = {}

function p.incrementHeadings(frame)
    -- Get the content and recursion depth
    local content = frame.args.content or "No content provided."
    local depth = tonumber(frame.args.depth) or 1
    local maxDepth = 3 -- Set a reasonable recursion limit

    -- Check if recursion limit is reached
    if depth > maxDepth then
        return "Recursion limit reached."
    end

    -- Increment heading levels
    local incrementedContent = content:gsub("(=%s*)(.-)(%s*=)", function(leadingEquals, text, trailingEquals)
        local headingLevel = #leadingEquals -- Count the number of `=` signs
        if headingLevel < 6 then
            local newEquals = string.rep("=", headingLevel + 1)
            return newEquals .. text .. newEquals
        else
            return leadingEquals .. text .. trailingEquals
        end
    end)

    -- Add a marker to indicate processing is complete
    return "{{H|content=" .. incrementedContent .. "|processed=yes}}"
end

return p