html 充值模块,模块:Html

wikitable

wikitable(schema, data)

schema: 表头

data: 表格数据

Example

数组方式

wikitable(

{"col1", "col2", "col3"},

{

{1, 2, 3},

{4, 5, 6},

{7, 8, 9}

}

)

字典方式

wikitable(

{

{

["scope"] = "a",

["label"] = "col1"

},

{

["scope"] = "b",

["label"] = "col2"

},

{

["scope"] = "c",

["label"] = "col3"

}

},

{

{["a"] = 1, ["b"] = 2, ["c"] = 3},

{["a"] = 4, ["b"] = 5, ["c"] = 6},

{["a"] = 7, ["b"] = 8, ["c"] = 9}

}

)

local p = {}

function p.wikitable(schema, data, options)

local transpose, expandRow, expandRowKey, width, class

if options then

transpose = options.transpose or nil

expandRow = options.expandRow or nil

expandRowKey = options.expandRowKey or nil

width = options.width or nil

class = options.class or nil

end

local out = ""

if schema[1]["scope"] then

-- 数据为dict形式

if transpose then

-- 转置

for _, field in ipairs(schema) do

local rowHtml = ""

rowHtml = rowHtml .. "

" .. field.label .. ""

for rowNumber, row in ipairs(data) do

if row[field.scope] == nil then

error("wikitable数据第" .. rowNumber .. "列 " .. field.scope .. " 的值为nil")

end

rowHtml = rowHtml .. "

" .. row[field.scope] .. ""

end

rowHtml = "

" .. rowHtml .. ""

out = out .. rowHtml

end

elseif transpose == nil and expandRow == nil then

for _, field in ipairs(schema) do

out = out .. "

" .. field["label"] .. ""

end

out = "

" .. out .. ""

for rowNumber, row in ipairs(data) do

local rowHtml = ""

for _, field in ipairs(schema) do

if row[field.scope] == nil then

error("wikitable数据第" .. rowNumber .. "行 " .. field.scope .. " 的值为nil")

end

rowHtml = rowHtml .. "

" .. row[field.scope] .. ""

end

rowHtml = "

" .. rowHtml .. ""

out = out .. rowHtml

end

elseif expandRow then

for _, field in ipairs(schema) do

out = out .. "

" .. field["label"] .. ""

end

out = "

" .. out .. ""

for rowNumber, row in ipairs(data) do

local rowHtml = ""

for _, field in ipairs(schema) do

if row[field.scope] == nil then

error("wikitable数据第" .. rowNumber .. "行 " .. field.scope .. " 的值为nil")

end

rowHtml = rowHtml .. "

" .. row[field.scope] .. ""

end

rowHtml = '

' .. rowHtml .. ""

out = out .. rowHtml

rowHtml = ""

local expandContent = ""

for _, field in ipairs(expandRow) do

if row[field.scope] and #tostring(row[field.scope]) > 0 then

expandContent =

expandContent ..

mw.ustring.format(

[[

%s
%s
]],

field.label,

row[field.scope]

)

end

end

rowHtml =

rowHtml .. '

' .. expandContent .. "
"

rowHtml =

'

" .. rowHtml .. ""

out = out .. rowHtml

end

end

else

-- 数据为array形式

if transpose then

-- 转置

for i, label in ipairs(schema) do

local rowHtml = ""

rowHtml = rowHtml .. "

" .. label .. ""

for _, row in ipairs(data) do

rowHtml = rowHtml .. "

" .. row[i] .. ""

end

rowHtml = "

" .. rowHtml .. ""

out = out .. rowHtml

end

else

for _, label in ipairs(schema) do

out = out .. "

" .. label .. ""

end

out = "

" .. out .. ""

for _, row in ipairs(data) do

local rowHtml = ""

for i, _ in ipairs(schema) do

rowHtml = rowHtml .. "

" .. row[i] .. ""

end

rowHtml = "

" .. rowHtml .. ""

out = out .. rowHtml

end

end

end

out =

mw.ustring.format(

'

\n',

class or "wikitable",

width and 'style="width:' .. width .. ';"' or "",

out

)

return out

end

function p.h2(text)

return "

" .. text .. "
"

end

function p.h3(text)

return "

" .. text .. "
"

end

function p.h4(text)

return "

" .. text .. "
"

end

function p.p(text)

return "

" .. text .. "

"

end

function p.ul(array)

if #array > 0 then

local text = ""

for _, v in ipairs(array) do

if #v > 0 then

text = text .. "

" .. v .. ""

end

end

return "

  • " .. text .. "
"

end

return ""

end

function p.ol(array)

if #array > 0 then

local text = ""

for _, v in ipairs(array) do

if #v > 0 then

text = text .. "

" .. v .. ""

end

end

return "

  1. " .. text .. "
"

end

return ""

end

return p

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值