Module:CopyEmbeddedStories: Difference between revisions
From Seven Sages of Rome
(Created page with "-- Module:CopyTemplates local p = {} -- Helper function to extract all EmbeddedStory templates from text local function extractEmbeddedStories(text) local stories = {} -- Match all EmbeddedStory templates for story in mw.ustring.gmatch(text, "{{EmbeddedStory.-}}") do table.insert(stories, story) end return stories end -- Helper function to append templates to a page local function appendToPage(title, templates) local page = mw.title.new(...") |
No edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
-- | -- Function to fetch EmbeddedStory templates from a given page | ||
function p.fetchEmbeddedStories(frame) | |||
local | local pageTitle = frame.args["sourcePage"] | ||
if not pageTitle then | |||
return "Error: No source page specified." | |||
end | end | ||
-- Get the wikitext content of the source page | |||
local content = mw.title.new(pageTitle):getContent() | |||
if not content then | |||
return "Error: Source page not found or empty." | |||
local | |||
if not | |||
return "Error: | |||
end | end | ||
-- Find all EmbeddedStory templates | |||
local templates = {} | |||
for embeddedStory in content:gmatch("{{EmbeddedStory.-}}") do | |||
table.insert(templates, embeddedStory) | |||
-- | |||
local | |||
for | |||
end | end | ||
return | -- Return templates as a single concatenated string | ||
return table.concat(templates, "\n") | |||
end | end | ||
return p | return p |
Latest revision as of 20:17, 13 November 2024
Documentation for this module may be created at Module:CopyEmbeddedStories/doc
local p = {}
-- Function to fetch EmbeddedStory templates from a given page
function p.fetchEmbeddedStories(frame)
local pageTitle = frame.args["sourcePage"]
if not pageTitle then
return "Error: No source page specified."
end
-- Get the wikitext content of the source page
local content = mw.title.new(pageTitle):getContent()
if not content then
return "Error: Source page not found or empty."
end
-- Find all EmbeddedStory templates
local templates = {}
for embeddedStory in content:gmatch("{{EmbeddedStory.-}}") do
table.insert(templates, embeddedStory)
end
-- Return templates as a single concatenated string
return table.concat(templates, "\n")
end
return p