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

Module:Cite

武外梗百科 爱国好学自强图新的百科全书
Zelda110留言 | 贡献2026年2月9日 (一) 21:18的版本 (创建页面,内容为“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 "❌ 无法读取条目内容"…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

此模块的文档可以在Module:Cite/doc创建

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 "❌ 无法读取条目内容"
    end

    -- 匹配 == 段落 ==
    local pattern = "==%s*" .. mw.ustring.gsub(section, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1") .. "%s*=="

    local startPos = mw.ustring.find(content, pattern)
    if not startPos then
        return "❌ 未找到段落:" .. section
    end

    -- 截取段落正文
    local after = mw.ustring.sub(content, startPos + #section + 4)
    local nextHeader = mw.ustring.find(after, "\n==[^=]")

    local sectionText
    if nextHeader then
        sectionText = mw.ustring.sub(after, 1, nextHeader - 1)
    else
        sectionText = after
    end

    sectionText = mw.text.trim(sectionText)

    return string.format(
        "'''原条目:[[%s]]'''\n\n%s",
        page,
        sectionText
    )
end

return p