打开/关闭菜单
60
73
29
1.1K
武外梗百科
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

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*" .. mw.ustring.gsub(section, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1") .. "%s*=="
     local pattern = "==%s*" .. safeSection .. "%s*=="
    local startPos, endPos = mw.ustring.find(content, pattern)


    local startPos = 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, startPos + #section + 4)
     local after = mw.ustring.sub(content, endPos + 1)
 
    -- 找下一个二级标题
     local nextHeader = mw.ustring.find(after, "\n==[^=]")
     local nextHeader = mw.ustring.find(after, "\n==[^=]")