“模块:少女歌剧”的版本间的差异
小 (支持显示icon) |
小 (合并对话) |
||
第7行: | 第7行: | ||
:addClass("wikitable") | :addClass("wikitable") | ||
:tag("tr") | :tag("tr") | ||
− | + | :tag("th") | |
− | + | :done() | |
:tag("th") | :tag("th") | ||
:css("width", "50%") | :css("width", "50%") | ||
第19行: | 第19行: | ||
:done() | :done() | ||
local actor = "???" | local actor = "???" | ||
+ | local pair = true | ||
+ | local actor_image = nil | ||
local counter = 0 | local counter = 0 | ||
for index, line in ipairs(args) do | for index, line in ipairs(args) do | ||
第24行: | 第26行: | ||
if mw.ustring.find(mw.text.trim(line), "^@[^@]") then | if mw.ustring.find(mw.text.trim(line), "^@[^@]") then | ||
− | + | if not pair then | |
− | if | ||
node:tag("td") | node:tag("td") | ||
node = node.done() | node = node.done() | ||
+ | pair = true | ||
+ | counter = counter + 1 | ||
+ | end | ||
+ | local new_actor = mw.text.trim(mw.ustring.sub(line, 2)) | ||
+ | if actor_image ~= nil and new_actor ~= actor then | ||
+ | if counter > 1 then | ||
+ | actor_image:attr("rowspan", counter) | ||
+ | end | ||
+ | actor_image = nil | ||
counter = 0 | counter = 0 | ||
end | end | ||
+ | actor = new_actor | ||
elseif mw.ustring.find(mw.text.trim(line), "^-[^-]") then | elseif mw.ustring.find(mw.text.trim(line), "^-[^-]") then | ||
− | + | if not pair then | |
− | if | ||
node:tag("td") | node:tag("td") | ||
node = node.done() | node = node.done() | ||
+ | pair = true | ||
+ | counter = counter + 1 | ||
+ | end | ||
+ | if actor_image ~= nil then | ||
+ | if counter > 1 then | ||
+ | actor_image:attr("rowspan", counter) | ||
+ | end | ||
+ | actor_image = nil | ||
counter = 0 | counter = 0 | ||
end | end | ||
+ | local chapter = mw.text.trim(mw.ustring.sub(line, 2)) | ||
node:tag("tr"):tag("th") | node:tag("tr"):tag("th") | ||
:attr("colspan", 3) | :attr("colspan", 3) | ||
:wikitext(chapter) | :wikitext(chapter) | ||
− | + | pair = true | |
else | else | ||
− | if | + | if pair then |
− | + | module.images = module.images or require("Module:少女歌剧/images") | |
− | node = node:tag("tr"):tag("td") | + | node = node:tag("tr") |
− | + | actor_image = actor_image or node:tag("td") | |
− | + | :wikitext("[[File:") | |
− | + | :wikitext(module.images.icon(actor)) | |
− | + | :wikitext("|40px]]") | |
end | end | ||
local rawtext = mw.ustring.gsub(line, "[-@][-@]", function(match) | local rawtext = mw.ustring.gsub(line, "[-@][-@]", function(match) | ||
return mw.ustring.sub(match, 1, 2) | return mw.ustring.sub(match, 1, 2) | ||
end) | end) | ||
− | if | + | if pair then |
rawtext = frame:expandTemplate{ title = "lj", args = { rawtext } } | rawtext = frame:expandTemplate{ title = "lj", args = { rawtext } } | ||
end | end | ||
node:tag("td") | node:tag("td") | ||
:wikitext(rawtext) | :wikitext(rawtext) | ||
− | if | + | if not pair then |
node = node:done() | node = node:done() | ||
+ | counter = counter + 1 | ||
end | end | ||
− | + | pair = not pair | |
+ | end | ||
+ | end | ||
+ | if actor_image ~= nil then | ||
+ | if counter > 1 then | ||
+ | actor_image:attr("rowspan", counter) | ||
end | end | ||
+ | actor_image = nil | ||
+ | counter = 0 | ||
end | end | ||
2020年8月14日 (五) 16:26的版本
此模块的文档可以在模块:少女歌剧/doc创建
local module = {} function module.scenario(frame) local args = frame.args local node = mw.html.create("table") :addClass("wikitable") :tag("tr") :tag("th") :done() :tag("th") :css("width", "50%") :wikitext("原文") :done() :tag("th") :css("width", "50%") :wikitext("译文") :done() :done() local actor = "???" local pair = true local actor_image = nil local counter = 0 for index, line in ipairs(args) do line = mw.text.trim(line) if mw.ustring.find(mw.text.trim(line), "^@[^@]") then if not pair then node:tag("td") node = node.done() pair = true counter = counter + 1 end local new_actor = mw.text.trim(mw.ustring.sub(line, 2)) if actor_image ~= nil and new_actor ~= actor then if counter > 1 then actor_image:attr("rowspan", counter) end actor_image = nil counter = 0 end actor = new_actor elseif mw.ustring.find(mw.text.trim(line), "^-[^-]") then if not pair then node:tag("td") node = node.done() pair = true counter = counter + 1 end if actor_image ~= nil then if counter > 1 then actor_image:attr("rowspan", counter) end actor_image = nil counter = 0 end local chapter = mw.text.trim(mw.ustring.sub(line, 2)) node:tag("tr"):tag("th") :attr("colspan", 3) :wikitext(chapter) pair = true else if pair then module.images = module.images or require("Module:少女歌剧/images") node = node:tag("tr") actor_image = actor_image or node:tag("td") :wikitext("[[File:") :wikitext(module.images.icon(actor)) :wikitext("|40px]]") end local rawtext = mw.ustring.gsub(line, "[-@][-@]", function(match) return mw.ustring.sub(match, 1, 2) end) if pair then rawtext = frame:expandTemplate{ title = "lj", args = { rawtext } } end node:tag("td") :wikitext(rawtext) if not pair then node = node:done() counter = counter + 1 end pair = not pair end end if actor_image ~= nil then if counter > 1 then actor_image:attr("rowspan", counter) end actor_image = nil counter = 0 end return tostring(node) end return module