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

Module:Gochicolor

萌娘百科,万物皆可萌的百科全书!转载请标注来源页面的网页链接,并声明引自萌娘百科。内容不可商用。
跳转到导航 跳转到搜索
Template-info.svg 模块文档  [创建] [刷新]
local hex_table = mw.loadData("Module:Gochicolor/Dataset")
local p = {}
 
local function find_hex(chara, colortype)
    local hex
        hex = hex_table[chara] and hex_table[chara][colortype]
    if hex then
        return hex
    else
    	hex = hex_table["default"]["base"]
        return hex
    end
end

function p.code(frame)
    local chara = frame.args[1]
    local colortype = frame.args[2]
    local hex_code = find_hex(chara, colortype)
    return mw.text.nowiki(hex_code)
end

function p.block(frame)
    local chara = frame.args[1]
    local hex_text = frame.args[2]
    local hex_block = find_hex(chara, "base")
    local chara_link = find_hex(chara, "link")
    
    local block = '<span style="width:0.8em; height:0.8em; background-color:' .. hex_block .. ';display:inline-block;"></span>'
    local text = block .. ' [[:' .. chara_link .. '|' .. chara .. ']]'
    
    if hex_text then
    	if hex_text == "color" then
			hex_text = find_hex(chara, "dark")
		end
		text = block .. ' [[:' .. chara_link .. '|<span style="color:' .. hex_text .. '">' .. chara .. '</span>]]'
	end
    
    return text
end

return p