More actions
Content deleted Content added
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
function p. |
function p.adjustHeadings(frame) |
||
⚫ | |||
-- Get the raw wikitext of the transcluded page |
|||
return p.incrementHeadings(content) |
|||
⚫ | |||
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 |
|||
⚫ | |||
if headingLevel < 6 then -- MediaWiki supports up to level 6 headings |
|||
local newEquals = string.rep("=", headingLevel + 1) |
|||
⚫ | |||
else |
else |
||
return |
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