模块:Lyrics2

来自希灵百科
跳转至: 导航搜索

此模块的文档可以在模块:Lyrics2/doc创建

local p = {}

local getArgs = require('Module:Arguments').getArgs
local lang = require('Module:Lang')

function p._lyrics(args)
	local orig = mw.text.split(args.original or '', '\n')
	local tran = mw.text.split(args.translated or '', '\n')
	local llang = args.llang or 'ja'
	local rlang = args.rlang or 'zh'
	local lstyle = 'width:45%;min-width:300px;display:inline-block;white-space:pre-wrap;' .. (args.lstyle or '')
	local rstyle = 'width:45%;min-width:300px;display:inline-block;white-space:pre-wrap;' .. (args.rstyle or '')

	if args.original:match('<ruby') then
		lstyle = 'line-height:2;' .. lstyle
	end

	local html = mw.html.create()

	for i, v in pairs(orig) do
		html:
			tag('div')
				:tag('div')
					:cssText(lstyle)
					:node(lang.wrap(v, llang))
					:tag('br')
						:done()
					:done()
				:tag('div')
					:cssText(rstyle)
					:node(lang.wrap(tran[i], rlang))
					:tag('br')
						:done()
					:done()
	end
	
	-- Clear the floating
	html:tag('div'):cssText('clear:both')

	return tostring(html)
end

function p.lyrics(frame)
	local args = getArgs(frame, {wrappers='Template:LyricsKai2'})
	return p._lyrics(args)
end

return p
为本页面评分: