Module:段落頂註
跳转到导航
跳转到搜索
本模組用於頂註模板,用法見各模板文檔。
本模組依賴模組:頂註中的hatnote.getArgs(frame)
和hatnote.formatLinks(links)
。
模組內容
hatnote
本模組的返回值。
hatnote.main(frame)
hatnote._main(args)
- 對應{{段落頂註}}。
hatnote.mainarticle(frame)
- 對應{{主}}。
hatnote.further(frame)
- 對應{{更多信息}}。
hatnote.seealso(frame)
- 對應{{参见}}。
hatnote.wrapper(content, prefix)
- 接收內容表
content
和前綴字串prefix
,返回頂註結果。
參見
local hatnote = {}
hatnote.getArgs = require('Module:頂註').getArgs
hatnote.formatLinks = require('Module:頂註').formatLinks
local ts = require('Module:参数').loadData('Module:頂註/參數')
local function invoke(functio, prefix, ...)
local wrappers = { ... }
return function(frame)
local args = hatnote.getArgs(frame, wrappers)
return hatnote[functio](args, prefix)
end
end
hatnote.mainarticle = invoke('wrapper', ts:msg('主'), 'Template:主')
hatnote.further = invoke('wrapper', ts:msg('更多'), 'Template:更多信息', 'Template:更多資訊')
hatnote.seealso = invoke('wrapper', ts:msg('參見'), 'Template:参见')
function hatnote.wrapper(content, prefix) -- 輸出結果
content = hatnote.formatLinks(content or {})
prefix = prefix or ''
local links
if content[3] then
links = table.concat(content, ts:msg('、'))
else
links = table.concat(content, ts:msg('和'))
end
if content[1] and prefix ~= '' then
links = string.format('%s%s', ts:msg(':'), links)
end
local wikitext = mw.text.tag('div', { class = 'hatnote hatnote-section' }, string.format('%s%s', prefix, links))
return wikitext
end
hatnote.main = invoke('_main', nil, 'Template:段落頂註', 'Template:段落顶注')
function hatnote._main(args)
local prefix = table.remove(args, 1)
return hatnote.wrapper(args, prefix)
end
return hatnote