Module:Section link/sandbox: Difference between revisions

Content deleted Content added
add support for display= option
update display title checking
Line 9:
page = page or ''
return string.format('[[%s#%s|%s]]', page, section, display)
end
 
local function normalizeTitle(title)
title = mw.ustring.gsub(title.lower,"_"," ")
title = mw.ustring.gsub(title,"'","")
title = mw.ustring.gsub(title,"%b<>","")
title = mw.ustring.gsub(title,"^:","")
title = mw.ustring.gsub(title,":([^%s])",": %1",1)
return title
end
 
Line 44 ⟶ 53:
page = page or title.prefixedText
if displaytitle then
if mw.ustring.gsubnormalizeTitle(displaytitle,"'","") == mw.ustring.gsubnormalizeTitle(page,"'","") then
display = displaytitle .. ' ' .. display
else
error("Display title does not match page title")string.format(
'Warning: Display title "%s" was ignored since it ' ..
"is not equivalent to the page's actual title.",
displaytitle
), 2)
end
else