“模块:少女歌剧”的版本间的差异

来自萌娘文库
跳转至: 导航搜索
(サンムル移动页面模块:阿斯蒂芬模块:少女歌剧,不留重定向:错误创建)
(修复tooltip显示文本错误)
 
(未显示同一用户的8个中间版本)
第2行: 第2行:
  
 
function module.scenario(frame)
 
function module.scenario(frame)
local args = frame.args
+
    local args = frame.args
+
   
local node = mw.html.create("table")
+
    local node = mw.html.create("table")
:addClass("wikitable")
+
        :addClass("wikitable")
:css("width", "100%")
+
        :tag("tr")
:tag("tr")
+
            :tag("th")
:tag("th")
+
                :done()
:css("width", "50%")
+
            :tag("th")
:wikitext("原文")
+
                :css("width", "50%")
:done()
+
                :wikitext("原文")
:tag("th")
+
                :done()
:css("width", "50%")
+
            :tag("th")
:wikitext("译文")
+
                :css("width", "50%")
:done()
+
                :wikitext("译文")
:done()
+
                :done()
local actor = "???"
+
            :done()
local counter = 0
+
    local actors = { "???" }
for _, line in ipairs(args) do
+
    local pair = true
line = mw.text.trim(line)
+
    local actors_image = nil
+
    local counter = 0
if mw.ustring.find(mw.text.trim(line), "^@[^@]") then
+
    for index, line in ipairs(args) do
actor = mw.text.trim(mw.ustring.sub(line, 2))
+
        line = mw.text.trim(line)
if counter == 1 then
+
       
node:tag("td"):done()
+
        if mw.ustring.find(mw.text.trim(line), "^@[^@]") then
counter = 0
+
            if not pair then
end
+
                node:tag("td")
elseif mw.ustring.find(mw.text.trim(line), "^-[^-]") then
+
                node = node.done()
local chapter = mw.text.trim(mw.ustring.sub(line, 2))
+
                pair = true
if counter == 1 then
+
                counter = counter + 1
node:tag("td")
+
            end
node = node.done()
+
           
end
+
            local new_actors = { mw.text.trim(mw.ustring.sub(line, 2)) }
node:tag("tr"):tag("th")
+
            while true do
:attr("colspan", 2)
+
                local str = new_actors[#new_actors]
:wikitext(chapter)
+
                local pos = mw.ustring.find(str, "&[^&]")
counter = 0
+
                if pos then
else
+
                    new_actors[#new_actors] = mw.ustring.gsub(mw.text.trim(mw.ustring.sub(str, 1, pos - 1)), "&&", "&")
node:tag("td")
+
                    new_actors[#new_actors + 1] = mw.text.trim(mw.ustring.sub(str, pos + 1))
:wikitext("<sup>")
+
                else
:wikitext(actor)
+
                    new_actors[#new_actors] = mw.ustring.gsub(str, "&&", "&")
:wikitext("</sup>")
+
                    break
:wikitext(mw.ustring.gsub(line, "[-@][-@]", function(match)
+
                end
return mw.ustring.sub(match, 1, 2)
+
            end
end))
+
           
end
+
            if actors_image ~= nil and table.concat(new_actors) ~= table.concat(actors) then
+
                if counter > 1 then
if counter == 0 then
+
                    actors_image:attr("rowspan", counter)
node = node:tag("tr")
+
                end
end
+
                actors_image = nil
end
+
                counter = 0
 +
            end
 +
            actors = new_actors
 +
        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 actors_image ~= nil then
 +
                if counter > 1 then
 +
                    actors_image:attr("rowspan", counter)
 +
                end
 +
                actors_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")
 +
                if not actors_image then
 +
                    actors_image = node:tag("td")
 +
                    local flag = true
 +
                    for _, actor in ipairs(actors) do
 +
                        if flag then
 +
                            flag = false
 +
                        else
 +
                            actors_image:newline() -- 多人时换行。
 +
                        end
 +
                        actors_image
 +
                            :wikitext("[[File:")
 +
                            :wikitext(module.images.icon(actor))
 +
                            :wikitext("|40px|link=|")
 +
                            :wikitext(module.images.officialName(actor) or "???")
 +
                            :wikitext("]]")
 +
                    end
 +
                end
 +
            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
 +
            local actor_names = {}
 +
            for _, actor in ipairs(actors) do
 +
            table.insert(actor_names, module.images.officialName(actor) or "???")
 +
            end
 +
            node:tag("td"):tag("span")
 +
                :attr("title", table.concat(actor_names, "&"))
 +
                :wikitext(rawtext)
 +
            if not pair then
 +
                node = node:done()
 +
                counter = counter + 1
 +
            end
 +
           
 +
            pair = not pair
 +
        end
 +
    end
 +
    node = node:allDone()
 +
    if actors_image ~= nil then
 +
        if counter > 1 then
 +
            actors_image:attr("rowspan", counter)
 +
        end
 +
        actors_image = nil
 +
        counter = 0
 +
    end
 +
   
 +
    return tostring(node)
 
end
 
end
  
 
return module
 
return module

2020年8月15日 (六) 11:30的最新版本

此模块的文档可以在模块:少女歌剧/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 actors = { "???" }
    local pair = true
    local actors_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_actors = { mw.text.trim(mw.ustring.sub(line, 2)) }
            while true do
                local str = new_actors[#new_actors]
                local pos = mw.ustring.find(str, "&[^&]")
                if pos then
                    new_actors[#new_actors] = mw.ustring.gsub(mw.text.trim(mw.ustring.sub(str, 1, pos - 1)), "&&", "&")
                    new_actors[#new_actors + 1] = mw.text.trim(mw.ustring.sub(str, pos + 1))
                else
                    new_actors[#new_actors] = mw.ustring.gsub(str, "&&", "&")
                    break
                end
            end
            
            if actors_image ~= nil and table.concat(new_actors) ~= table.concat(actors) then
                if counter > 1 then
                    actors_image:attr("rowspan", counter)
                end
                actors_image = nil
                counter = 0
            end
            actors = new_actors
        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 actors_image ~= nil then
                if counter > 1 then
                    actors_image:attr("rowspan", counter)
                end
                actors_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")
                if not actors_image then
                    actors_image = node:tag("td")
                    local flag = true
                    for _, actor in ipairs(actors) do
                        if flag then
                            flag = false
                        else
                            actors_image:newline() -- 多人时换行。
                        end
                        actors_image
                            :wikitext("[[File:")
                            :wikitext(module.images.icon(actor))
                            :wikitext("|40px|link=|")
                            :wikitext(module.images.officialName(actor) or "???")
                            :wikitext("]]")
                    end
                end
            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
            local actor_names = {}
            for _, actor in ipairs(actors) do
            	table.insert(actor_names, module.images.officialName(actor) or "???")
            end
            node:tag("td"):tag("span")
                :attr("title", table.concat(actor_names, "&"))
                :wikitext(rawtext)
            if not pair then
                node = node:done()
                counter = counter + 1
            end
            
            pair = not pair
        end
    end
    node = node:allDone()
    if actors_image ~= nil then
        if counter > 1 then
            actors_image:attr("rowspan", counter)
        end
        actors_image = nil
        counter = 0
    end
    
    return tostring(node)
end

return module