Module:Hatnote: Difference between revisions
Content deleted Content added
Caleb Cooper (talk | contribs) Created page with "-------------------------------------------------------------------------------- -- Module:Hatnote -- --..." |
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 94:
-- Make the category text.
local category
if not title.isTalkPage
and title.namespace ~= 2 -- Don't categorise userspace
and yesno(addTrackingCategory) ~= false -- Allow opting out
then
category = 'Hatnote templates with errors'
category = string.format(
Line 127 ⟶ 130:
-- with colons if necessary, and links to sections are detected and displayed
-- with " § " as a separator rather than the standard MediaWiki "#". Used in
-- the {{format
--------------------------------------------------------------------------------
Line 138 ⟶ 141:
return p.makeWikitextError(
'no link specified',
'Template:Format
args.category
)
Line 177 ⟶ 180:
local prePipe, display = link:match('^(.-)|(.*)$')
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.
local
if postHash and postHash ~= '' then
▲ page = page or link
section = postHash
end
return {
Line 228 ⟶ 245:
local page = maybeItalicize(parsed.page, options.italicizePage)
local section = maybeItalicize(parsed.section, options.italicizeSection)
if
display = string.format('§ %s', section)
elseif section then
display = string.format('%s § %s', page, section)
else
| |||