Jump to content
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
No edit summary
No edit summary
Line 1: Line 1:
local p = {}
local p = {}


function p.increaseHeadings(frame)
function p.adjustHeadings(frame)
    -- Get the raw wikitext of the transcluded page
     local content = frame:getParent().args[1] or ""
     local pageContent = frame:expandTemplate{ title = frame.args[1] } or ''
     return p.incrementHeadings(content)
      
end
     -- Replace headings with custom wrapping or increase levels
 
     pageContent = mw.ustring.gsub(pageContent, '^(=+)(.-)(=+)$', function(eq1, text, eq2)
function p.incrementHeadings(content)
         if #eq1 == #eq2 then
     -- Increment headings
             local newLevel = eq1 .. '='
     local incrementedContent = content:gsub("(=%s*)(.-)(%s*=)", function(leadingEquals, text, trailingEquals)
             return '(((' .. newLevel .. text .. newLevel .. ')))'
         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
         else
             return eq1 .. text .. eq2
             return leadingEquals .. text .. trailingEquals
         end
         end
     end)
     end)
   
     return incrementedContent
     return pageContent
end
end


return p
return p

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