Modul:Redirect hatnote: Unterschied zwischen den Versionen
(add kerning for redir titles beginning or ending with apostrophes or quotation marks, as at Neighbourhood and Kurtis Blow) |
(Updated from sandbox: Rewrote p._quote to use mw.html, divided functions into helper functions and main functions, and tweaked getTitle) |
||
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 | return success and titleObj or nil | ||
end | |||
function p._quote(title) | |||
--Wraps titles in quotation marks. If the title starts/ends with a quotation | |||
--mark, kerns that side as with {{-'}} | |||
local quotationMarks = { | |||
["'"]=true, ['"']=true, ['“']=true, ["‘"]=true, ['”']=true, ["’"]=true | |||
} | |||
local quoteLeft, quoteRight = -- Test if start/end are quotation marks | |||
quotationMarks[string.sub(title, 1, 1)], | |||
quotationMarks[string.sub(title, -1, -1)] | |||
if quoteLeft or quoteRight then | |||
title = mw.html.create("span"):wikitext(title) | |||
end | end | ||
if quoteLeft then title:css("padding-left", "0.15em") end | |||
if quoteRight then title:css("padding-right", "0.15em") end | |||
return '"' .. tostring(title) .. '"' | |||
end | end | ||
-------------------------------------------------------------------------------- | |||
-- Main functions | |||
-------------------------------------------------------------------------------- | |||
function p.redirect(frame) | function p.redirect(frame) | ||
Zeile 119: | Zeile 141: | ||
return mHatnote._hatnote(text, mhOptions) .. category | return mHatnote._hatnote(text, mhOptions) .. category | ||
end | end | ||
return p | return p |