local p = {}
-- 换行处理 {{#invoke:角色卡片|newline|变量=xxx}}
function p.newline(frame)
local args = frame.args
local paragraphs = {}
local text = args['变量']
for line in text:gmatch("[^\r\n]+") do
table.insert(paragraphs, "<p>" .. line .. "</p>")
end
return table.concat(paragraphs, "\n")
--return textToParagraphs(args['变量'])
end
-- 角色卡片图片处理
function p.kp_img(frame)
local args = frame.args
local data = args['img']
local sub = args['sub']
local text = ""
local dataArray = {}
for item in data:gmatch("[^;]+") do
-- 将拆分出的数据添加到text
local abc = frame:callParserFunction('filepath:'..item)
text = text .. abc .. ";"
table.insert(dataArray, item)
end
-- 删除最后一个;号
text = string.sub(text, 1, -2)
if sub == nil then
return dataArray[sub]
else
return text
end
end
function p.jskp(frame)
local args = frame.args
local input = args['变量']
local parsed_data = ''
for line in input:gmatch("[^\r\n]+") do
local key, value = line:match("(.*)=(.*)")
if key and value then
--print(key, "=", value)
parsed_data = parsed_data..'<p>'..key..":"..value..'</p>'
end
end
return parsed_data
end
function textToParagraphs(text)
local paragraphs = {}
for line in text:gmatch("[^\r\n]+") do
table.insert(paragraphs, "<p>" .. line .. "</p>")
end
return table.concat(paragraphs, "\n")
end
return p