跳转到内容

模組:RouteSequence

被永久保护的模块
维基百科,自由的百科全书

这是本页的一个历史版本,由Siyuwj留言 | 贡献2015年1月21日 (三) 14:52 建立内容为“local p = {} function p.rail_route(frame) local style = frame.args['style'] local stations = mw.text.split(frame.args['stations'], '~') local st...”的新页面)编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)

local p = {}

function p.rail_route(frame)
	local style = frame.args['style']
	local stations = mw.text.split(frame.args['stations'], '~')
	local stations_strs = {}, station_str
	local station_split, station_parts, station_prefix, station_suffix
	local station_expr, station_link, station_name
	local match
	for i, station in ipairs(stations) do
		station_split = mw.text.split(station, '#')
		if table.getn(station_split) == 1 then
			station_prefix = ''
			station_expr = station_split[1]
			station_suffix = ''
		elseif table.getn(station_split) == 2 then
			station_prefix = station_split[1]
			station_expr = station_split[2]
			station_suffix = ''
		elseif table.getn(station_split) == 3 then
			station_prefix = station_split[1]
			station_expr = station_split[2]
			station_suffix = station_split[3]
		end
		station_parts = mw.text.split(station_expr, '!')
		if table.getn(station_parts) == 1 then
			station_link = mw.text.trim(station_parts[1])
			station_name, match = string.gsub(station_link, '站 +%(.+%)$', '')
			if match == 0 then
				station_name, match = string.gsub(station_link, '站$', '')
			end
			if match == 0 then
				station_name = station_link
				station_link = station_link .. '站'
			end
		else
			station_link = station_parts[1]
			station_name = station_parts[2]
		end
 
		station_str = ''
 
		if station_prefix ~= '' then
			station_str = station_prefix .. ' '
		end
 
		if style == nil then
			station_str = station_str .. '[[' .. station_link .. '|' .. station_name .. ']]'
		else
			station_str = station_str .. '[[' .. station_link .. '|<span style="' .. style .. '">' .. station_name .. '</span>]]'
		end
 
		if station_suffix ~= '' then
			station_str = station_str .. '&nbsp;' .. station_suffix
		end
		table.insert(stations_strs, station_str)
	end
	return table.concat(stations_strs, '&nbsp;&ndash;</span>&#32;<span class="nowrap">') 
end
 
return p