Module:Redirect hatnote: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content added Content deleted
(Updated from sandbox: Rewrote p._quote to use mw.html, divided functions into helper functions and main functions, and tweaked getTitle) |
(Updated from sandbox: Migrated p._quote to Module:Hatnote) |
||
Line 22: | Line 22: | ||
local success, titleObj = pcall(mw.title.new, ...) |
local success, titleObj = pcall(mw.title.new, ...) |
||
return success and titleObj or nil |
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 |
|||
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 |
||
Line 81: | Line 64: | ||
local formattedRedirect = {} |
local formattedRedirect = {} |
||
for k,v in pairs(redirect) do |
for k,v in pairs(redirect) do |
||
formattedRedirect[k] = |
formattedRedirect[k] = mHatnote.quote(v) |
||
end |
end |
||
local text = { |
local text = { |