Module:Cite:修订间差异
武外梗百科 爱国好学自强图新的百科全书
更多操作
创建页面,内容为“local p = {} function p.main(frame) local page = frame.args.page or frame.args[1] local section = frame.args.section or frame.args[2] if not page or not section then return "❌ 参数不足(需要 page 和 section)" end local title = mw.title.new(page) if not title then return "❌ 条目不存在" end local content = title:getContent() if not content then return "❌ 无法读取条目内容"…” |
无编辑摘要 |
||
| 第10行: | 第10行: | ||
local title = mw.title.new(page) | local title = mw.title.new(page) | ||
if not title then | if not title or not title.exists then | ||
return "❌ | return "❌ 条目不存在:" .. page | ||
end | end | ||
| 第18行: | 第18行: | ||
return "❌ 无法读取条目内容" | return "❌ 无法读取条目内容" | ||
end | end | ||
-- 转义段落名中的特殊字符 | |||
local safeSection = mw.ustring.gsub( | |||
section, | |||
"([%^%$%(%)%%%.%[%]%*%+%-%?])", | |||
"%%%1" | |||
) | |||
-- 匹配 == 段落 == | -- 匹配 == 段落 == | ||
local pattern = "==%s*" .. | local pattern = "==%s*" .. safeSection .. "%s*==" | ||
local startPos, endPos = mw.ustring.find(content, pattern) | |||
if not startPos then | if not startPos then | ||
return "❌ 未找到段落:" .. section | return "❌ 未找到段落:" .. section | ||
end | end | ||
-- | -- 从标题结束后开始截取 | ||
local after = mw.ustring.sub(content, | local after = mw.ustring.sub(content, endPos + 1) | ||
-- 找下一个二级标题 | |||
local nextHeader = mw.ustring.find(after, "\n==[^=]") | local nextHeader = mw.ustring.find(after, "\n==[^=]") | ||