2023年政策修订增补工作正在进行中,欢迎参与!
Module:Lyrics/colors/hover
< Module:Lyrics | colors
local module = {}
local getArgs = require('Module:Arguments').getArgs
local lang = require('Module:Lang')
function module.main(frame)
local args = getArgs(frame, {wrappers='Template:LyricsKai/colors/hover'})
local lyricshtml = frame:expandTemplate{ title = 'LyricsKai/colors', args = args }
lyricshtml = mw.ustring.gsub(lyricshtml, '(<div%s-class="Lyrics%-line">)', '/unprocessed/%1')..'/unprocessed/'
-- 假设一个Lyrics-line后一定是另一个Lyrics-line(事实的确如此),这样我们就不用写很难看的平衡匹配了
local HoverWithNextLine_state = 0
while mw.ustring.match(lyricshtml, '/unprocessed/<div%s-class="Lyrics%-line">') ~= nil do
lyricshtml = mw.ustring.gsub(lyricshtml, '/unprocessed/(<div%s-class="Lyrics%-line">.-)/unprocessed/', function(line)
if(mw.ustring.match(line, '#NoHover') ~= nil) then
return line..'/unprocessed/'
else
if (mw.ustring.match(line, '#HoverWithNextLine') ~= nil) then
if (HoverWithNextLine_state == 0) then
HoverWithNextLine_state = 1;
return'<div class="bg_hover">'..line..'/unprocessed/'
else
if (HoverWithNextLine_state == 1) then
return line..'/unprocessed/'
end
end
end
if (HoverWithNextLine_state ~= 0) then
HoverWithNextLine_state = 0
return line..'</div>'..'/unprocessed/'
end
return '<div class="bg_hover">'..line..'</div>'..'/unprocessed/'
end
end, 1 )
end
lyricshtml = lyricshtml:gsub('#NoHover', ''):gsub('#HoverWithNextLine', ''):gsub('/unprocessed/$', '')
return lyricshtml
end
return module