Title: Module:Delink - freem URL Source: https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink Markdown Content: [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#) - [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%3ADelink&returntoquery=mobileaction%3Dtoggle_view_mobile%26oldid%3D580054) * [Settings](https://freemwiki.com/index.php?title=Special:MobileOptions&returnto=Module%3ADelink) * [About](https://freemwiki.com/wiki/About) * [Terms of Service](https://freemwiki.com/wiki/Terms_of_Service) [freem](https://freemwiki.com/wiki/Main_Page) Search # Module:Delink * [Language](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink "Language") * [Watch](https://freemwiki.com/index.php?title=Special:UserLogin&returnto=Module%3ADelink) * [Edit](https://freemwiki.com/index.php?title=Module:Delink&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:Delink&diff=prev&oldid=580054 "Module:Delink")) [← Older revision](https://freemwiki.com/index.php?title=Module:Delink&direction=prev&oldid=580054 "Module:Delink") | Latest revision (diff) | Newer revision → (diff) _Documentation for this module may be created at [Module:Delink/doc](https://freemwiki.com/index.php?title=Module:Delink/doc&action=edit&redlink=1 "Module:Delink/doc (page does not exist)")_ [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-1)-- This module de-links most wikitext.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-2)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-3)require("strict")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-4)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-5)local p = {}[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-6)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-7)local getArgs[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-8)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-9)local function delinkReversePipeTrick(s)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-10)if s:match("^%[%[|.*[|\n]") then -- Check for newlines or multiple pipes.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-11)return s[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-12)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-13)return s:match("%[%[|(.*)%]%]")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-14)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-15)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-16)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-17)local function delinkPipeTrick(s)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-18)-- We need to deal with colons, brackets, and commas, per [[Help:Pipe trick]].[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-19)-- First, remove the text before the first colon, if any.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-20)if s:match(":") then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-21)s = s:match("%[%[.-:(.*)|%]%]")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-22)-- If there are no colons, grab all of the text apart from the square brackets and the pipe.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-23)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-24)s = s:match("%[%[(.*)|%]%]")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-25)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-26)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-27)-- Next up, brackets and commas.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-28)if s:match("%(.-%)$") then -- Brackets trump commas.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-29)s = s:match("(.-) ?%(.-%)$")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-30)elseif s:match(",") then -- If there are no brackets, display only the text before the first comma.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-31)s = s:match("(.-),.*$")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-32)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-33)return s[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-34)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-35)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-36)-- Return wikilink target |wikilinks=target[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-37)local function getDelinkedTarget(s)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-38)local result = s[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-39)-- Deal with the reverse pipe trick.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-40)if result:match("%[%[|") then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-41)return delinkReversePipeTrick(result)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-42)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-43)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-44)result = mw.uri.decode(result, "PATH") -- decode percent-encoded entities. Leave underscores and plus signs.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-45)result = mw.text.decode(result, true) -- decode HTML entities.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-46)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-47)-- Check for bad titles. To do this we need to find the[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-48)-- title area of the link, i.e. the part before any pipes.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-49)local target_area[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-50)if result:match("|") then -- Find if we're dealing with a piped link.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-51)target_area = result:match("^%[%[(.-)|.*%]%]")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-52)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-53)target_area = result:match("^%[%[(.-)%]%]")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-54)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-55)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-56)-- Check for bad characters.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-57)if mw.ustring.match(target_area, "[%[%]<>{}%%%c\n]") and mw.ustring.match(target_area, "[%[%]<>{}%%%c\n]") ~= "?" then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-58)return s[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-59)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-60)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-61)return target_area[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-62)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-63)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-64)local function getDelinkedLabel(s)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-65)local result = s[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-66)-- Deal with the reverse pipe trick.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-67)if result:match("%[%[|") then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-68)return delinkReversePipeTrick(result)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-69)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-70)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-71)result = mw.uri.decode(result, "PATH") -- decode percent-encoded entities. Leave underscores and plus signs.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-72)result = mw.text.decode(result, true) -- decode HTML entities.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-73)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-74)-- Check for bad titles. To do this we need to find the[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-75)-- title area of the link, i.e. the part before any pipes.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-76)local target_area[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-77)if result:match("|") then -- Find if we're dealing with a piped link.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-78)target_area = result:match("^%[%[(.-)|.*%]%]")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-79)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-80)target_area = result:match("^%[%[(.-)%]%]")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-81)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-82)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-83)-- Check for bad characters.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-84)if mw.ustring.match(target_area, "[%[%]<>{}%%%c\n]") and mw.ustring.match(target_area, "[%[%]<>{}%%%c\n]") ~= "?" then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-85)return s[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-86)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-87)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-88)-- Check for categories, interwikis, and files.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-89)local colon_prefix = result:match("%[%[(.-):.*%]%]") or "" -- Get the text before the first colon.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-90)local ns = mw.site.namespaces[colon_prefix] -- see if this is a known namespace[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-91)if mw.language.isKnownLanguageTag(colon_prefix) or (ns and (ns.canonicalName == "File" or ns.canonicalName == "Category")) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-92)return ""[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-93)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-94)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-95)-- Remove the colon if the link is using the [[Help:Colon trick]].[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-96)if result:match("%[%[:") then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-97)result = "[[" .. result:match("%[%[:(.*%]%])")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-98)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-99)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-100)-- Deal with links using the [[Help:Pipe trick]].[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-101)if mw.ustring.match(result, "^%[%[[^|]*|%]%]") then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-102)return delinkPipeTrick(result)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-103)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-104)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-105)-- Find the display area of the wikilink[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-106)if result:match("|") then -- Find if we're dealing with a piped link.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-107)result = result:match("^%[%[.-|(.+)%]%]")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-108)-- Remove new lines from the display of multiline piped links,[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-109)-- where the pipe is before the first new line.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-110)result = result:gsub("\n", "")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-111)else[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-112)result = result:match("^%[%[(.-)%]%]")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-113)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-114)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-115)return result[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-116)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-117)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-118)local function delinkURL(s)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-119)-- Assume we have already delinked internal wikilinks, and that[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-120)-- we have been passed some text between two square brackets [foo].[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-121)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-122)-- If the text contains a line break it is not formatted as a URL, regardless of other content.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-123)if s:match("\n") then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-124)return s[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-125)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-126)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-127)-- Check if the text has a valid URL prefix and at least one valid URL character.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-128)local valid_url_prefixes = {"//", "http://", "https://", "ftp://", "gopher://", "mailto:", "news:", "irc://"} [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-129)local url_prefix[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-130)for _ ,v in ipairs(valid_url_prefixes) do[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-131)if mw.ustring.match(s, '^%[' .. v ..'[^"%s].*%]' ) then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-132)url_prefix = v[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-133)break[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-134)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-135)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-136)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-137)-- Get display text[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-138)if not url_prefix then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-139)return s[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-140)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-141)s = s:match("^%[" .. url_prefix .. "(.*)%]") -- Grab all of the text after the URL prefix and before the final square bracket.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-142)s = s:match('^.-(["<> ].*)') or "" -- Grab all of the text after the first URL separator character ("<> ).[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-143)s = mw.ustring.match(s, "^%s*(%S.*)$") or "" -- If the separating character was a space, trim it off.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-144)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-145)local s_decoded = mw.text.decode(s, true)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-146)if mw.ustring.match(s_decoded, "%c") then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-147)return s[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-148)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-149)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-150)return s_decoded[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-151)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-152)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-153)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-154)local function delinkLinkClass(text, pattern, delinkFunction)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-155)if type(text) ~= "string" then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-156)error("Attempt to de-link non-string input.", 2)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-157)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-158)if type(pattern) ~= "string" or mw.ustring.sub(pattern, 1, 1) ~= "^" then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-159)error('Invalid pattern detected. Patterns must begin with "^".', 2)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-160)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-161)-- Iterate over the text string, and replace any matched text. using the [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-162)-- delink function. We need to iterate character by character rather [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-163)-- than just use gsub, otherwise nested links aren't detected properly.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-164)local result = ""[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-165)while text ~= "" do[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-166)-- Replace text using one iteration of gsub.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-167)text = mw.ustring.gsub(text, pattern, delinkFunction, 1)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-168)-- Append the left-most character to the result string.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-169)result = result .. mw.ustring.sub(text, 1, 1)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-170)text = mw.ustring.sub(text, 2, -1)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-171)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-172)return result[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-173)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-174)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-175)function p._delink(args)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-176)local text = args[1] or ""[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-177)if args.refs == "yes" then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-178)-- Remove any [[Help:Strip markers]] representing ref tags. In most situations [](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-179)-- this is not a good idea - only use it if you know what you are doing![](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-180)text = mw.ustring.gsub(text, "UNIQ%w*%-ref%-%d*%-QINU", "")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-181)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-182)if args.comments ~= "no" then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-183)text = text:gsub("", "") -- Remove html comments.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-184)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-185)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-186)if args.wikilinks ~= "no" and args.wikilinks ~= "target" then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-187)-- De-link wikilinks and return the label portion of the wikilink.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-188)text = delinkLinkClass(text, "^%[%[.-%]%]", getDelinkedLabel)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-189)elseif args.wikilinks == "target" then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-190)-- De-link wikilinks and return the target portions of the wikilink.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-191)text = delinkLinkClass(text, "^%[%[.-%]%]", getDelinkedTarget)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-192)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-193)if args.urls ~= "no" then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-194)text = delinkLinkClass(text, "^%[.-%]", delinkURL) -- De-link URLs.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-195)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-196)if args.whitespace ~= "no" then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-197)-- Replace single new lines with a single space, but leave double new lines[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-198)-- and new lines only containing spaces or tabs before a second new line.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-199)text = mw.ustring.gsub(text, "([^\n \t][ \t]*)\n([ \t]*[^\n \t])", "%1 %2")[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-200)text = text:gsub("[ \t]+", " ") -- Remove extra tabs and spaces.[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-201)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-202)return text[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-203)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-204)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-205)function p.delink(frame)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-206)if not getArgs then[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-207)getArgs = require('Module:Arguments').getArgs[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-208)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-209)return p._delink(getArgs(frame, {wrappers = 'Template:Delink'}))[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-210)end[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-211)[](https://freemwiki.com/index.php?mobileaction=toggle_view_mobile&oldid=580054&title=Module%3ADelink#L-212)return p Retrieved from "[https://freemwiki.com/index.php?title=Module:Delink&oldid=580054](https://freemwiki.com/index.php?title=Module:Delink&oldid=580054)" [Last edited on 21 October 2025, at 06:18](https://freemwiki.com/index.php?title=Module:Delink&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/Privacy_Policy) * [About](https://freemwiki.com/wiki/About) * [Terms of Service](https://freemwiki.com/wiki/Terms_of_Service) * [Desktop](https://freemwiki.com/index.php?title=Module:Delink&mobileaction=toggle_view_desktop&oldid=580054)