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

Module:IncreaseHeadings: Difference between revisions

From Teriock
Content deleted Content added
No edit summary
No edit summary
Line 1: Line 1:
local p = {}
local p = {}


function p.increaseHeadings(frame)
function p.adjustHeadings(frame)
local content = frame:getParent().args[1] or ""
-- Get the raw wikitext of the transcluded page
return p.incrementHeadings(content)
local pageContent = frame:expandTemplate{ title = frame.args[1] } or ''
end

-- Replace headings with custom wrapping or increase levels
function p.incrementHeadings(content)
pageContent = mw.ustring.gsub(pageContent, '^(=+)(.-)(=+)$', function(eq1, text, eq2)
-- Increment headings
if #eq1 == #eq2 then
local incrementedContent = content:gsub("(=%s*)(.-)(%s*=)", function(leadingEquals, text, trailingEquals)
local newLevel = eq1 .. '='
local headingLevel = #leadingEquals
return '(((' .. newLevel .. text .. newLevel .. ')))'
if headingLevel < 6 then -- MediaWiki supports up to level 6 headings
local newEquals = string.rep("=", headingLevel + 1)
return newEquals .. text .. newEquals
else
else
return eq1 .. text .. eq2
return leadingEquals .. text .. trailingEquals
end
end
end)
end)
return incrementedContent
return pageContent
end
end



Revision as of 01:49, 26 December 2024

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

local p = {}

function p.adjustHeadings(frame)
    local content = frame:getParent().args[1] or ""
    return p.incrementHeadings(content)
end

function p.incrementHeadings(content)
    -- Increment headings
    local incrementedContent = content:gsub("(=%s*)(.-)(%s*=)", function(leadingEquals, text, trailingEquals)
        local headingLevel = #leadingEquals
        if headingLevel < 6 then -- MediaWiki supports up to level 6 headings
            local newEquals = string.rep("=", headingLevel + 1)
            return newEquals .. text .. newEquals
        else
            return leadingEquals .. text .. trailingEquals
        end
    end)
    return incrementedContent
end

return p