更改 - 知沅教育出版社偶梦课程教研所

更改

跳到导航 跳到搜索
添加1,134字节 、 2025年4月30日 (三) 21:26
建立内容为“local p = {} function p.getParentSection(frame) local title = frame:getTitle() local content = frame:callParserFunction{ name = '#tag', a…”的新页面
local p = {}

function p.getParentSection(frame)
local title = frame:getTitle()
local content = frame:callParserFunction{
name = '#tag',
args = { 'pre', frame:expandTemplate{ title = ':' .. title } }
}

local sections = {}
for level, section in content:gmatch('(=+)([^=]+)=+') do
table.insert(sections, {
name = section:match('^%s*(.-)%s*$'),
level = #level
})
end

local currentTitle = mw.title.getCurrentTitle()
local currentSection = frame:getParent().args[1] or ""

local currentIndex = 0
for i, sec in ipairs(sections) do
if sec.name == currentSection then
currentIndex = i
break
end
end

if currentIndex == 0 then
return "警告 - 无法确定当前章节!"
end

local parentSection = "警告 - 无上级章节!"
for i = currentIndex - 1, 1, -1 do
if sections[i].level < sections[currentIndex].level then
parentSection = sections[i].name
break
end
end

return parentSection
end

return p

导航菜单