Title: Module:Footnotes - freem
URL Source: https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes
Published Time: Thu, 25 Jun 2026 06:41:32 GMT
Markdown Content:
[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#)
- [x]
* [Home](https://freemwiki.com/wiki/Main_Page)
* [Random](https://freemwiki.com/wiki/Special:Random)
* [Log in](https://freemwiki.com/index.php?title=Special:UserLogin&returnto=Module%3AFootnotes&returntoquery=mobileaction%3Dtoggle_view_mobile%26oldid%3D580068)
* [Settings](https://freemwiki.com/index.php?title=Special:MobileOptions&returnto=Module%3AFootnotes)
* [About freem](https://freemwiki.com/wiki/Freem:About)
* [Disclaimers](https://freemwiki.com/wiki/Freem:General_disclaimer)
[freem](https://freemwiki.com/wiki/Main_Page)
Search
# Module:Footnotes
* [Language](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes "Language")
* [Watch](https://freemwiki.com/index.php?title=Special:UserLogin&returnto=Module%3AFootnotes)
* [Edit](https://freemwiki.com/index.php?title=Module:Footnotes&action=edit)
Revision as of 06:18, 21 October 2025 by [Lukegao](https://freemwiki.com/index.php?title=User:Lukegao&action=edit&redlink=1 "User:Lukegao (page does not exist)")([talk](https://freemwiki.com/index.php?title=User_talk:Lukegao&action=edit&redlink=1 "User talk:Lukegao (page does not exist)") | [contribs](https://freemwiki.com/wiki/Special:Contributions/Lukegao "Special:Contributions/Lukegao"))(1 revision imported)
([diff](https://freemwiki.com/index.php?title=Module:Footnotes&diff=prev&oldid=580068 "Module:Footnotes")) [← Older revision](https://freemwiki.com/index.php?title=Module:Footnotes&direction=prev&oldid=580068 "Module:Footnotes") | Latest revision (diff) | Newer revision → (diff)
_Documentation for this module may be created at [Module:Footnotes/doc](https://freemwiki.com/index.php?title=Module:Footnotes/doc&action=edit&redlink=1 "Module:Footnotes/doc (page does not exist)")_
[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-1)require('strict');[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-2)local getArgs = require (['Module:Arguments'](https://freemwiki.com/wiki/Module:Arguments)).getArgs;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-3)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-4)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-5)--[[--------------------------< A R G S _ D E F A U L T >------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-6)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-7)a table to specify initial values.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-8)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-9)]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-10)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-11)local args_default = {[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-12) group = '',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-13)bracket_left = '',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-14)bracket_right = '',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-15)bracket_year_left = '',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-16)bracket_year_right = '',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-17)postscript = '',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-18)page = '',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-19)pages = '',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-20)location = '',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-21)page_sep = ", p. ",[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-22)pages_sep = ", pp. ",[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-23)ref = '',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-24)template = 'harv',-- if template name not provided in {{#invoke:}} use this[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-25)};[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-26)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-27)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-28)--[[--------------------------< T A R G E T _ C H E C K >------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-29)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-30)look for anchor_id (CITEREF name-list and year or text from |ref=) in anchor_id_list[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-31)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-32)the 'no target' error may be suppressed with |ignore-err=yes when target cannot be found because target is inside[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-33)a template that wraps another template; 'multiple targets' error may not be suppressed[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-34)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-35)]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-36)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-37)local function target_check (anchor_id, args)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-38)local namespace = mw.title.getCurrentTitle().namespace;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-39)local anchor_id_list_module = mw.loadData (['Module:Footnotes/anchor_id_list'](https://freemwiki.com/wiki/Module:Footnotes/anchor_id_list));[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-40)local anchor_id_list = anchor_id_list_module.anchor_id_list;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-41)local article_whitelist = anchor_id_list_module.article_whitelist;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-42)local template_list = anchor_id_list_module.template_list;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-43) local citeref_patterns = anchor_id_list_module.citeref_patterns[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-44)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-45)local whitelist_module = mw.loadData (['Module:Footnotes/whitelist'](https://freemwiki.com/wiki/Module:Footnotes/whitelist));[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-46)local whitelist = whitelist_module.whitelist;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-47)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-48)local tally = anchor_id_list[anchor_id];-- nil when anchor_id not in list; else a tally[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-49)local msg;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-50)local category;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-51)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-52)if not tally then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-53)if args.ignore then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-54)return '';-- if ignore is true then no message, no category[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-55)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-56)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-57)if article_whitelist and article_whitelist[anchor_id] then-- if an article-local whitelist and anchor ID is in it[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-58)return '';-- done[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-59)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-60)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-61)local wl_anchor_id = anchor_id;-- copy to be modified to index into the whitelist[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-62)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-63)if args.year then-- for anchor IDs created by this template (not in |ref=) that have a date[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-64)if args.year:match ('%d%l$') or-- use the date value to determine if we should remove the disambiguator[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-65)args.year:match ('n%.d%.%l$') or[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-66)args.year:match ('nd%l$') then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-67)wl_anchor_id = wl_anchor_id:gsub ('%l$', '');-- remove the disambiguator[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-68)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-69)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-70)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-71)local t_tbl = whitelist[wl_anchor_id];-- get list of templates associated with this anchor ID[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-72)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-73)if t_tbl then-- when anchor ID not whitelisted t_tbl is nil[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-74)for _, t in ipairs (t_tbl) do-- spin through the list of templates associated with this anchor ID[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-75)if template_list[t] then-- if associated template is found in the list of templates in the article[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-76)return '';-- anchor ID is whitlisted and article has matching template so no error[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-77)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-78)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-79)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-80)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-81) for _, pattern in ipairs(citeref_patterns) do -- load patterns for wrapper templates on this page[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-82) if anchor_id:match(pattern) then -- spin through the special patterns and try to match[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-83) return ''[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-84) end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-85) end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-86) [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-87)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-88)msg = 'no target: ' .. anchor_id;-- anchor_id not found[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-89)mw.log(msg)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-90) if namespace == 10 and not args.show then -- do not generate error message in template namespace[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-91) return ''[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-92) end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-93)category = '[[Category:Harv and Sfn no-target errors]]';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-94)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-95)elseif 1 < tally then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-96)msg = 'multiple targets (' .. tally .. '×): ' .. anchor_id;-- more than one anchor_id in this article[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-97)mw.log(msg)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-98) if namespace == 10 and not args.show then -- do not generate error message in template namespace[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-99) return ''[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-100) end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-101)category = 0 == namespace and '[[Category:Harv and Sfn multiple-target errors]]' or '';-- only categorize in article space[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-102)return ' ' .. args.template .. ' error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])' .. category;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-103)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-104)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-105)-- category = 0 == namespace and '[[[Category:Harv and Sfn template errors]]](https://freemwiki.com/wiki/Category:Harv_and_Sfn_template_errors "Category:Harv and Sfn template errors")' or ''; -- only categorize in article space[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-106)category = 0 == namespace and category or '';-- only categorize in article space[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-107)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-108)-- display based on args.show (no display by default)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-109) local display = args.show and 'inline' or 'none'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-110) return msg and ' ' .. args.template .. ' error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])' .. category or '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-111)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-112)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-113)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-114)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-115)--[[--------------------------< I S _ Y E A R >----------------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-116)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-117)evaluates param to see if it is one of these forms with or without lowercase letter disambiguator:[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-118) YYYY[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-119) n.d.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-120) nd [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-121) c. YYYY[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-122) YYYY–YYYY (separator is endash)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-123) YYYY–YY (separator is endash)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-124)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-125)return true when param has a recognized form; false else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-126)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-127)]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-128)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-129)local patterns_date= {[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-130)'^%d%d%d%d?%l?$',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-131)'^n%.d%.%l?$',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-132)'^nd%l?$',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-133)'^c%. %d%d%d%d?%l?$',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-134)'^%d%d%d%d–%d%d%d%d%l?$',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-135)'^%d%d%d%d–%d%d%l?$',[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-136)}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-137)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-138)local function is_year (param, args)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-139)args.year = '';-- used for harv error; [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-140)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-141)for _, pattern in ipairs (patterns_date) do[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-142)if mw.ustring.match (param, pattern) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-143)args.year = param;-- used for harv error; [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-144)return true;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-145)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-146)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-147)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-148)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-149)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-150)--[[--------------------------< C O R E >----------------------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-151)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-152)returns an anchor link (CITEREF) formed from one to four author names, year, and insource location (|p=, |pp=, loc=)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-153)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-154)]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-155)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-156)local function core( args )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-157)local result;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-158)local err_msg = ''[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-159)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-160)if args.P5 ~= '' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-161)if is_year (args.P5, args) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-162)result = table.concat ({args.P1, ' et al. ', args.bracket_year_left, args.P5, args.bracket_year_right});[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-163)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-164)args.P5 = '';-- when P5 not a year don't include in anchor[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-165)result = table.concat ({args.P1, ' et al.'});-- and don't render it[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-166)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-167)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-168)elseif args.P4 ~= '' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-169)if is_year (args.P4, args) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-170)result = table.concat ({args.P1, ', ', args.P2, ' & ', args.P3, ' ', args.bracket_year_left, args.P4, args.bracket_year_right});-- three names and a year[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-171)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-172)result = table.concat ({args.P1, ' et al.'});-- four names[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-173)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-174)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-175)elseif args.P3 ~= '' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-176)if is_year (args.P3, args) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-177)result = table.concat ({args.P1, ' & ', args.P2, ' ', args.bracket_year_left, args.P3, args.bracket_year_right});-- two names and a year[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-178)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-179)result = table.concat ({args.P1, ', ', args.P2, ' ', ' & ', args.P3});-- three names[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-180)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-181)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-182)elseif args.P2 ~= '' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-183)if is_year (args.P2, args) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-184)result = table.concat ({args.P1, ' ', args.bracket_year_left, args.P2, args.bracket_year_right});-- one name and year[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-185)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-186)result = table.concat ({args.P1, ' & ', args.P2});-- two names[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-187)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-188)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-189)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-190)result = args.P1;-- one name[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-191)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-192)-- when author-date result ends with a dot (typically when the last positional parameter holds 'n.d.')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-193)-- and when no in-source location (no |p=, |pp=, or |loc=)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-194)-- and when the first or only character in args.postscript is a dot[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-195)-- remove the author-date result trailing dot[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-196)-- the author-date result trailing dot will be replaced later with the content of args.postscript (usually a dot)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-197)if ('.' == result:sub(-1)) and ('.' == args.postscript:sub(1)) and ('' == args.page) and ('' == args.pages) and ('' == args.location) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-198)result = result:gsub ('%.$', '');[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-199)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-200)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-201)if args.ref ~= 'none' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-202)local anchor_id;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-203)if args.ref ~= '' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-204)anchor_id = mw.uri.anchorEncode (args.ref);[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-205)err_msg = target_check (anchor_id, args);[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-206)result = table.concat ({'[[#', anchor_id, '|', result, ']]'});[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-207)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-208)anchor_id = mw.uri.anchorEncode (table.concat ({'CITEREF', args.P1, args.P2, args.P3, args.P4, args.P5}));[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-209)err_msg = target_check (anchor_id, args);[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-210)result = table.concat ({'[[#', anchor_id, '|', result, ']]'});[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-211)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-212)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-213)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-214)if args.page ~= '' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-215)result = table.concat ({result, args.page_sep, args.page});[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-216)elseif args.pages ~= ''then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-217)result = table.concat ({result, args.pages_sep, args.pages});[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-218)end [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-219)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-220)if args.location ~= '' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-221)result = table.concat ({result, ', ', args.location});[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-222)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-223)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-224)result = table.concat ({args.bracket_left, result, args.bracket_right, args.postscript}):gsub ('%s+', ' ');-- strip redundant spaces[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-225)return result .. err_msg;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-226)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-227)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-228)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-229)--[[--------------------------< H Y P H E N _ T O _ D A S H >--------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-230)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-231)Converts a hyphen to a dash under certain conditions. The hyphen must separate[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-232)like items; unlike items are returned unmodified. These forms are modified:[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-233) letter - letter (A - B)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-234) digit - digit (4-5)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-235) digit separator digit - digit separator digit (4.1-4.5 or 4-1-4-5)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-236) letterdigit - letterdigit (A1-A5) (an optional separator between letter and[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-237) digit is supported – a.1-a.5 or a-1-a-5)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-238) digitletter - digitletter (5a - 5d) (an optional separator between letter and[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-239) digit is supported – 5.a-5.d or 5-a-5-d)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-240)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-241)any other forms are returned unmodified.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-242)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-243)str may be a comma- or semicolon-separated list[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-244)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-245)This code copied from Module:Citation/CS1. The only modification is to require Module:Citation/CS1/Utilities[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-246)so that it has access to the functions is_set() and has_accept_as_written()[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-247)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-248)]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-249)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-250)local function hyphen_to_dash( str )[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-251)local utilities = require (['Module:Citation/CS1/Utilities'](https://freemwiki.com/wiki/Module:Citation/CS1/Utilities));-- only modification so that this function has access to is_set() and has_accept_as_written()[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-252)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-253)if not utilities.is_set (str) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-254)return str;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-255)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-256)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-257)local accept; -- Boolean[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-258)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-259)str = str:gsub ('&[nm]dash;', {['–'] = '–', ['—'] = '—'});-- replace — and – entities with their characters; semicolon mucks up the text.split[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-260)str = str:gsub ('-', '-'); -- replace HTML numeric entity with hyphen character[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-261)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-262)str = str:gsub (' ', ' '); -- replace entity with generic keyboard space character[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-263)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-264)local out = {};[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-265)local list = mw.text.split (str, '%s*[,;]%s*');-- split str at comma or semicolon separators if there are any[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-266)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-267)for _, item in ipairs (list) do-- for each item in the list[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-268)item, accept = utilities.has_accept_as_written (item);-- remove accept-this-as-written markup when it wraps all of item[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-269)if not accept and mw.ustring.match (item, '^%w*[%.%-]?%w+%s*[%-–—]%s*%w*[%.%-]?%w+$') then-- if a hyphenated range or has endash or emdash separators[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-270)if item:match ('^%a+[%.%-]?%d+%s*%-%s*%a+[%.%-]?%d+$') or-- letterdigit hyphen letterdigit (optional separator between letter and digit)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-271)item:match ('^%d+[%.%-]?%a+%s*%-%s*%d+[%.%-]?%a+$') or-- digitletter hyphen digitletter (optional separator between digit and letter)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-272)item:match ('^%d+[%.%-]%d+%s*%-%s*%d+[%.%-]%d+$') or-- digit separator digit hyphen digit separator digit[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-273)item:match ('^%d+%s*%-%s*%d+$') or-- digit hyphen digit[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-274)item:match ('^%a+%s*%-%s*%a+$') then-- letter hyphen letter[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-275)item = item:gsub ('(%w*[%.%-]?%w+)%s*%-%s*(%w*[%.%-]?%w+)', '%1–%2');-- replace hyphen, remove extraneous space characters[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-276)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-277)item = mw.ustring.gsub (item, '%s*[–—]%s*', '–');-- for endash or emdash separated ranges, replace em with en, remove extraneous whitespace[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-278)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-279)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-280)table.insert (out, item);-- add the (possibly modified) item to the output table[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-281)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-282)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-283)local temp_str = '';-- concatenate the output table into a comma separated string[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-284)temp_str, accept = utilities.has_accept_as_written (table.concat (out, ', ')); -- remove accept-this-as-written markup when it wraps all of concatenated out[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-285)if accept then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-286)temp_str = utilities.has_accept_as_written (str);-- when global markup removed, return original str; do it this way to suppress boolean second return value[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-287)return temp_str;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-288)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-289)return temp_str;-- else, return assembled temp_str[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-290)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-291)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-292)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-293)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-294)--[[--------------------------< A R G S _ F E T C H >---------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-295)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-296)Because all of the templates share a common set of parameters, a single common function to fetch those parameters[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-297)from frame and parent frame.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-298)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-299)]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-300)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-301)local function args_fetch (frame, ps)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-302)local args = args_default;-- create a copy of the default table[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-303)local pframe = frame:getParent();-- point to the template's parameter table[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-304)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-305)for k, v in pairs (frame.args) do-- override defaults with values provided in the #invoke: if any[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-306)args[k] = v; [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-307)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-308)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-309)args.postscript = pframe.args.postscript or pframe.args.ps or ps;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-310)if 'none' == args.postscript then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-311)args.postscript = '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-312)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-313)args.group = pframe.args.group or '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-314)args.page = pframe.args.p or pframe.args.page or '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-315)args.pages = pframe.args.pp or pframe.args.pages or '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-316)args.pages = ('' ~= args.pages) and hyphen_to_dash (args.pages) or '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-317)args.location = pframe.args.at or pframe.args.loc or '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-318)args.ref = pframe.args.ref or pframe.args.Ref or '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-319)args.ignore = ('yes' == pframe.args['ignore-false-positive']) or ('yes' == pframe.args['ignore-err']);[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-320)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-321)for i, v in ipairs ({'P1', 'P2', 'P3', 'P4', 'P5'}) do-- loop through the five positional parameters and trim if set else empty string[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-322)args[v] = (pframe.args[i] and mw.text.trim (pframe.args[i])) or '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-323)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-324)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-325)if args.P5 and not is_year (args.P5, args) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-326)local i = 6;-- initialize the indexer to the sixth positional parameter[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-327)while pframe.args[i] do-- in case there are too many authors loop through the authors looking for a year[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-328)local v = mw.text.trim (pframe.args[i]);-- trim[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-329)if is_year (v, args) then-- if a year[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-330)args.P5 = v;-- overwrite whatever was in args.P5 with year[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-331)break;-- and abandon the search[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-332)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-333)i = i + 1;-- bump the indexer[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-334)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-335)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-336)return args;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-337)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-338)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-339)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-340)--[[--------------------------< H A R V A R D _ C I T A T I O N >----------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-341)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-342)common entry point for:[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-343) {{[harvard citation](https://freemwiki.com/wiki/Template:Harvard_citation "Template:Harvard citation")}} aka {{[harv](https://freemwiki.com/wiki/Template:Harv "Template:Harv")}}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-344) {{[Harvard citation no brackets](https://freemwiki.com/wiki/Template:Harvard_citation_no_brackets "Template:Harvard citation no brackets")}} aka {{[harvnb](https://freemwiki.com/wiki/Template:Harvnb "Template:Harvnb")}}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-345) {{[harvcol](https://freemwiki.com/wiki/Template:Harvcol "Template:Harvcol")}}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-346) {{[harvcolnb](https://freemwiki.com/wiki/Template:Harvcolnb "Template:Harvcolnb")}}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-347) {{[harvcoltxt](https://freemwiki.com/wiki/Template:Harvcoltxt "Template:Harvcoltxt")}}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-348) {{[Harvard citation text](https://freemwiki.com/wiki/Template:Harvard_citation_text "Template:Harvard citation text")}} aka {{[harvtxt](https://freemwiki.com/wiki/Template:Harvtxt "Template:Harvtxt")}}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-349) {{[Harvp](https://freemwiki.com/wiki/Template:Harvp "Template:Harvp")}}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-350)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-351)Distinguishing features (brackets and page separators) are specified in this module's {{#invoke}} in the respective templates.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-352)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-353)]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-354)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-355)local function harvard_citation (frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-356)local args = args_fetch (frame, '');-- get the template and invoke parameters; default postscript is empty string[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-357)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-358)return core (args);[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-359)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-360)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-361)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-362)--[[--------------------------< S T R I P _ U R L >------------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-363)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-364)used by sfn() and sfnm(). This function fixes an issue with reference tooltip gadget where the tooltip is not displayed[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-365)when an insource locator (|p=, |pp=, |loc=) has an external wikilink that contains a # character[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-366)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-367)strip uri-reserved characters from urls in |p=, |pp-, and |loc= parameters The researved characters are:[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-368) !#$&'()*+,/:;=?@[][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-369)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-370)]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-371)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-372)local function strip_url (pages)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-373)local escaped_uri;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-374)if not pages or ('' == pages) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-375)return pages;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-376)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-377)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-378)for uri in pages:gmatch ('%[(%a[%w%+%.%-]*://%S+)') do-- for each external link get the uri[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-379)escaped_uri = uri:gsub ("([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" );-- save a copy with lua pattern characters escaped[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-380)uri = uri:gsub ("[!#%$&'%(%)%*%+,/:;=%?@%[%]%.%%]", '');-- remove reserved characters and '%' because '%20' (space character) is a lua 'invalid capture index'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-381)pages = pages:gsub (escaped_uri, uri, 1);-- replace original uri with the stripped version[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-382)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-383)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-384)return pages;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-385)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-386)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-387)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-388)--[[--------------------------< S F N >------------------------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-389)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-390)entry point for {{[sfn](https://freemwiki.com/wiki/Template:Sfn "Template:Sfn")}} and {{[sfnp](https://freemwiki.com/wiki/Template:Sfnp "Template:Sfnp")}}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-391)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-392)]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-393)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-394)local function sfn (frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-395)local args = args_fetch (frame, '.');-- get the template and invoke parameters; default postscript is a dot[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-396)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-397)local result = core (args);-- go make a CITEREF anchor[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-398)-- put it all together and then strip redundant spaces[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-399)local name = table.concat ({'FOOTNOTE', args.P1, args.P2, args.P3, args.P4, args.P5, strip_url (args.page), strip_url (args.pages), strip_url (args.location)}):gsub ('%s+', ' ');[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-400)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-401)return frame:extensionTag ({name='ref', args={group=args.group, name=name}, content=result});[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-402)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-403)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-404)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-405)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-406)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-407)--[[--------------------------< S F N M >----------------------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-408)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-409)common entry point for {{[sfnm](https://freemwiki.com/wiki/Template:Sfnm "Template:Sfnm")}} and {{[sfnmp](https://freemwiki.com/wiki/Template:Sfnmp "Template:Sfnmp")}}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-410)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-411)Distinguishing features (brackets) are specified in this module's {{#invoke}} in the respective templates.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-412)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-413)]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-414)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-415)local function sfnm (frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-416)local args = args_default;-- create a copy of the default table[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-417)local pframe = frame:getParent();-- point to the template's parameter table[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-418)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-419)local n = 1;-- index of source; this is the 'n' in na1, ny, etc[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-420)local first_pnum = 1;-- first of a pair of positional parameters[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-421)local second_pnum = 2;-- second of a pair of positional parameters[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-422)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-423)local last_ps = 0;-- index of the last source with |nps= set[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-424)local last_index = 0;-- index of the last source; these used to determine which of |ps= or |nps= will terminate the whole rendering[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-425)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-426)local out = {};-- table to hold rendered sources[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-427)local footnote = {'FOOTNOTE'};-- all author, date, insource location stuff becomes part of the reference's footnote id; added as we go[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-428)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-429)for k, v in pairs (frame.args) do-- override defaults with values provided in the #invoke: if any[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-430)args[k] = v; [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-431)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-432)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-433)while true do[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-434)if not pframe.args[table.concat ({n, 'a1'})] and not pframe.args[first_pnum] then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-435)break;-- no na1 or matching positional parameter so done[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-436)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-437)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-438)if pframe.args[table.concat ({n, 'a1'})] then-- does this source use named parameters?[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-439)for _, v in ipairs ({'P1', 'P2', 'P3', 'P4', 'P5'}) do-- initialize for this source[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-440)args[v] = '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-441)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-442)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-443)for i, v in ipairs ({'P1', 'P2', 'P3', 'P4', 'P5'}) do-- extract author and year parameters for this source[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-444)args[v] = pframe.args[table.concat ({n, 'a', i})] or '';-- attempt to assign author name[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-445)if '' == args[v] then-- when there wasn't an author name[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-446)args[v] = pframe.args[table.concat ({n, 'y'})] or '';-- attempt to assign year[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-447)break;-- done with author/date for this source[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-448)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-449)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-450)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-451)else-- this source uses positional parameters[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-452)args.P1 = mw.text.trim (pframe.args[first_pnum]);-- yes, only one author supported[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-453)args.P2 = (pframe.args[second_pnum] and mw.text.trim (pframe.args[second_pnum])) or '';-- when positional author, year must also be positional[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-454)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-455)for _, v in ipairs ({'P3', 'P4', 'P5'}) do-- blank the rest of these for this source[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-456)args[v] = '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-457)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-458)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-459)first_pnum = first_pnum + 2;-- source must use positional author and positional year[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-460)second_pnum = first_pnum + 1;-- bump these for possible next positional source[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-461)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-462)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-463)args.postscript = pframe.args[table.concat ({n, 'ps'})] or '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-464)if 'none' == args.postscript then-- this for compatibility with other footnote templates; does nothing[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-465)args.postscript = '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-466)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-467)args.group = pframe.args.group or '';-- reference group[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-468)args.ref = pframe.args[table.concat ({n, 'ref'})] or '';-- alternate reference for this source[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-469)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-470)args.page = pframe.args[table.concat ({n, 'p'})] or '';-- insource locations for this source[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-471)args.pages = pframe.args[table.concat ({n, 'pp'})] or '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-472)args.pages = ('' ~= args.pages) and hyphen_to_dash (args.pages) or '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-473)args.location = pframe.args[table.concat ({n, 'loc'})] or pframe.args[table.concat ({n, 'at'})] or '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-474)args.ignore = ('yes' == pframe.args[table.concat ({n, 'ignore-false-positive'})]) or ('yes' == pframe.args[table.concat ({n, 'ignore-err'})]);[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-475)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-476)table.insert (out, core (args));-- save the rendering of this source[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-477)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-478)for k, v in ipairs ({'P1', 'P2', 'P3', 'P4', 'P5'}) do-- create the FOOTNOTE id[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-479)if '' ~= args[v] then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-480)table.insert (footnote, args[v]);[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-481)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-482)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-483)for k, v in ipairs ({'page', 'pages', 'location'}) do-- these done separately so that we can strip uri-reserved characters from extlinked page numbers [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-484)if '' ~= args[v] then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-485)table.insert (footnote, strip_url (args[v]))[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-486)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-487)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-488)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-489)last_index = n;-- flags used to select terminal postscript from nps or from end_ps[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-490)if '' ~= args.postscript then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-491)last_ps = n;[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-492)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-493)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-494)n = n+1;-- bump for the next one[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-495)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-496)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-497)local name = table.concat (footnote):gsub ('%s+', ' ');-- put the footnote together and strip redundant space[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-498)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-499)args.end_ps = pframe.args.postscript or pframe.args.ps or '.';-- this is the postscript for the whole not for the individual sources[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-500)if 'none' == args.end_ps then-- not an original sfnm parameter value; added for compatibility with other footnote templates[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-501)args.end_ps = '';[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-502)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-503)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-504)local result = table.concat ({table.concat (out, '; '), (last_index == last_ps) and '' or args.end_ps});[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-505)return frame:extensionTag ({name='ref', args={group=args.group, name=name}, content=result});[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-506)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-507)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-508)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-509)--[[--------------------------< S F N R E F >------------------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-510)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-511)implements {{[sfnref](https://freemwiki.com/wiki/Template:Sfnref "Template:Sfnref")}}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-512)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-513)]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-514)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-515)local function sfnref (frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-516)local args = getArgs (frame);[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-517)local out = {};[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-518)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-519)for i=1, 5 do-- get the first five args if there are five args[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-520)if args[i] then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-521)out[i] = args[i];[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-522)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-523)break;-- less than 5 args break out[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-524)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-525)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-526)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-527)if 5 == #out then-- when we have seen five args there may bemore[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-528)local i = 6;-- initialize the indexer to the sixth positional parameter[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-529)while args[i] do-- in case there are too many authors loop through the authors looking for a year[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-530)if is_year (args[i], args) then-- if a year[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-531)out[5] = args[i];-- overwrite whatever was in args[5] with year[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-532)break;-- and abandon the search[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-533)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-534)i = i + 1;-- bump the indexer[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-535)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-536)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-537)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-538)return mw.uri.anchorEncode ('CITEREF' .. table.concat (out));[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-539)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-540)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-541)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-542)--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-543)]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-544)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-545)return {[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-546)harvard_citation = harvard_citation,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-547)sfn = sfn,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-548)sfnm = sfnm,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-549)sfnref = sfnref,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-550) target_check = target_check,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580068&title=Module%3AFootnotes#L-551)};
Retrieved from "[https://freemwiki.com/index.php?title=Module:Footnotes&oldid=580068](https://freemwiki.com/index.php?title=Module:Footnotes&oldid=580068)"
[**Last edited 8 months ago** by Lukegao](https://freemwiki.com/index.php?title=Module:Footnotes&action=history)
#### Languages
This page is not available in other languages.
freem
* This page was last edited on 21 October 2025, at 06:18.
* Content is available under [Creative Commons Attribution-ShareAlike 4.0](https://creativecommons.org/licenses/by-sa/4.0/) unless otherwise noted. FreemWiki is operated by **FINGERPOWER DIGITAL TECHNOLOGY LLC** (Colorado, Entity ID 20221978727).
* [Privacy policy](https://freemwiki.com/wiki/Freem:Privacy_policy)
* [About freem](https://freemwiki.com/wiki/Freem:About)
* [Disclaimers](https://freemwiki.com/wiki/Freem:General_disclaimer)
* [Desktop](https://freemwiki.com/index.php?title=Module:Footnotes&mobileaction=toggle_view_desktop&oldid=580068)