模組:沙盒/SolidBlock/存档简化器
外观
![文档图示](http://upload.wikimedia.org/wikipedia/commons/thumb/4/43/Test_Template_Info-Icon_-_Version_%282%29.svg/50px-Test_Template_Info-Icon_-_Version_%282%29.svg.png)
您可能想要创建本Scribunto模块的文档。 编者可以在本模块的沙盒 (创建 | 镜像)和测试样例 (创建)页面进行实验。 请在/doc子页面中添加分类。本模块的子页面。 |
local page=mw.title.new( 'User talk:SolidBlock/存档' ):getContent()
local paget={}
-- explode
while page:find("\n") do
local idx=page:find("\n")-1
table.insert(paget,page:sub(1,idx))
page=page:sub(idx+2,-1)
end
table.insert(paget,page)
-- paget:将每一行转化为一个域值,形成一个域表
local title={}
local meta={}
function meta.__tostring(t)
local str=''
if t.index>0 then
str=str..'['..tostring(t.index)..'级标题:]'
end
str=str..t.text
return str
end
for k,v in pairs(paget) do
local text=v
local headerindex=0
while text:sub(1,1)=='=' and text:sub(-1,-1)=='=' do
headerindex=headerindex+1
text=text:sub(2,-2)
end
if headerindex>0 then
text=mw.text.trim(text)
end
table.insert(title,setmetatable({
index=headerindex,
text=text,
num=k
},meta))
end
return title