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

Module:Cite:修订间差异

武外梗百科 爱国好学自强图新的百科全书
无编辑摘要
无编辑摘要
第9行: 第9行:
     end
     end


     -- 和你给的示例一致:直接用 title + getContent
     -- 获取条目内容(沿用你给的方式)
     local title = mw.title.new(page)
     local title = mw.title.new(page)
     if not title or not title.exists then
     if not title or not title.exists then
第20行: 第20行:
     end
     end


     -- 转义标题名(防正则炸)
     -- 转义标题名,防正则问题
     local safeSection = mw.ustring.gsub(
     local safeSection = mw.ustring.gsub(
         section,
         section,
第28行: 第28行:


     ----------------------------------------------------------------
     ----------------------------------------------------------------
     -- 1. 匹配任意级别标题,并捕获 '=' 数量
     -- 1. 找目标标题,并记录级别
     ----------------------------------------------------------------
     ----------------------------------------------------------------
    local headerPattern = "\n(=+)%s*" .. safeSection .. "%s*%1%s*\n"
     local startPos, endPos, eqs =
     local startPos, endPos, eqs =
         mw.ustring.find(content, headerPattern)
         mw.ustring.find(content,
            "\n(=+)%s*" .. safeSection .. "%s*%1%s*\n"
        )


     -- 兼容标题在页面最开头
     -- 兼容标题在页面开头
     if not startPos then
     if not startPos then
        headerPattern = "^(=+)%s*" .. safeSection .. "%s*%1%s*\n"
         startPos, endPos, eqs =
         startPos, endPos, eqs =
             mw.ustring.find(content, headerPattern)
             mw.ustring.find(content,
                "^(=+)%s*" .. safeSection .. "%s*%1%s*\n"
            )
     end
     end


第48行: 第50行:


     ----------------------------------------------------------------
     ----------------------------------------------------------------
     -- 2. 从标题结束后开始,找下一个“级别 ≤ 当前级别”的标题
     -- 2. 从标题结束后,顺序扫描后续标题
    --    第一个 level' <= level 的标题即为终点
     ----------------------------------------------------------------
     ----------------------------------------------------------------
     local after = mw.ustring.sub(content, endPos + 1)
     local after = mw.ustring.sub(content, endPos + 1)


     local nextHeaderPattern = "\n={1," .. level .. "}[^=].-\n"
     local cutPos = nil
    local nextStart = mw.ustring.find(after, nextHeaderPattern)
    for pos, marks in mw.ustring.gmatch(after, "()\n(=+)") do
        local nextLevel = mw.ustring.len(marks)
        if nextLevel <= level then
            cutPos = pos
            break
        end
    end


     local body
     local body
     if nextStart then
     if cutPos then
         body = mw.ustring.sub(after, 1, nextStart - 1)
         body = mw.ustring.sub(after, 1, cutPos - 1)
     else
     else
         body = after
         body = after
第63行: 第72行:


     ----------------------------------------------------------------
     ----------------------------------------------------------------
     -- 3. 维基百科式帽注 + 原样正文
     -- 3. 维基百科帽注样式
     ----------------------------------------------------------------
     ----------------------------------------------------------------
     local hatnote =
     local hatnote =