Module:Section link: Difference between revisions

implement display= parameter
m>Andy M. Wang
(changing to non-breaking nbsp per lengthy talk discussion with Edokter, SMcCandlish, LLarson, among others about § not wrapping)
m>Ahecht
(implement display= parameter)
Line 11: Line 11:
end
end


function p._main(page, sections, options, title)
local function normalizeTitle(title)
title = mw.ustring.gsub(title,"'","")
title = mw.ustring.gsub(title,'"','')
title = mw.ustring.gsub(title,"%b<>","")
return mw.title.new(title).prefixedText
end
 
function p._main(page, sections, options, title, displaytitle)
-- Validate input.
-- Validate input.
checkType('_main', 1, page, 'string', true)
checkType('_main', 1, page, 'string', true)
Line 43: Line 50:
if isShowingPage then
if isShowingPage then
page = page or title.prefixedText
page = page or title.prefixedText
display = page .. ' ' .. display
if displaytitle then
if normalizeTitle(displaytitle) == normalizeTitle(page) then
display = displaytitle .. ' ' .. display
else
error(string.format(
'Display title "%s" was ignored since it is ' ..
"not equivalent to the page's actual title",
displaytitle
), 0)
end
else
display = page .. ' ' .. display
end
end
end
return makeSectionLink(linkPage, section, display)
return makeSectionLink(linkPage, section, display)
Line 89: Line 108:


-- Sort the arguments.
-- Sort the arguments.
local page
local page, displaytitle
local sections, options = {}, {}
local sections, options = {}, {}
for k, v in pairs(args) do
for k, v in pairs(args) do
Line 98: Line 117:
elseif type(k) == 'number' then
elseif type(k) == 'number' then
sections[k] = v
sections[k] = v
elseif k == 'display' then
displaytitle = v
else
else
options[k] = v
options[k] = v
Line 117: Line 138:
sections = compressArray(sections)
sections = compressArray(sections)


return p._main(page, sections, options)
return p._main(page, sections, options, nil, displaytitle)
end
end


return p
return p
Anonymous user