More actions
Content deleted Content added
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local p = {} |
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) |
function p.transclude(frame) |
||
-- Get |
-- Get and preprocess the input |
||
local |
local raw_input = frame.args[1] or '' |
||
local |
local processed_input = frame:preprocess(raw_input) |
||
-- |
-- Debug output |
||
return string.format( |
|||
for line in input:gmatch('[^\r\n]+') do |
|||
"Raw input:\n<pre>%s</pre>\n\nProcessed input:\n<pre>%s</pre>", |
|||
line = trim(line) |
|||
raw_input, |
|||
processed_input |
|||
-- Only add the transclusion brackets if they're not already present |
|||
⚫ | |||
if not line:match('^{{.*}}$') then |
|||
line = string.format('{{%s}}', line) |
|||
end |
|||
table.insert(output, line) |
|||
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 |
end |
||
Revision as of 11:47, 14 January 2025
Documentation for this module may be created at Module:Transclude/doc
local p = {}
function p.transclude(frame)
-- Get and preprocess the input
local raw_input = frame.args[1] or ''
local processed_input = frame:preprocess(raw_input)
-- Debug output
return string.format(
"Raw input:\n<pre>%s</pre>\n\nProcessed input:\n<pre>%s</pre>",
raw_input,
processed_input
)
end
return p