Modul:Redirect hatnote: Unterschied zwischen den Versionen

K
39 Versionen von wpen:Module:Redirect_hatnote importiert
(add kerning for redir titles beginning or ending with apostrophes or quotation marks, as at Neighbourhood and Kurtis Blow)
K (39 Versionen von wpen:Module:Redirect_hatnote importiert)
 
(2 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt)
Zeile 13: Zeile 13:


local p = {}
local p = {}
--------------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------------


local function getTitle(...)
local function getTitle(...)
--Calls mw.title.new and returns either a title object, or nil on error
local success, titleObj = pcall(mw.title.new, ...)
local success, titleObj = pcall(mw.title.new, ...)
if success then
return success and titleObj or nil
return titleObj
else
return nil
end
end
end
--------------------------------------------------------------------------------
-- Main functions
--------------------------------------------------------------------------------


function p.redirect(frame)
function p.redirect(frame)
Zeile 59: Zeile 64:
local formattedRedirect = {}
local formattedRedirect = {}
for k,v in pairs(redirect) do
for k,v in pairs(redirect) do
formattedRedirect[k] = p._quote(v)
formattedRedirect[k] = mHatnote.quote(v)
end
end
local text = {
local text = {
Zeile 119: Zeile 124:


return mHatnote._hatnote(text, mhOptions) .. category
return mHatnote._hatnote(text, mhOptions) .. category
end
function p._quote(title)
local quotationMarks = {["'"]=true, ['"']=true, ['“']=true, ["‘"]=true, ['”']=true, ["’"]=true}
local style = ""
-- If string starts with anything in quotationMarks, kern to same degree {{-'}} does
if quotationMarks[string.sub(title, 1, 1)] then
style = "padding-left:0.15em;"
end
-- Likewise if it ends with any of them
if quotationMarks[string.sub(title, -1, -1)] then
style = style .. "padding-right:0.15em;"
end
return style ~= "" and '"<span style="' .. style .. '">' .. title .. '</span>"' or '"' .. title .. '"'
end
end
   
   
return p
return p