Module:Hatnote: Difference between revisions
Jump to navigation
Jump to search
trim colons in findNamespaceId by default
>Mr. Stradivarius (split main, see also, further and details out into their own templates, make formatLink available from #invoke, make other helper functions available from other Lua modules, and add type checks) |
>Mr. Stradivarius (trim colons in findNamespaceId by default) |
||
Line 31: | Line 31: | ||
function p._findNamespaceId(link, removeColon) | function p._findNamespaceId(link, removeColon) | ||
-- Finds the namespace id (namespace number) of a link or a pagename. This | -- Finds the namespace id (namespace number) of a link or a pagename. This | ||
-- function will not work if the link is enclosed in double brackets. | -- function will not work if the link is enclosed in double brackets. Colons | ||
-- | -- are trimmed from the start of the link by default. To skip colon | ||
-- | -- trimming, set the removeColon parameter to true. | ||
checkType('_findNamespaceId', 1, link, 'string') | checkType('_findNamespaceId', 1, link, 'string') | ||
checkType('_findNamespaceId', 2, removeColon, 'boolean', true) | checkType('_findNamespaceId', 2, removeColon, 'boolean', true) | ||
if removeColon then | if removeColon ~= false then | ||
link = removeInitialColon(link) | link = removeInitialColon(link) | ||
end | end | ||
Line 104: | Line 104: | ||
checkType('_formatLink', 2, display, 'string', true) | checkType('_formatLink', 2, display, 'string', true) | ||
link = removeInitialColon(link) | link = removeInitialColon(link) | ||
local namespace = p._findNamespaceId(link) | local namespace = p._findNamespaceId(link, false) | ||
local colon | local colon | ||
if namespace == 6 or namespace == 14 then | if namespace == 6 or namespace == 14 then |