2023年政策修订增补工作正在进行中,欢迎参与!
  • Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

Module:Lyrics/colors/hover

萌娘百科,万物皆可萌的百科全书!转载请标注来源页面的网页链接,并声明引自萌娘百科。内容不可商用。
跳转到导航 跳转到搜索
Template-info.svg 模块文档  [创建] [刷新]
    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