More actions
Content deleted Content added
No edit summary |
No edit summary |
||
Line 8: | Line 8: | ||
-- Main function to transclude pages |
-- Main function to transclude pages |
||
function p.transclude(frame) |
function p.transclude(frame) |
||
-- Get the raw input |
|||
local input = frame.args[1] or '' |
local input = frame.args[1] or '' |
||
⚫ | |||
-- Remove <DynamicPageList> tags if present |
|||
-- Handle both newline-separated and space-separated inputs |
|||
input = input:gsub('<DynamicPageList>.*</DynamicPageList>', function(dpl) |
|||
local pages = {} |
|||
-- Extract just the results, removing the DPL configuration |
|||
-- First split by newlines |
|||
return frame:preprocess(dpl) |
|||
for line in input:gmatch('[^\r\n]+') do |
|||
⚫ | |||
-- Then split each line by spaces |
|||
for page in line:gmatch('%S+') do |
|||
⚫ | |||
table.insert(pages, page) |
|||
end |
|||
⚫ | |||
-- Split input by any whitespace (newlines or spaces) |
|||
-- Process each page |
|||
for |
for page in mw.text.split(input, '%s+', true) do |
||
page = trim(page) |
page = trim(page) |
||
if page ~= '' then |
if page ~= '' then |
Revision as of 11:45, 14 January 2025
Documentation for this module may be created at Module:Transclude/doc
local p = {}
-- Helper function to trim whitespace from a string
local function trim(s)
return s:match('^%s*(.-)%s*$')
end
-- Main function to transclude pages
function p.transclude(frame)
-- Get the raw input
local input = frame.args[1] or ''
-- Remove <DynamicPageList> tags if present
input = input:gsub('<DynamicPageList>.*</DynamicPageList>', function(dpl)
-- Extract just the results, removing the DPL configuration
return frame:preprocess(dpl)
end)
local output = {}
-- Split input by any whitespace (newlines or spaces)
for page in mw.text.split(input, '%s+', true) do
page = trim(page)
if page ~= '' then
table.insert(output, string.format('{{%s}}', page))
end
end
-- Join all transclusions with newlines
return table.concat(output, '\n')
end
-- Function to handle direct template calls
function p.transcludeFromTemplate(frame)
local parent = frame:getParent()
return p.transclude(parent)
end
return p