Module:Tlg
模块文档[创建]
您可能想要创建本的文档。 编者可以在本模板的沙盒 (创建 | 镜像)和测试样例 (创建)页面进行实验。 请在/doc子页面中添加分类。本模块的子页面。 |
-- This implements Template:Tlglocal getArgs = require('Module:Arguments').getArgslocal p = {}-- Is a string non-empty?local function _ne(s) return s ~= nil and s ~= ""endlocal nw = mw.text.nowikilocal function addTemplate(s)local i, _ = s:find(':', 1, true)if i == nil thenreturn 'Template:' .. sendlocal ns = s:sub(1, i - 1)if ns == '' or mw.site.namespaces[ns] thenreturn selsereturn 'Template:' .. sendendlocal function trimTemplate(s)local needle = 'template:'if s:sub(1, needle:len()):lower() == needle thenreturn s:sub(needle:len() + 1)elsereturn sendendlocal function linkTitle(args)if _ne(args.nolink) thenreturn args['1']endlocal titleObjlocal titlePart = '[['if args['1'] then-- This handles :Page and other NStitleObj = mw.title.new(args['1'], 'Template')elsetitleObj = mw.title.getCurrentTitle()endtitlePart = titlePart .. (titleObj ~= nil and titleObj.fullText oraddTemplate(args['1']))local textPart = args.alttextif not _ne(textPart) thenif titleObj ~= nil thentextPart = titleObj:inNamespace("Template") and args['1'] or titleObj.fullTextelse-- redlinktextPart = args['1']endendif _ne(args.subst) then-- HACK: the ns thing above is probably brokentextPart = 'subst:' .. textPartendif _ne(args.brace) thentextPart = nw('{{') .. textPart .. nw('}}')elseif _ne(args.braceinside) thentextPart = nw('{') .. textPart .. nw('}')endtitlePart = titlePart .. '|' .. textPart .. ']]'if _ne(args.braceinside) thentitlePart = nw('{') .. titlePart .. nw('}')endreturn titlePartendfunction p.main(frame)local args = getArgs(frame, {trim = true,removeBlanks = false})return p._main(args)endfunction p._main(args)local bold = _ne(args.bold) or _ne(args.boldlink) or _ne(args.boldname)local italic = _ne(args.italic) or _ne(args.italics)local dontBrace = _ne(args.brace) or _ne(args.braceinside)local code = _ne(args.code) or _ne(args.tt)local show_result = _ne(args._show_result)-- Build the link partlocal titlePart = linkTitle(args)if bold then titlePart = "'''" .. titlePart .. "'''" endif _ne(args.nowrapname) then titlePart = '<span class="nowrap">' .. titlePart .. '</span>' end-- Build the argumentslocal textPart = ""local textPartBuffer = ""local codeArguments = {}local i = 2while args[i] dolocal val = args[i]textPartBuffer = textPartBuffer .. '|'if val ~= "" thenif _ne(args.nowiki) then-- Unstrip nowiki tags first because calling nw on something that already contains nowiki tags will-- mangle the nowiki strip marker and result in literal UNIQ...QINU showing upval = nw(mw.text.unstripNoWiki(val))endlocal k, v = string.match(val, "(.*)=(.*)")if not k thencodeArguments[i - 1] = valelsecodeArguments[k] = vendif italic then val = '<span style="font-style:italic;">' .. val .. '</span>' endtextPart = textPart .. textPartBuffer .. valtextPartBuffer = ""endi = i+1end-- final wraplocal ret = titlePart .. textPartif not dontBrace then ret = nw('{{') .. ret .. nw('}}') endif _ne(args.a) then ret = nw('*') .. ' ' .. ret endif _ne(args.kbd) then ret = '<kbd>' .. ret .. '</kbd>' endif code thenret = '<code>' .. ret .. '</code>'elseif _ne(args.plaincode) thenret = '<code style="border:none;background:transparent;">' .. ret .. '</code>'endif _ne(args.nowrap) then ret = '<span class="nowrap">' .. ret .. '</span>' end--[[ Wrap as html?? local span = mw.html.create('span')span:wikitext(ret)--]]if _ne(args.debug) then ret = ret .. '\n<pre>' .. mw.text.encode(mw.dumpObject(args)) .. '</pre>' endif show_result thenlocal result = mw.getCurrentFrame():expandTemplate{title = "Template:" .. args[1], args = codeArguments}ret = ret .. " → " .. resultendreturn retendreturn p
🔥 Popular: 首页广州閩南語會話手冊Special:搜索中东中国行政区划国际电话区号列表京都府联合国教科文组织世界遗产名录西歐File:Vietnam Regions Map (zh-hans)-越南地图.png杭州巧家会泽富源威信中欧欧洲亚美尼亚广州白云国际机场汝城长征湄潭关岭京都市安顺宜章毕节意大利非洲中亚阿姆斯特丹Special:最近更改File:Map of India (zh-hans)-印度地图.png柏林/東部巴塞罗那文化Wiki Travel:地理分层File:Map-USA-Regions (zh-hans)-美国地图.png列支敦士登關西地方语言Wiki Travel:机器人Wiki Travel:免责声明北美洲瑞金新山Wiki Travel:互助客栈东南亚福州话会话手册格鲁吉亚User:Theklan喬科大田毛里求斯File:Map of Asia (zh-hans)-亚洲地图.png广州 (消歧义)印度京都巴尔干德國Category:会话手册常山摩爾曼斯克州黑水车臣格陵兰Wiki Travel:Resources/中山公交B1路线不丹南美洲Wiki Travel:指南条目土耳其語會話手冊新北File:Wikimania 2022 Vector (2022) Presentation.pdf马来语会话手册越南语会话手册File:Wikipedia 2006 1.pdfWiki Travel:Twinkle马来西亚