您似乎还未注册一个账号?我们强烈推荐您点击此处创建一个账户。|如果您在H萌娘上发现某些内容错误/空缺/不中立,请勇于按右上角编辑按钮!

Module:Lyrics/hover:修订间差异

H萌娘,万物皆可H的百科全书!
跳转到导航 跳转到搜索
imported>实验性:无用论废人
[InPageEdit] 没有编辑摘要
 
imported>实验性:无用论废人
[InPageEdit] 没有编辑摘要
 
第2行: 第2行:
   
   
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local buildLyrics = require('Module:Lyrics/Sandbox')._lyrics
local buildLyrics = require('Module:Lyrics')._lyrics
local initHandler = require('Module:HooksHandler').init
local initHandler = require('Module:HooksHandler').init
   
   

2022年1月24日 (一) 13:31的最新版本

模块文档  [创建] [刷新]
local module = {}
 
local getArgs = require('Module:Arguments').getArgs
local buildLyrics = require('Module:Lyrics')._lyrics
local initHandler = require('Module:HooksHandler').init
 
local preSplit = function (original, translated, customArgs)
	-- 旧的示例里面翻译部分也有加,但是实际上没有必要
	return original, mw.ustring.gsub(mw.ustring.gsub(translated, '#HoverWithNextLine', ''), '#NoHover', '')
end
 
local preParse = function (original, translated, customArgs)
	customArgs.noHover = {}
	customArgs.hoverWithNextLine = {}
	for idx, val in ipairs(original) do
		val = mw.ustring.gsub(val, '#NoHover', function()
			customArgs.noHover[idx] = true
			return ''
		end)
		original[idx] = mw.ustring.gsub(val, '#HoverWithNextLine', function()
			customArgs.hoverWithNextLine[idx] = true
			return ''
		end)
	end
end
 
local postParse = function (lines, customArgs)
	local index, all, add, start = 1, #lines, 0, nil
	local warp = function (_start)
		if not _start then _start = start end
		table.insert(lines, _start, '<div class="bg_hover">')
		table.insert(lines, index + 2, '</div>')
		index = index + 2
		add = add + 2
		start = nil
	end
	repeat
		if not customArgs.noHover[index - add] then
			if not customArgs.hoverWithNextLine[index - add] then
				warp(start or index)
			else
				start = start or index
			end
		elseif start then
			warp()
		end
		index = index + 1
	until index > all + add
	if start then warp() end
end
 
function module.initHooks(args, hooksHandler, customArgs)
	return hooksHandler({ preSplit = preSplit, preParse = preParse, postParse = postParse })
end
 
function module.main(frame)
	local args = getArgs(frame, {wrappers='Template:LyricsKai/colors/hover/Sandbox'})
	local hooksHandler, customArgs = initHandler(), {}
	local hookTrigger = module.initHooks(args, hooksHandler, customArgs)
 
	return buildLyrics(args, hookTrigger, customArgs)
end
 
return module