模块:Gloss:修订间差异

来自「荏苒之境」
无编辑摘要
无编辑摘要
 
(未显示同一用户的3个中间版本)
第1行: 第1行:
local utils_str = require("Module:Utils/String")
local gloss = {}
local gloss = {}


第7行: 第9行:
end
end
return parts
return parts
end
local function format_tooltip(t, text, tip)
if tip ~= "" and tip ~= nil then
t[#t+1] = "{{#tip-text:"
t[#t+1] = text
t[#t+1] = "|"
t[#t+1] = tip
t[#t+1] = "}}"
else
t[#t+1] = text
end
end
end


gloss.show = function(frame)
gloss.show = function(frame)
local delimiter = frame.args.delimiter or " "
local text = frame.args[1]
local text = frame.args[1]
local descs = split(frame.args[2], delimiter)
local tips = utils_str.unlines(frame:preprocess(frame.args[2]), "\n;")
local separator = frame.args.separator or ""
local t = {}
local t = {}
local i = 1
local i = 1
local mode = frame.args.mode
for word in string.gmatch(text, "([^"..delimiter.."]+)") do
if mode == nil or mode == "" or mode == "空格" then
if word ~= "" then
for word in string.gmatch(text, "([^ ]+)") do
local desc = descs[i]
if word ~= "" then
if desc ~= nil then
format_tooltip(t, word, tips[i])
t[#t+1] = "{{#tip-text:"
i = i + 1
t[#t+1] = word
t[#t+1] = "|"
t[#t+1] = desc
t[#t+1] = "}}"
else
t[#t+1] = word
end
end
i = i + 1
t[#t+1] = " "
end
t[#t+1] = nil
elseif mode == "分隔符" then
local delimiter = frame.args.delimiter
if delimiter == nil or delimiter == "" then
delimiter = ";"
end
end
if separator ~= "" then
for word in string.gmatch(text, "([^"..delimiter.."]+)") do
t[#t+1] = separator
if word ~= "" then
format_tooltip(t, word, tips[i])
i = i + 1
end
end
end
end
end


return table.concat(t)
return frame:preprocess(table.concat(t))
end
end


return gloss
return gloss

2025年8月21日 (四) 19:30的最新版本

此模块的文档可以在模块:Gloss/doc创建

local utils_str = require("Module:Utils/String")

local gloss = {}

local function split(text, delimiters)
	local parts = {}
	for part in string.gmatch(text, "([^"..delimiters.."]+)") do
		parts[#parts+1] = part
	end
	return parts
end

local function format_tooltip(t, text, tip)
	if tip ~= "" and tip ~= nil then
		t[#t+1] = "{{#tip-text:"
		t[#t+1] = text
		t[#t+1] = "|"
		t[#t+1] = tip
		t[#t+1] = "}}"
	else
		t[#t+1] = text
	end
end

gloss.show = function(frame)
	local text = frame.args[1]
	local tips = utils_str.unlines(frame:preprocess(frame.args[2]), "\n;")
	
	local t = {}
	local i = 1
	
	local mode = frame.args.mode
	if mode == nil or mode == "" or mode == "空格" then
		for word in string.gmatch(text, "([^ ]+)") do
			if word ~= "" then
				format_tooltip(t, word, tips[i])
				i = i + 1
			end
			t[#t+1] = " "
		end
		t[#t+1] = nil
	elseif mode == "分隔符" then
		local delimiter = frame.args.delimiter
		if delimiter == nil or delimiter == "" then
			delimiter = ";"
		end
		for word in string.gmatch(text, "([^"..delimiter.."]+)") do
			if word ~= "" then
				format_tooltip(t, word, tips[i])
				i = i + 1
			end
		end
	end

	return frame:preprocess(table.concat(t))
end

return gloss