Jump to content

Wiki/Module:Footnote: Difference between revisions

From WikiGence
Created page with "local p = {} local function makeRef(args) local content = args[1] or '' local name = args.name local group = args.group local ref = args.ref local tag = 'ref' local out = '<' .. tag if name and name ~= '' then out = out .. ' name="' .. name .. '"' end if group and group ~= '' then out = out .. ' group="' .. group .. '"' end out = out .. '>' if ref and ref ~= '' then out = out .. ref elseif content and content ~= '' then out = out .. content end..."
 
No edit summary
Line 1: Line 1:
local p = {}
local p = {}
local function getArgsFromFrame(frame)
-- Prefer parent args (when module is called from a template), otherwise use frame.args
local parent = nil
if frame.getParent then
parent = frame:getParent()
end
if parent and parent.args then
return parent.args
end
-- fallback to frame.args (when module is invoked directly with parameters)
if frame.args then
return frame.args
end
-- ultimate fallback: empty table
return {}
end


local function makeRef(args)
local function makeRef(args)
local content = args[1] or ''
local content = args[1] or ''
local name = args.name
-- some templates pass parameters as strings or tables, handle both
local group = args.group
local name = args.name or args["name"] or ''
local ref = args.ref
local group = args.group or args["group"] or ''
local ref = args.ref or args["ref"] or ''
local tag = 'ref'
local tag = 'ref'


local out = '<' .. tag
local out = '<' .. tag
if name and name ~= '' then
if name ~= '' then
out = out .. ' name="' .. name .. '"'
out = out .. ' name="' .. mw.text.escape(name) .. '"'
end
end
if group and group ~= '' then
if group ~= '' then
out = out .. ' group="' .. group .. '"'
out = out .. ' group="' .. mw.text.escape(group) .. '"'
end
end
out = out .. '>'
out = out .. '>'


if ref and ref ~= '' then
if ref ~= '' then
out = out .. ref
out = out .. ref
elseif content and content ~= '' then
elseif content ~= '' then
out = out .. content
out = out .. content
end
end
Line 28: Line 46:


function p.efn(frame)
function p.efn(frame)
local args = frame:getParent().args
local args = getArgsFromFrame(frame)
return makeRef(args)
return makeRef(args)
end
end


function p.refn(frame)
function p.refn(frame)
local args = frame:getParent().args
local args = getArgsFromFrame(frame)
return makeRef(args)
return makeRef(args)
end
end


function p.notelist(frame)
function p.notelist(frame)
local args = frame:getParent().args
local args = getArgsFromFrame(frame)
local group = args.group or 'note'
local group = args.group or args["group"] or 'note'
local refs = args.refs or ''
local refs = args.refs or args["refs"] or ''
return '<references group="' .. group .. '">' .. refs .. '</references>'
return '<references group="' .. mw.text.escape(group) .. '">' .. refs .. '</references>'
end
end


return p
return p

Revision as of 05:08, 27 October 2025

local p = {}

local function getArgsFromFrame(frame) -- Prefer parent args (when module is called from a template), otherwise use frame.args local parent = nil if frame.getParent then parent = frame:getParent() end if parent and parent.args then return parent.args end -- fallback to frame.args (when module is invoked directly with parameters) if frame.args then return frame.args end -- ultimate fallback: empty table return {} end

local function makeRef(args) local content = args[1] or -- some templates pass parameters as strings or tables, handle both local name = args.name or args["name"] or local group = args.group or args["group"] or local ref = args.ref or args["ref"] or local tag = 'ref'

local out = '<' .. tag if name ~= then out = out .. ' name="' .. mw.text.escape(name) .. '"' end if group ~= then out = out .. ' group="' .. mw.text.escape(group) .. '"' end out = out .. '>'

if ref ~= then out = out .. ref elseif content ~= then out = out .. content end

out = out .. '</' .. tag .. '>' return out end

function p.efn(frame) local args = getArgsFromFrame(frame) return makeRef(args) end

function p.refn(frame) local args = getArgsFromFrame(frame) return makeRef(args) end

function p.notelist(frame) local args = getArgsFromFrame(frame) local group = args.group or args["group"] or 'note' local refs = args.refs or args["refs"] or return '' end

return p