跳转到内容

模組:FakeH

维基百科,自由的百科全书

这是本页的一个历史版本,由SunAfterRain留言 | 贡献2020年10月10日 (六) 03:42编辑。这可能和当前版本存在着巨大的差异。

local p = {}
local mError = require('Module:Error').error

local csslist = {
	[1] = "font-size: 1.8em; margin-top: 1em; margin-bottom: 0.25em; display: block; line-height: 1.3; border-bottom-color: rgb(162, 169, 177); border-bottom-style: solid; border-bottom-width: 1px; font-family: 'Linux Libertine','Georgia','Times',serif",
	[2] = "font-size: 1.5em; margin-top: 1em; line-height: 1.3; display: block; border-bottom-color: rgb(162, 169, 177); border-bottom-style: solid; border-bottom-width: 1px; font-family: 'Linux Libertine','Georgia','Times',serif",
	[3] = "font-size: 1.2em; font-weight: bold; display: block; margin-top: 0.3em; padding-top: 0.5em;",
	[4] = "font-size: 100%; font-weight: bold; display: block; margin-top: 0.3em; padding-top: 0.5em;",
	[5] = "font-size: 100%; font-weight: bold; display: block; margin-top: 0.3em; padding-top: 0.5em;",
	[6] = "font-size: 100%; font-weight: bold; display: block; margin-top: 0.3em; padding-top: 0.5em;"
}

local function getFakeH (level, text)
	return tostring(mw.html.create('span'):attr('style', csslist[level]):wikitext(text):done())
end

function p._main (configs, text)
	local frame = mw.getCurrentFrame()
	local level = configs.level
	if not tonumber(level) or not csslist[tonumber(level)] then
		return mError({[1] = '無法解釋章節等級' .. tostring(frame:extensionTag('syntaxhighlight', '<h' .. level .. '></h .. level .. >', {lang = 'html', inline = ''}))})
	end
	return getFakeH (level, text)
end

function p.main (frame)
	local text = ''
	local getArgs = require('Module:Arguments').getArgs
	local configs = getArgs(frame, {
		frameOnly = true
	})
	local args = getArgs(frame, {
		removeBlanks = false,
		valueFunc = (function (key, value)
			if key == 1 then
				return value
			end
			return nil
		end),
		frameOnly = true
	})
	if not args[1] then
		text = '標題'
	else
		text = args[1]
	end
	return p._main (configs, text)
end

return p