Module:Cite:修订间差异
武外梗百科 爱国好学自强图新的百科全书
更多操作
无编辑摘要 |
无编辑摘要 |
||
| 第9行: | 第9行: | ||
end | end | ||
-- | -- 获取条目内容(沿用你给的方式) | ||
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 startPos, endPos, eqs = | local startPos, endPos, eqs = | ||
mw.ustring.find(content, | mw.ustring.find(content, | ||
"\n(=+)%s*" .. safeSection .. "%s*%1%s*\n" | |||
) | |||
-- | -- 兼容标题在页面开头 | ||
if not startPos then | if not startPos then | ||
startPos, endPos, eqs = | startPos, endPos, eqs = | ||
mw.ustring.find(content, | 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 | local cutPos = nil | ||
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 | if cutPos then | ||
body = mw.ustring.sub(after, 1, | body = mw.ustring.sub(after, 1, cutPos - 1) | ||
else | else | ||
body = after | body = after | ||
| 第63行: | 第72行: | ||
---------------------------------------------------------------- | ---------------------------------------------------------------- | ||
-- 3. | -- 3. 维基百科帽注样式 | ||
---------------------------------------------------------------- | ---------------------------------------------------------------- | ||
local hatnote = | local hatnote = | ||