Module:Hatnote: Difference between revisions
Jump to navigation
Jump to search
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
>Pppery (Remove stray space per edit request; update comment and error message for move of Template:Format hatnote link to Template:Format link in 2014) |
>Mr. Stradivarius (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 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]]. | |||
page = link | |||
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 not page | if not page then | ||
display = string.format('§ %s', section) | display = string.format('§ %s', section) | ||
elseif section then | elseif section then |