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

来自萌娘文库
跳转至: 导航搜索
(实现游戏台词表格式输出)
第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")
:tag("tr")
+
        :tag("tr")
:tag("th")
+
            :tag("th")
:css("width", "50%")
+
                :css("width", "50%")
:wikitext("原文")
+
                :wikitext("原文")
:done()
+
                :done()
:tag("th")
+
            :tag("th")
:css("width", "50%")
+
                :css("width", "50%")
:wikitext("译文")
+
                :wikitext("译文")
:done()
+
                :done()
:done()
+
            :done()
local actor = "???"
+
    local actor = "???"
local counter = 0
+
    local counter = 0
for index, line in ipairs(args) do
+
    for index, line in ipairs(args) do
line = mw.text.trim(line)
+
        line = mw.text.trim(line)
+
       
if mw.ustring.find(mw.text.trim(line), "^@[^@]") then
+
        if mw.ustring.find(mw.text.trim(line), "^@[^@]") then
actor = mw.text.trim(mw.ustring.sub(line, 2))
+
            actor = mw.text.trim(mw.ustring.sub(line, 2))
--error(mw.dumpObject({index,actor}))
+
            if counter == 1 then
if counter == 1 then
+
                node:tag("td")
node:tag("td")
+
                node = node.done()
node = node.done()
+
                counter = 0
counter = 0
+
            end
end
+
        elseif mw.ustring.find(mw.text.trim(line), "^-[^-]") then
elseif mw.ustring.find(mw.text.trim(line), "^-[^-]") then
+
            local chapter = mw.text.trim(mw.ustring.sub(line, 2))
local chapter = mw.text.trim(mw.ustring.sub(line, 2))
+
            if counter == 1 then
if counter == 1 then
+
                node:tag("td")
node:tag("td")
+
                node = node.done()
error(tostring(node))
+
                counter = 0
node = node.done()
+
            end
counter = 0
+
            node:tag("tr"):tag("th")
end
+
                :attr("colspan", 2)
node:tag("tr"):tag("th")
+
                :wikitext(chapter)
:attr("colspan", 2)
+
            counter = 0
:wikitext(chapter)
+
        else
counter = 0
+
            if counter == 0 then
else
+
                node = node:tag("tr")
if counter == 0 then
+
            end
node = node:tag("tr")
+
            local rawtext = mw.ustring.gsub(line, "[-@][-@]", function(match)
end
+
                return mw.ustring.sub(match, 1, 2)
local rawtext = mw.ustring.gsub(line, "[-@][-@]", function(match)
+
            end)
return mw.ustring.sub(match, 1, 2)
+
            if counter == 0 then
end)
+
                rawtext = frame:expandTemplate{ title = "lj", args = { rawtext } }
node:tag("td")
+
            end
:wikitext("<sup>")
+
            node:tag("td")
:wikitext(actor)
+
                :wikitext("<sup>")
:wikitext("</sup>")
+
                :wikitext(actor)
:wikitext(rawtext)
+
                :wikitext("</sup>")
if counter == 1 then
+
                :wikitext(rawtext)
node = node:done()
+
            if counter == 1 then
end
+
                node = node:done()
+
            end
counter = math.mod(counter + 1, 2)
+
           
end
+
            counter = math.mod(counter + 1, 2)
end
+
        end
+
    end
return tostring(node)
+
   
 +
    return tostring(node)
 
end
 
end
  
 
return module
 
return module

2020年8月13日 (四) 20:15的版本

此模块的文档可以在模块:少女歌剧/doc创建

local module = {}

function module.scenario(frame)
    local args = frame.args
    
    local node = mw.html.create("table")
        :addClass("wikitable")
        :tag("tr")
            :tag("th")
                :css("width", "50%")
                :wikitext("原文")
                :done()
            :tag("th")
                :css("width", "50%")
                :wikitext("译文")
                :done()
            :done()
    local actor = "???"
    local counter = 0
    for index, line in ipairs(args) do
        line = mw.text.trim(line)
        
        if mw.ustring.find(mw.text.trim(line), "^@[^@]") then
            actor = mw.text.trim(mw.ustring.sub(line, 2))
            if counter == 1 then
                node:tag("td")
                node = node.done()
                counter = 0
            end
        elseif mw.ustring.find(mw.text.trim(line), "^-[^-]") then
            local chapter = mw.text.trim(mw.ustring.sub(line, 2))
            if counter == 1 then
                node:tag("td")
                node = node.done()
                counter = 0
            end
            node:tag("tr"):tag("th")
                :attr("colspan", 2)
                :wikitext(chapter)
            counter = 0
        else
            if counter == 0 then
                node = node:tag("tr")
            end
            local rawtext = mw.ustring.gsub(line, "[-@][-@]", function(match)
                return mw.ustring.sub(match, 1, 2)
            end)
            if counter == 0 then
                rawtext = frame:expandTemplate{ title = "lj", args = { rawtext } }
            end
            node:tag("td")
                :wikitext("<sup>")
                :wikitext(actor)
                :wikitext("</sup>")
                :wikitext(rawtext)
            if counter == 1 then
                node = node:done()
            end
            
            counter = math.mod(counter + 1, 2)
        end
    end
    
    return tostring(node)
end

return module