Module:Citation/CS1: Difference between revisions
Jump to navigation
Jump to search
Infobox>Uncle G Substituted for currently missing function. |
Infobox>Uncle G Tweaked two functions. |
||
Line 4: | Line 4: | ||
-- This can be removed when mw.text.tag appears. | -- This can be removed when mw.text.tag appears. | ||
function tag(t) | function p.tag(frame, t) | ||
local name = t.name or "!--" | local name = t.name or "!--" | ||
local content = t.contents or "" | local content = t.contents or "" | ||
local params = "" | local params = "" | ||
for n,v in pairs(t.params) do | for n,v in pairs(t.params) do | ||
params = params .. " " .. n .. "=" .. v | params = params .. "|" .. n .. "=" .. v | ||
end | end | ||
return " | return frame:preprocess("{{#tag:" .. name .. "|" .. content .. params .. ">") | ||
end | end | ||
Line 32: | Line 32: | ||
local P4 = frame.args[4] or "" | local P4 = frame.args[4] or "" | ||
if ( frame.args[4] ~= nil ) then | if ( frame.args[4] ~= nil ) then | ||
P3 = " & " .. P3 | P3 = " & " .. P3 | ||
P2 = " & " .. P2 | |||
elseif ( frame.args[3] ~= nil ) then | |||
P2 = " & " .. P2 | P2 = " & " .. P2 | ||
end | end | ||
Line 82: | Line 79: | ||
local args = { name = anchorid(pframe) } | local args = { name = anchorid(pframe) } | ||
-- return mw.text.tag{name = "ref", contents = content, params = args} | -- return mw.text.tag{name = "ref", contents = content, params = args} | ||
return tag{name = "ref", contents = content, params = args} | return tag(frame, {name = "ref", contents = content, params = args}) | ||
end | end | ||
return p | return p |
Revision as of 12:35, 25 August 2012
Documentation for this module may be created at Module:Citation/CS1/doc
--require "mw.text"
local p = {}
-- This can be removed when mw.text.tag appears.
function p.tag(frame, t)
local name = t.name or "!--"
local content = t.contents or ""
local params = ""
for n,v in pairs(t.params) do
params = params .. "|" .. n .. "=" .. v
end
return frame:preprocess("{{#tag:" .. name .. "|" .. content .. params .. ">")
end
function anchorid(frame)
local P1 = frame.args[1] or ""
local P2 = frame.args[2] or ""
local P3 = frame.args[3] or ""
local P4 = frame.args[4] or ""
local P5 = frame.args[5] or ""
return "CITEREF" .. P1 .. P2 .. P3 .. P4 .. P5
end
function name(frame)
local P1 = frame.args[1] or ""
if ( frame.args[5] ~= nil) then
return P1 .. " et al."
else
local P2 = frame.args[2] or ""
local P3 = frame.args[3] or ""
local P4 = frame.args[4] or ""
if ( frame.args[4] ~= nil ) then
P3 = " & " .. P3
P2 = " & " .. P2
elseif ( frame.args[3] ~= nil ) then
P2 = " & " .. P2
end
return P1 .. P2 .. P3 .. P4
end
end
function crossref(frame)
local LB = frame.BracketLeft or ""
local RB = frame.BracketRightt or ""
local anchor = frame.ref or frame.Ref or anchorid(frame)
local text = name(frame)
local loc = frame.loc or ""
local page = frame.p or frame.page or nil
local pages = frame.pp or frame.pages or nil
if ( page ~= nil ) then
local pagesep = frame.PageSep or ""
text = text .. pagesep .. page
end
if ( pages ~= nil ) then
local pagessep = frame.PagesSep or ""
text = text .. pagessep .. pages
end
local ps = frame.Postscript or ""
return LB .. "[[#" .. anchor .. "|" .. text .. "]]" .. RB .. ps
end
-- This is used by templates such as {{SfnRef}} to create the (encoded) anchor name for a Harvard cross-reference hyperlink.
function p.SFNID(frame)
local pframe = frame:getParent()
return anchorid(pframe)
end
-- This is used by templates such as {{Harvard citation}} to create the Harvard cross-reference text.
function p.Harvard(frame)
local pframe = frame:getParent()
return crossref(pframe)
end
-- This is used by templates such as {{sfn}} to create the entire cross-reference.
function p.sfn(frame)
local pframe = frame:getParent()
local content = crossref(pframe)
local args = { name = anchorid(pframe) }
-- return mw.text.tag{name = "ref", contents = content, params = args}
return tag(frame, {name = "ref", contents = content, params = args})
end
return p