모듈:Text

신사 (토론 | 기여)님의 2024년 5월 21일 (화) 13:42 판 (새 문서: local getArgs = require('Module:Arguments').getArgs local p = {} function p.fontsize( frame, size, text ) local count_char = require('Module:String').count_ local input_size = frame.args[1] or '' local text = frame.args[2] or text local size if string.find(input_size, '[+-]') then size = (( count_char(input_size, '+') - count_char(input_size, '-') ) / 5 + 1)..'rem' else size = input_size end return string.format('<span style="font-size:%s;line-height:1.6em">%s</sp...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

이 모듈에 대한 설명문서는 모듈:Text/설명문서에서 만들 수 있습니다

local getArgs = require('Module:Arguments').getArgs
local p = {}

function p.fontsize( frame, size, text )
	local count_char = require('Module:String').count_
	local input_size = frame.args[1] or ''
	local text = frame.args[2] or text
	local size
	if string.find(input_size, '[+-]') then
		size = (( count_char(input_size, '+') - count_char(input_size, '-') ) / 5 + 1)..'rem'
	else
		size = input_size
	end
	
	return string.format('<span style="font-size:%s;line-height:1.6em">%s</span>', size, text )
	
end

function p.color( frame, text, background )
	local ifexist = require('Module:String').ifexist_
	local color = frame.args[1]
	local text = frame.args[2] or text
	local background =  frame.args[3] or background or '#fff0'
	
	local style = ifexist( color, 'gradient',
		'color: #fff0;background:'..color..';-webkit-background-clip: text;background-clip: text;',
		'color:'..color..';background:'..background )
	
	return string.format('<span style="%s">%s</span>', style, text )
end

function p.calcColor( frame )
	local args = getArgs(frame)
	return p.calcColor_( args[1] )
end

function p.calcColor_( colorCode )
	if colorCode == nil or colorCode == 'transparent' or colorCode == '#fff0' then
		return '#000'
	end
	
	local red, green, blue
	
	if string.len(colorCode) == 4 then
		red = tonumber("0x" .. string.rep(string.sub(colorCode, 2, 2), 2 ) )
		green = tonumber("0x" .. string.rep(string.sub(colorCode, 3, 3), 2 ) )
		blue = tonumber("0x" .. string.rep(string.sub(colorCode, 4, 4), 2 ) )
	else
		red = tonumber("0x" .. string.sub(colorCode, 2, 3))
		green = tonumber("0x" .. string.sub(colorCode, 4, 5))
		blue = tonumber("0x" .. string.sub(colorCode, 6, 7))
	end
	
	if (0.299 * red + 0.587 * green + 0.114 * blue) > 186 then
		return " #000000"
	else
		return " #FFFFFF"
	end
end

return p