local export = {}
local string_remove_comments_module = "Module:string/removeComments"
local require = require
local tonumber = tonumber
local unstrip_nowiki = mw.text.unstripNoWiki
local function remove_comments(...)
remove_comments = require(string_remove_comments_module)
return remove_comments(...)
end
-- Ported from ] by Benwing2 on Sep 1st 2023 around 6am UTC.
local nowiki_strip_marker_pattern = "\127'\"`UNIQ%-%-nowiki%-" .. (""):rep(8) .. "%-QINU`\"'\127"
local nowiki_replacements = {
= ">",
= "<",
= "{",
= "}",
}
function export.main(frame)
local boolean = {type = "boolean"}
local args = require("Module:parameters").process(frame:getParent().args, {
= true,
= {
set = {
= true, = "compact",
= true, = "inline", = "inline",
= true, = "multiline",
= true,
= true, = "twoline",
},
default = frame.args.fmt or "compact"
},
= true,
= true,
= boolean,
= boolean,
= true,
})
local source = args
if source:match(nowiki_strip_marker_pattern) then
-- Unescape the four patterns that automatically get escaped by nowiki
-- (taken from CoreTagHooks.php).
source = unstrip_nowiki(source)
source = source:gsub("()&(2??);", function(pos, code)
local ch = nowiki_replacements
if ch == "{" then -- -{
return source:byte(pos - 1) == 0x2D and ch or nil
elseif ch == "}" then -- }-
return source:byte(pos + 6) == 0x2D and ch or nil
end
return ch
end)
end
local output = remove_comments(frame:preprocess(source), "POST")
-- FIXME: this will miss some categories.
if args.nocat then
output = output:gsub("%%]", "")
end
local sep, fmt, rev = args.sep, args.fmt, args.reverse
if not sep then
local br = args.br
if br then
sep = tonumber(br) and ("<br />"):rep(br) or br
elseif fmt == "inline" or fmt == "twoline" then
sep = (rev and "⇐" or "⇒") .. (fmt == "twoline" and "<br />\n" or "")
elseif fmt == "raw" then
sep = ""
else
sep = (rev and "generated from" or "which produces") .. "<br />\n"
if fmt == "compact" then
sep = "<br />" .. sep
end
end
end
if #sep > 0 and not (sep:find("\n", nil, true) or sep:match("<br%f.->")) then
sep = " " .. sep .. " "
end
source = frame:extensionTag("syntaxhighlight", source, {
lang = "wikitext",
inline = (fmt == "inline" or fmt == "twoline" or fmt == "compact") and true or nil,
style = args.style
})
return rev and
output .. sep .. source or
source .. sep .. output
end
return export