Module:Hatnote: Difference between revisions
Content added Content deleted
m (1 revision imported: for franchise page) |
(parse pages for section-only links as nil - this prevents section-only links that have an italicized page parameter from having empty <i></i> tags) |
||
Line 130: | Line 130: | ||
-- with colons if necessary, and links to sections are detected and displayed |
-- with colons if necessary, and links to sections are detected and displayed |
||
-- with " § " as a separator rather than the standard MediaWiki "#". Used in |
-- with " § " as a separator rather than the standard MediaWiki "#". Used in |
||
-- the {{format |
-- the {{format link}} template. |
||
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
||
Line 141: | Line 141: | ||
return p.makeWikitextError( |
return p.makeWikitextError( |
||
'no link specified', |
'no link specified', |
||
'Template:Format |
'Template:Format link#Errors', |
||
args.category |
args.category |
||
) |
) |
||
Line 180: | Line 180: | ||
local prePipe, display = link:match('^(.-)|(.*)$') |
local prePipe, display = link:match('^(.-)|(.*)$') |
||
link = prePipe or link |
link = prePipe or link |
||
-- Find the page, if it exists. |
|||
-- For links like [[#Bar]], the page will be nil. |
|||
local preHash, postHash = link:match('^(.-)#(.*)$') |
|||
local page |
|||
if not preHash then |
|||
-- We have a link like [[Foo]]. |
|||
⚫ | |||
elseif preHash ~= '' then |
|||
-- We have a link like [[Foo#Bar]]. |
|||
page = preHash |
|||
end |
|||
-- Find the section, if it exists. |
-- Find the section, if it exists. |
||
local |
local section |
||
if postHash and postHash ~= '' then |
|||
⚫ | |||
section = postHash |
|||
end |
|||
return { |
return { |
||
Line 231: | Line 245: | ||
local page = maybeItalicize(parsed.page, options.italicizePage) |
local page = maybeItalicize(parsed.page, options.italicizePage) |
||
local section = maybeItalicize(parsed.section, options.italicizeSection) |
local section = maybeItalicize(parsed.section, options.italicizeSection) |
||
if |
if not page then |
||
display = string.format('§ %s', section) |
|||
elseif section then |
|||
display = string.format('%s § %s', page, section) |
display = string.format('%s § %s', page, section) |
||
else |
else |