模块:ExampleTable:修订间差异
无编辑摘要 |
无编辑摘要 |
||
| 第5行: | 第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 | if not output then | ||
-- 检查输入是否包含 <nowiki> 标签 | |||
local has_nowiki = input:match("</?nowiki>") | |||
if has_nowiki then | if has_nowiki then | ||
-- | -- 移除 <nowiki> 标签并渲染内容 | ||
local nowiki_content = input:gsub("</?nowiki>", " | local nowiki_content = input:gsub("</?nowiki>", "") | ||
output = frame:preprocess(nowiki_content) | output = frame:preprocess(nowiki_content) | ||
else | else | ||
-- | -- 如果输入没有 <nowiki> 标签,则直接使用输入作为输出 | ||
output = input | output = input | ||
end | end | ||
end | end | ||
| 第30行: | 第27行: | ||
output = output:gsub("\n+", "\n"):gsub("^%s*(.-)%s*$", "%1") | 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') | ||
| 第50行: | 第48行: | ||
:tag('pre') | :tag('pre') | ||
:css('white-space', 'pre-wrap') | :css('white-space', 'pre-wrap') | ||
:wikitext(input) | :wikitext(input) -- 左侧显示原始输入(包括 <nowiki> 标签) | ||
:done() | :done() | ||
:done() | :done() | ||
| 第58行: | 第56行: | ||
width = '50%' | width = '50%' | ||
}) | }) | ||
:wikitext(output) | :wikitext(output) -- 右侧显示输出内容 | ||
:done() | :done() | ||
:done() | :done() | ||