Module:Hatnote:修订间差异
删除的内容 添加的内容
无编辑摘要 |
|||
(未显示5个用户的7个中间版本) | |||
第9行:
local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg
local mArguments -- lazily initialise [[Module:Arguments]]
local yesno -- lazily initialise [[Module:Yesno]]
local formatLink -- lazily initialise [[Module:Format link]] ._formatLink
local p = {}
第28行 ⟶ 第30行:
-- Removes the initial colon from a string, if present.
return s:match('^:?(.*)')
end
function p.defaultClasses(inline)
-- Provides the default hatnote classes as a space-separated string; useful
-- for hatnote-manipulation modules like [[Module:Hatnote group]].
return
(inline == 1 and 'hatnote-inline' or 'hatnote') .. ' ' ..
'navigation-not-searchable'
end
function p.disambiguate(page, disambiguator)
-- Formats a page title with a disambiguation parenthetical,
-- i.e. "Example" → "Example (disambiguation)".
checkType('disambiguate', 1, page, 'string')
checkType('disambiguate', 2, disambiguator, 'string', true)
disambiguator = disambiguator or '消歧义'
return mw.ustring.format('%s (%s)', page, disambiguator)
end
第48行 ⟶ 第67行:
end
return 0
end
第87行 ⟶ 第81行:
local helpText
if helpLink then
helpText = '
else
helpText = ''
第93行 ⟶ 第87行:
-- Make the category text.
local category
if not title.isTalkPage
and title.namespace ~= 2 -- Don't categorise userspace
and yesno(addTrackingCategory) ~= false -- Allow opting out
then
category = '有错误的顶注模板'
category = mw.ustring.format(
'[[%s:%s]]',
mw.site.namespaces[14].name,
第103行 ⟶ 第100行:
category = ''
end
return
'<strong class="error">
msg,
helpText,
第111行 ⟶ 第108行:
end
local curNs = mw.title.getCurrentTitle().namespace
p.missingTargetCat =
--Default missing target category, exported for use in related modules
((curNs == 0) or (curNs == 14)) and
'顶注模板包含不存在页面的条目' or nil
function p.quote(title)
--Wraps titles in quotation marks. If the title starts/ends with a quotation
--mark, kerns that side as with {{-'}}
local quotationMarks = {
["'"]=true, ['"']=true, ['“']=true, ["‘"]=true, ["「"]=true, ["『"]=true, ['”']=true, ["’"]=true, ["」"]=true, ["』"]=true
}
local quoteLeft, quoteRight = -- Test if start/end are quotation marks
quotationMarks[string.sub(title, 1, 1)],
quotationMarks[string.sub(title, -1, -1)]
if quoteLeft or quoteRight then
title = mw.html.create("span"):wikitext(title)
end
if quoteLeft then title:css("padding-left", "0.15em") end
if quoteRight then title:css("padding-right", "0.15em") end
return '「' .. tostring(title) .. '」'
end
--------------------------------------------------------------------------------
-- Hatnote 顶注
--
-- Produces standard hatnote text. Implements the {{hatnote}} template.
-- 产生标准顶注文字。实现{{hatnote}}模板
--------------------------------------------------------------------------------
第187行 ⟶ 第141行:
local args = getArgs(frame)
local s = args[1]
if not s then
return p.makeWikitextError(
'
'Template:Hatnote#
args.category
)
end
return p._hatnote(s, {
selfref = args.selfref
})
end
第204行 ⟶ 第158行:
checkType('_hatnote', 2, options, 'table', true)
options = options or {}
local
local hatnote = mw.html.create(inline == 1 and 'span' or 'div')
local
if type(options.extraclasses) == 'string' then
end
hatnote
:attr('role', 'note')
:addClass(p.defaultClasses(inline))
:addClass(extraclasses)
:addClass(options.selfref and 'selfref' or nil)
:wikitext(s)
return mw.getCurrentFrame():extensionTag{
name = 'templatestyles', args = { src = 'Module:Hatnote/styles.css' }
} .. tostring(hatnote)
end
|