维护提醒

BWIKI 全站将于 9 月 3 日(全天)进行维护,期间无法编辑任何页面或发布新的评论。

全站通知:

模块:Expanded/Format link

来自星露谷物语维基
跳到导航 跳到搜索
[ 创建 | 刷新 ]文档页面
当前模块文档缺失,需要扩充。
local p = {}

function p.call( inputArgs )
	if not inputArgs or type( inputArgs ) ~= 'table' then
		return nil
	end

	local rawPage = inputArgs[ 1 ] or ''
	local rawSection = inputArgs[ 2 ] or ''
	local isSVE = rawPage:find( 'SVE', 1, true )
	local prefix = isSVE and 'SVE:' or ':'
	
	-- 处理SVE前缀
	if isSVE then
		rawPage = rawPage:gsub( 'SVE:', '' )
	end
	
	-- 处理页面和章节
	local finalPage, finalSection
	if rawPage:find( '#', 1, true ) then
		local splitParts = mw.text.split( rawPage:gsub( '#+', '#' ), '#', true )
		finalPage = splitParts[ 1 ]
		finalSection = splitParts[ 2 ]
	else
		finalPage = rawPage
		finalSection = rawSection
	end

	finalPage = finalPage:gsub( '^:', '' )
	
	-- 特殊情况:包含管道符的非SVE链接
	if not isSVE and rawPage:find( '|', 1, true ) then
		return '[[:' .. rawPage .. ']]'
	end
	
	-- 生成最终链接
	if finalSection == '' then
		return '[[' .. prefix .. finalPage .. ']]'
	elseif finalPage == '' then
		return '[[#' .. finalSection .. '|§ ' .. finalSection .. ']]'
	else
		return '[[' .. prefix .. finalPage .. '#' .. finalSection .. '|' .. finalPage .. ' § ' .. finalSection .. ']]'
	end
end

function p.main( f )
	local args = f
	local frame = mw.getCurrentFrame()
	if f == frame then
		args = require( 'Module:ProcessArgs' ).merge( true )
	end

	return p.call( {
		args[ 1 ] or '',
		args[ 2 ] or ''
	} )
end

return p