Module:Hatnote list:修订间差异
删除的内容 添加的内容
enwiki>Nihiltres Updated from sandbox: added support for punctuation collapse when text is italicized. The update's content includes changes by users Johnuniq, Dexxor, and Nihiltres. |
IdleTap-bot(留言 | 贡献) 导入自求闻百科 |
||
第9行:
local mArguments --initialize lazily
local mHatnote = require('Module:Hatnote')
local libraryUtil = require('libraryUtil')
第23行 ⟶ 第22行:
--default options table used across the list stringification functions
-- 本地化注意
local stringifyListDefaultOptions = {
conjunction = "
separator = "
altSeparator = "
space = "
formatted = false,
boldfaced = false,
quotes = false
}
--Searches display text only▼
local function searchDisp(haystack, needle)▼
string.sub(haystack, (string.find(haystack, '|') or 0) + 1), needle▼
)▼
end▼
-- Stringifies a list generically; probably shouldn't be used directly
-- Type-checks, defaults, and a shortcut
checkType("stringifyList", 1, list, "table")
第50行 ⟶ 第45行:
local s = options.space
-- Format the list if requested
if options.formatted then list = mHatnote.formatPages(unpack(list)) end
end▼
-- Set the separator; if any item contains it, use the alternate separator
local separator = options.separator
▲ end
for k, v in pairs(list) do
-- 本地化注意
if options.boldfaced then
list[k] = '\'\'\'' .. list[k] .. '\'\'\''
if options.quotes then
list[k] = '「' .. list[k] .. '」'
if searchDisp(v, separator) then
separator = options.altSeparator
第65行 ⟶ 第67行:
-- Set the conjunction, apply Oxford comma, and force a comma if #1 has "§"
local conjunction = s .. options.conjunction .. s
-- 本地化注意
if #list == 2 and searchDisp(list[1], "§") or #list > 2 then▼
▲ -- if #list == 2 and searchDisp(list[1], "§") or #list > 2 then
▲ end
-- conjunction = separator .. conjunction
-- end
-- Return the formatted string
return mw.text.listToText(list, separator .. s, conjunction)
第73行 ⟶ 第77行:
--DRY function
-- 本地化注意
function
return stringifyList(list, {conjunction = conj, formatted = fmt, boldfaced = bold, quotes=quo})
end
-- Stringifies lists with "and" or "or"
-- 本地化注意
function p.andList (...) return p.conjList("and", ...) end▼
function p.
--------------------------------------------------------------------------------
第89行 ⟶ 第95行:
--default options table used across the forSee family of functions
-- 本地化注意
local forSeeDefaultOptions = {
andKeyword = '
title = mw.title.getCurrentTitle().text,
otherText = '
forSeeForm = '
}
--Collapses duplicate punctuation
-- 本地化注意
local replacements = {
["%.%.$"] = ".",
["%?%.$"] = "?",
["%!%.$"] = "!",
["%.%]%]%.$"] = ".]]",
["%?%]%]%.$"] = "?]]",
["%!%]%]%.$"] = "!]]",
["%。%。$"] = "。",
["%?%。$"] = "?",
["%!%。$"] = "!",
["%。%]%]%。$"] = "。]]",
["%?%]%]%。$"] = "?]]",
["%!%]%]%。$"] = "!]]"
for k, v in pairs(replacements) do text = string.gsub(text, k, v) end
return text
end
第141行 ⟶ 第164行:
-- until the "and"'s stop. Blanks are ignored: "1|and||and|3" → {1, 3}
while args[i + 2] == options.andKeyword do
if args[i + 3] then
table.insert(forRow.pages, args[i + 3])
end
第152行 ⟶ 第175行:
table.insert(forTable, forRow)
until terminated or i > maxArg
return forTable
end
第170行 ⟶ 第193行:
for k, v in pairs(forSeeTable) do
local useStr = v.use or options.otherText
-- 本地化注意
local forSeeStr = string.format(options.forSeeForm, useStr, pagesStr)
forSeeStr = punctuationCollapse(forSeeStr)
第181行 ⟶ 第200行:
end
end
if options.extratext then table.insert(strList, punctuationCollapse(options.extratext..'
-- Return the concatenated list
return table.concat(strList
end
| |||