Modul:Delink: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
. |
-require('Module:No globals') |
||
(2 revisi perantara oleh 2 pengguna tidak ditampilkan) | |||
Baris 1:
-- This module de-links most wikitext.
require('strict')
p = {}▼
▲local p = {}
local getArgs
local function delinkReversePipeTrick(s)
if
return s
else
return
end
end
local function delinkPipeTrick(s)
local linkarea, display = "", ""
-- We need to deal with colons, brackets, and commas, per [[Help:Pipe trick]].
-- First, remove the text before the first colon, if any.
if
s =
-- If there are no colons, grab all of the text apart from the square brackets and the pipe.
else
s =
end
-- Next up, brackets and commas.
if
s =
elseif
s =
end
return s
end
local function delinkWikilink(s)
local result = s
-- Deal with the reverse pipe trick.
if
return delinkReversePipeTrick(result)
end
result = mw.uri.decode(result, "PATH") -- decode percent-encoded entities. Leave underscores and plus signs.
result = mw.text.decode(result, true) -- decode HTML entities.
-- Check for bad titles. To do this we need to find the
-- title area of the link, i.e. the part before any pipes.
local titlearea
if
titlearea =
else
titlearea =
end
-- Check for bad characters.
Baris 54 ⟶ 58:
return s
end
-- Check for categories, interwikis, and files.
local colonprefix =
local ns = mw.site.namespaces[colonprefix] -- see if this is a known namespace
if mw.language.isKnownLanguageTag(colonprefix)
or ( ns and ( ns.canonicalName == "File" or ns.canonicalName == "Category" ) ) then
return ""
end
-- Remove the colon if the link is using the [[Help:Colon trick]].
if
result = "[[" ..
end
-- Deal with links using the [[Help:Pipe trick]].
if mw.ustring.match(result, "^%[%[[^|]*|%]%]") then
return delinkPipeTrick(result)
end
-- Find the display area of the wikilink
if
result =
-- Remove new lines from the display of multiline piped links,
-- where the pipe is before the first new line.
result =
else
result =
end
return result
end
local function delinkURL(s)
-- Assume we have already delinked internal wikilinks, and that
-- we have been passed some text between two square brackets [foo].
-- If the text contains a line break it is not formatted as a URL, regardless of other content.
if
return s
end
-- Check if the text has a valid URL prefix and at least one valid URL character.
local valid_url_prefixes = {"//", "http://", "https://", "ftp://", "gopher://", "mailto:", "news:", "irc://"}
Baris 105 ⟶ 108:
end
end
-- Get display text
if not url_prefix then
return s
end
s =
s =
s = mw.ustring.match(s, "^%s*(%S.*)$") or "" -- If the separating character was a space, trim it off.
local s_decoded = mw.text.decode(s, true)
if mw.ustring.match(s_decoded, "%c") then
return s
Baris 121 ⟶ 124:
end
end
local function delinkLinkClass(s, pattern, delinkFunction)
if not type(s) == "string" then
Baris 133 ⟶ 136:
-- than just use gsub, otherwise nested links aren't detected properly.
local result = ""
while
-- Replace text using one iteration of gsub.
s = mw.ustring.gsub(s, pattern, delinkFunction, 1)
Baris 142 ⟶ 145:
return result
end
local text = args[1] or ""
if args.refs == "yes" then
Baris 151 ⟶ 154:
end
if not (args.comments == "no") then
text =
end
if not (args.wikilinks == "no") then
Baris 163 ⟶ 166:
-- and new lines only containing spaces or tabs before a second new line.
text = mw.ustring.gsub(text, "([^\n \t][ \t]*)\n([ \t]*[^\n \t])", "%1 %2")
text =
end
return text
end
function p.delink(frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
▲ else
end
return p._delink(
end
return p
|