Jump to content

Module:demo

Wiktionary වෙතින්


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 [[w:Module:Demo]] by Benwing2 on Sep 1st 2023 around 6am UTC.

local nowiki_strip_marker_pattern = "\127'\"`UNIQ%-%-nowiki%-" .. ("[%dA-F]"):rep(8) .. "%-QINU`\"'\127"

local nowiki_replacements = {
	["gt"] = ">",
	["lt"] = "<",
	["#123"] = "{",
	["#125"] = "}",
}

function export.main(frame)
	local boolean = {type = "boolean"}
	local args = require("Module:parameters").process(frame:getParent().args, {
		[1] = true,
		["fmt"] = {
			set = {
				["compact"] = true, ["c"] = "compact",
				["inline"] = true, ["i"] = "inline", ["1"] = "inline",
				["multiline"] = true, ["m"] = "multiline",
				["raw"] = true,
				["twoline"] = true, ["2"] = "twoline",
			},
			default = frame.args.fmt or "compact"
		},
		["br"] = true,
		["sep"] = true,
		["reverse"] = boolean,
		["nocat"] = boolean,
		["style"] = true,
	})

	local source = args[1]
	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("()&([#gl][1t]2?[35]?);", function(pos, code)
			local ch = nowiki_replacements[code]
			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("%[%[Category.-%]%]", "")
	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[%W].->")) 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
"https://si.wiktionary.org/w/index.php?title=Module:demo&oldid=218167" වෙතින් සම්ප්‍රවේශනය කෙරිණි