Title: Module:Format link - freem URL Source: https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link Markdown Content: Revision as of 13:37, 4 October 2022 by [en>Pppery](https://freemwiki.com/wiki/User:Pppery "en:User:Pppery") _Documentation for this module may be created at [Module:Format link/doc](https://freemwiki.com/index.php?title=Module:Format\_link/doc&action=edit&redlink=1 "Module:Format link/doc (page does not exist)")_ [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-1)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-2)-- Format link[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-3)--[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-4)-- Makes a wikilink from the given link and display values. Links are escaped[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-5)-- with colons if necessary, and links to sections are detected and displayed[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-6)-- with " § " as a separator rather than the standard MediaWiki "#". Used in[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-7)-- the {{format link}} template.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-8)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-9)local libraryUtil = require('libraryUtil')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-10)local checkType = libraryUtil.checkType[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-11)local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-12)local mArguments -- lazily initialise [[Module:Arguments]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-13)local mError -- lazily initialise [[Module:Error]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-14)local yesno -- lazily initialise [[Module:Yesno]][](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-15)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-16)local p = {}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-17)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-18)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-19)-- Helper functions[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-20)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-21)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-22)local function getArgs(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-23)-- Fetches the arguments from the parent frame. Whitespace is trimmed and[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-24)-- blanks are removed.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-25)mArguments = require('Module:Arguments')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-26)return mArguments.getArgs(frame, {parentOnly = true})[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-27)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-28)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-29)local function removeInitialColon(s)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-30)-- Removes the initial colon from a string, if present.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-31)return s:match('^:?(.*)')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-32)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-33)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-34)local function maybeItalicize(s, shouldItalicize)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-35)-- Italicize s if s is a string and the shouldItalicize parameter is true.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-36)if s and shouldItalicize then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-37)return '' .. s .. ''[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-38)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-39)return s[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-40)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-41)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-42)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-43)local function parseLink(link)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-44)-- Parse a link and return a table with the link's components.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-45)-- These components are:[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-46)-- - link: the link, stripped of any initial colon (always present)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-47)-- - page: the page name (always present)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-48)-- - section: the page name (may be nil)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-49)-- - display: the display text, if manually entered after a pipe (may be nil)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-50)link = removeInitialColon(link)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-51)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-52)-- Find whether a faux display value has been added with the {{!}} magic[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-53)-- word.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-54)local prePipe, display = link:match('^(.-)|(.*)$')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-55)link = prePipe or link[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-56)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-57)-- Find the page, if it exists.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-58)-- For links like [[#Bar]], the page will be nil.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-59)local preHash, postHash = link:match('^(.-)#(.*)$')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-60)local page[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-61)if not preHash then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-62)-- We have a link like [[Foo]].[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-63)page = link[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-64)elseif preHash ~= '' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-65)-- We have a link like [[Foo#Bar]].[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-66)page = preHash[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-67)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-68)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-69)-- Find the section, if it exists.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-70)local section[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-71)if postHash and postHash ~= '' then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-72)section = postHash[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-73)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-74)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-75)return {[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-76)link = link,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-77)page = page,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-78)section = section,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-79)display = display,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-80)}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-81)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-82)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-83)local function formatDisplay(parsed, options)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-84)-- Formats a display string based on a parsed link table (matching the[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-85)-- output of parseLink) and an options table (matching the input options for[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-86)-- _formatLink).[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-87)local page = maybeItalicize(parsed.page, options.italicizePage)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-88)local section = maybeItalicize(parsed.section, options.italicizeSection)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-89)if (not section) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-90)return page[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-91)elseif (not page) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-92)return mw.ustring.format('§ %s', section)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-93)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-94)return mw.ustring.format('%s § %s', page, section)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-95)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-96)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-97)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-98)local function missingArgError(target)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-99)mError = require('Module:Error')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-100)return mError.error{message =[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-101)'Error:no link or target specified!([[' .. target .. '#Errors|help]])'[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-102)}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-103)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-104)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-105)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-106)-- Main functions[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-107)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-108)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-109)function p.formatLink(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-110)-- The formatLink export function, for use in templates.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-111)yesno = require('Module:Yesno')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-112)local args = getArgs(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-113)local link = args[1] or args.link[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-114)local target = args[3] or args.target[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-115)if not (link or target) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-116)return missingArgError('Template:Format link')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-117)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-118)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-119)return p._formatLink{[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-120)link = link,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-121)display = args[2] or args.display,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-122)target = target,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-123)italicizePage = yesno(args.italicizepage),[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-124)italicizeSection = yesno(args.italicizesection),[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-125)categorizeMissing = args.categorizemissing[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-126)}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-127)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-128)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-129)function p._formatLink(options)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-130)-- The formatLink export function, for use in modules.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-131)checkType('_formatLink', 1, options, 'table')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-132)local function check(key, expectedType) --for brevity[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-133)checkTypeForNamedArg([](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-134)'_formatLink', key, options[key], expectedType or 'string', true[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-135))[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-136)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-137)check('link')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-138)check('display')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-139)check('target')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-140)check('italicizePage', 'boolean')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-141)check('italicizeSection', 'boolean')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-142)check('categorizeMissing')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-143)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-144)-- Normalize link and target and check that at least one is present[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-145)if options.link == '' then options.link = nil end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-146)if options.target == '' then options.target = nil end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-147)if not (options.link or options.target) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-148)return missingArgError('Module:Format link')[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-149)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-150)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-151)local parsed = parseLink(options.link)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-152)local display = options.display or parsed.display[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-153)local catMissing = options.categorizeMissing[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-154)local category = ''[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-155)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-156)-- Find the display text[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-157)if not display then display = formatDisplay(parsed, options) end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-158)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-159)-- Handle the target option if present[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-160)if options.target then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-161)local parsedTarget = parseLink(options.target)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-162)parsed.link = parsedTarget.link[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-163)parsed.page = parsedTarget.page[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-164)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-165)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-166)-- Test if page exists if a diagnostic category is specified[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-167)if catMissing and (mw.ustring.len(catMissing) > 0) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-168)local title = nil[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-169)if parsed.page then title = mw.title.new(parsed.page) end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-170)if title and (not title.isExternal) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-171)local success, exists = pcall(function() return title.exists end)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-172)if success and not exists then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-173)category = mw.ustring.format('[[Category:%s]]', catMissing)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-174)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-175)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-176)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-177)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-178)-- Format the result as a link[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-179)if parsed.link == display then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-180)return mw.ustring.format('[[:%s]]%s', parsed.link, category)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-181)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-182)return mw.ustring.format('[[:%s|%s]]%s', parsed.link, display, category)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-183)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-184)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-185)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-186)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-187)-- Derived convenience functions[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-188)--------------------------------------------------------------------------------[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-189)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-190)function p.formatPages(options, pages)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-191)-- Formats an array of pages using formatLink and the given options table,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-192)-- and returns it as an array. Nil values are not allowed.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-193)local ret = {}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-194)for i, page in ipairs(pages) do[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-195)ret[i] = p._formatLink{[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-196)link = page,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-197)categorizeMissing = options.categorizeMissing,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-198)italicizePage = options.italicizePage,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-199)italicizeSection = options.italicizeSection[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-200)}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-201)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-202)return ret[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-203)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-204)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=579765&title=Module%3AFormat_link#L-205)return p