More actions
Content deleted Content added
No edit summary |
No edit summary Tag: Reverted |
||
Line 2: | Line 2: | ||
function p.increaseHeadings(frame) |
function p.increaseHeadings(frame) |
||
-- Get the |
-- Get the page name from the argument |
||
local |
local pageName = frame.args[1] |
||
if not pageName or pageName == "" then |
|||
⚫ | |||
return "Error: No page name provided." |
|||
⚫ | |||
-- Fetch the raw content of the page |
|||
local title = mw.title.new(pageName) |
|||
if not title or not title.exists then |
|||
return "Error: Page does not exist." |
|||
⚫ | |||
local content = title:getContent() |
|||
if not content then |
|||
return "Error: Could not fetch page content." |
|||
end |
|||
-- Replace headings with custom wrapping or increase levels |
-- Replace headings with custom wrapping or increase levels |
||
content = mw.ustring.gsub(content, '^(=+)(.-)(=+)$', function(eq1, text, eq2) |
|||
if #eq1 == #eq2 then |
if #eq1 == #eq2 then |
||
return '{{' .. text .. '}}' -- Replace for testing |
|||
return newLevel .. text .. newLevel |
|||
else |
else |
||
return eq1 .. text .. eq2 |
return eq1 .. text .. eq2 |
||
end |
end |
||
end) |
end) |
||
⚫ | |||
return |
return content |
||
end |
end |
||
Revision as of 01:40, 26 December 2024
Documentation for this module may be created at Module:IncreaseHeadings/doc
local p = {}
function p.increaseHeadings(frame)
-- Get the page name from the argument
local pageName = frame.args[1]
if not pageName or pageName == "" then
return "Error: No page name provided."
end
-- Fetch the raw content of the page
local title = mw.title.new(pageName)
if not title or not title.exists then
return "Error: Page does not exist."
end
local content = title:getContent()
if not content then
return "Error: Could not fetch page content."
end
-- Replace headings with custom wrapping or increase levels
content = mw.ustring.gsub(content, '^(=+)(.-)(=+)$', function(eq1, text, eq2)
if #eq1 == #eq2 then
return '{{' .. text .. '}}' -- Replace for testing
else
return eq1 .. text .. eq2
end
end)
return content
end
return p