模块:ExampleTable:修订间差异
创建页面,内容为“-- 模块: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…” |
无编辑摘要 |
||
| (未显示同一用户的7个中间版本) | |||
| 第1行: | 第1行: | ||
local p = {} | local p = {} | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
| 第6行: | 第5行: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
-- | -- 获取输入和输出参数 | ||
local input = args[1] or "" | local input = args[1] or "" | ||
local output = args[2] | local output = args[2] | ||
-- | -- 如果 output 未提供,则移除左侧的 <nowiki> 标签并渲染内容 | ||
if not output then | |||
-- 移除 <nowiki> 标签 | |||
local nowiki_content = input:gsub("</?nowiki>", "") | |||
-- 渲染内容 | |||
output = frame:preprocess(nowiki_content) | |||
end | |||
-- 清理输出中的多余空格和换行 | |||
output = output:gsub("\n+", "\n"):gsub("^%s*(.-)%s*$", "%1") | |||
-- 创建表格HTML | |||
local tableHtml = mw.html.create('table') | local tableHtml = mw.html.create('table') | ||
:addClass('wikitable') | :addClass('wikitable') | ||
:tag('tr') | |||
:tag('th') | |||
:css('width', '50%') | |||
:wikitext('输入') | |||
:done() | |||
:tag('th') | |||
:css('width', '50%') | |||
:wikitext('输出') | |||
:done() | |||
:done() | |||
:tag('tr') | :tag('tr') | ||
:tag('td') | :tag('td') | ||
:css({ | :css({ | ||
['vertical-align'] = ' | ['vertical-align'] = 'middle', | ||
width = '50%' | width = '50%' | ||
}) | }) | ||
:tag('pre') | :tag('pre') | ||
:css('white-space', 'pre-wrap') | :css('white-space', 'pre-wrap') | ||
:wikitext(input) | :wikitext(input) -- 左侧显示原始输入(包括 <nowiki> 标签) | ||
:done() | :done() | ||
:done() | :done() | ||
:tag('td') | :tag('td') | ||
:css({ | :css({ | ||
['vertical-align'] = ' | ['vertical-align'] = 'middle', | ||
width = '50%' | width = '50%' | ||
}) | }) | ||
:wikitext(output) | :wikitext(output) -- 右侧显示输出内容 | ||
:done() | :done() | ||
:done() | :done() | ||