跳转到内容

模块:ExampleTable

来自DJMAX中文资料库
Raxter留言 | 贡献2025年10月16日 (四) 08:29的版本 (创建页面,内容为“-- 模块:ExampleTable local p = {} local getArgs = require('Module:Arguments').getArgs function p.main(frame) local args = getArgs(frame) -- 获取参数(匿名参数1为input,匿名参数2为output) local input = args[1] or "" local output = args[2] or input -- 如果没有提供output,默认使用input -- 构建表格(无表头) local tableHtml = mw.html.create('table') :addClass('wikitable') :t…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

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

-- 模块:ExampleTable
local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.main(frame)
    local args = getArgs(frame)
    
    -- 获取参数(匿名参数1为input,匿名参数2为output)
    local input = args[1] or ""
    local output = args[2] or input  -- 如果没有提供output,默认使用input
    
    -- 构建表格(无表头)
    local tableHtml = mw.html.create('table')
        :addClass('wikitable')
        :tag('tr')
            :tag('td')
                :css({
                    ['vertical-align'] = 'top',
                    width = '50%'
                })
                :tag('pre')
                    :css('white-space', 'pre-wrap')  -- 允许自动换行
                    :wikitext(input)
                :done()
            :done()
            :tag('td')
                :css({
                    ['vertical-align'] = 'top',
                    width = '50%'
                })
                :wikitext(output)
            :done()
        :done()
    
    return tostring(tableHtml)
end

return p