添加的内容 删除的内容
(创建页面,内容为“-- Imported from: https://runescape.wiki/w/Module:Module%20toc -- <nowiki> local p = {} local function getNewlineLocations( content ) local locs = {} local pos = 0 repeat pos = mw.ustring.find( content, '\n', pos + 1, true ) table.insert( locs, pos ) until not pos return locs end local function findLineNumber( pos, newLineLocs ) local max = #newLineLocs local min = 1 repeat local i = math.ceil( (max…”) |
小 (已保护“Module:Module toc”:重要模块([编辑=仅允许管理员](无限期)[移动=仅允许管理员](无限期))) |
||
(未显示同一用户的1个中间版本) | |||
第93行: | 第93行: | ||
local tbl = mw.html.create( 'table' ):addClass( 'wikitable mw-collapsible mw-collapsed' ) |
local tbl = mw.html.create( 'table' ):addClass( 'wikitable mw-collapsible mw-collapsed' ) |
||
tbl:tag( 'tr' ) |
tbl:tag( 'tr' ) |
||
:tag( 'th' ):wikitext( ' |
:tag( 'th' ):wikitext( '函数列表' ):done() |
||
:tag( 'tr' ) |
:tag( 'tr' ) |
||
:tag( 'td' ):wikitext( table.concat( res, '<br>' ) ) |
:tag( 'td' ):wikitext( table.concat( res, '<br>' ) ) |
2024年6月24日 (一) 18:56的最新版本
可在Module:Module toc/doc创建此模块的帮助文档
-- Imported from: https://runescape.wiki/w/Module:Module%20toc
-- <nowiki>
local p = {}
local function getNewlineLocations( content )
local locs = {}
local pos = 0
repeat
pos = mw.ustring.find( content, '\n', pos + 1, true )
table.insert( locs, pos )
until not pos
return locs
end
local function findLineNumber( pos, newLineLocs )
local max = #newLineLocs
local min = 1
repeat
local i = math.ceil( (max + min) / 2 )
if newLineLocs[i] < pos then
min = i
elseif newLineLocs[i] >= pos then
max = i
end
until newLineLocs[i] > pos and (newLineLocs[i - 1] or 0) < pos
return max
end
local function getFunctionLocations( content )
local locs = {}
local newLineLocs = getNewlineLocations( content )
local start = 0
repeat
local name
name, start = mw.ustring.match( content, '%sfunction%s+([^%s%(]+)%s*%(()', start + 1 )
if start then
table.insert( locs, { name=name, line = findLineNumber( start, newLineLocs ) } )
end
until not start
start = 0
repeat
local name
name, start = mw.ustring.match( content, '%s([^%s=])%s*=%s*function%s*%(()', start + 1 )
if start then
table.insert( locs, { name=name, line = findLineNumber( start, newLineLocs ) } )
end
until not start
return locs
end
function p.main()
local title = mw.title.getCurrentTitle()
local moduleName = mw.ustring.gsub( title.text, '/[Dd]oc$', '' )
if not title:inNamespaces( 828 ) then
return ''
end
local fullModuleName = mw.ustring.gsub( title.fullText, '/[Dd]oc$', '' )
local content = mw.title.new( fullModuleName ):getContent()
if not content then
return ''
end
local function substMutilineComment( match )
local lineCount = #getNewlineLocations( match )
return mw.ustring.rep( '\n', lineCount ) or ''
end
content = content:gsub( '(%-%-%[(=-)%[.-%]%2%])', substMutilineComment ):gsub( '%-%-[^\n]*', '' ) -- Strip comments
local functionLocs = getFunctionLocations( content )
table.sort( functionLocs, function(lhs, rhs) return lhs.line < rhs.line end )
if #functionLocs == 0 then
return ''
end
local res = {}
for _, func in ipairs( functionLocs ) do
table.insert( res, mw.ustring.format( 'L %d — [%s#L-%d %s]', func.line, title:fullUrl():gsub( '/[Dd]oc$', '' ), func.line, func.name ) )
end
local tbl = mw.html.create( 'table' ):addClass( 'wikitable mw-collapsible mw-collapsed' )
tbl:tag( 'tr' )
:tag( 'th' ):wikitext( '函数列表' ):done()
:tag( 'tr' )
:tag( 'td' ):wikitext( table.concat( res, '<br>' ) )
return tostring( tbl )
end
return p
-- </nowiki>