「模組:Hatnote list」:修訂間差異

增加 437 位元組 、​ 2025年5月14日 (星期三)
無編輯摘要
imported>DC
(建立內容為「-------------------------------------------------------------------------------- -- Module:Hatnote list --…」的新頁面)
 
DC對話 | 貢獻
無編輯摘要
 
第9行: 第9行:


local mArguments --initialize lazily
local mArguments --initialize lazily
local mFormatLink = require('Module:Format link')
local mHatnote = require('Module:Hatnote')
local mHatnote = require('Module:Hatnote')
local libraryUtil = require('libraryUtil')
local libraryUtil = require('libraryUtil')
第28行: 第29行:
altSeparator = ";",
altSeparator = ";",
space = "",
space = "",
formatted = false
formatted = false,
boldfaced = false,
quotes = false
}
}
--Searches display text only
local function searchDisp(haystack, needle)
return string.find(
string.sub(haystack, (string.find(haystack, '|') or 0) + 1), needle
)
end


-- Stringifies a list generically; probably shouldn't be used directly
-- Stringifies a list generically; probably shouldn't be used directly
function stringifyList(list, options)
local function stringifyList(list, options)
-- Type-checks, defaults, and a shortcut
-- Type-checks, defaults, and a shortcut
checkType("stringifyList", 1, list, "table")
checkType("stringifyList", 1, list, "table")
第43行: 第53行:
local s = options.space
local s = options.space
-- Format the list if requested
-- Format the list if requested
if options.formatted then list = mHatnote.formatPages(unpack(list)) end
if options.formatted then
list = mFormatLink.formatPages(
{}, list
)
end
-- Set the separator; if any item contains it, use the alternate separator
-- Set the separator; if any item contains it, use the alternate separator
local separator = options.separator
local separator = options.separator
--searches display text only
function searchDisp(t, f)
return string.find(string.sub(t, (string.find(t, '|') or 0) + 1), f)
end
for k, v in pairs(list) do
for k, v in pairs(list) do
-- 本地化注意
if options.boldfaced then
list[k] = '\'\'\'' .. list[k] .. '\'\'\''
end
if options.quotes then
list[k] = '「' .. list[k] .. '」'
end
if searchDisp(v, separator) then
if searchDisp(v, separator) then
separator = options.altSeparator
separator = options.altSeparator
第68行: 第85行:


--DRY function
--DRY function
function conjList (conj, list, fmt)
-- 本地化注意
return stringifyList(list, {conjunction = conj, formatted = fmt})
function conjList (conj, list, fmt, bold, quo)
return stringifyList(list, {conjunction = conj, formatted = fmt, boldfaced = bold, quotes=quo})
end
end


第90行: 第108行:
title = mw.title.getCurrentTitle().text,
title = mw.title.getCurrentTitle().text,
otherText = '其他用法',
otherText = '其他用法',
forSeeForm = '關於%s,請參見%s。',
forSeeForm = '关于%s,请见%s。',
}
}


第154行: 第172行:
-- until the "and"'s stop. Blanks are ignored: "1|and||and|3" → {1, 3}
-- until the "and"'s stop. Blanks are ignored: "1|and||and|3" → {1, 3}
while args[i + 2] == options.andKeyword do
while args[i + 2] == options.andKeyword do
if args[i + 3] then  
if args[i + 3] then
table.insert(forRow.pages, args[i + 3])
table.insert(forRow.pages, args[i + 3])
end
end
第165行: 第183行:
table.insert(forTable, forRow)
table.insert(forTable, forRow)
until terminated or i > maxArg
until terminated or i > maxArg
 
return forTable
return forTable
end
end
第183行: 第201行:
for k, v in pairs(forSeeTable) do
for k, v in pairs(forSeeTable) do
local useStr = v.use or options.otherText
local useStr = v.use or options.otherText
local pagesStr = p.andList(v.pages, true) or mHatnote._formatLink(mHatnote.disambiguate(options.title))
-- 本地化注意
local pagesStr = p.andList(v.pages, true, true, true) or '「\'\'\'' .. mFormatLink._formatLink{link = mHatnote.disambiguate(options.title)} .. '\'\'\'」'
local forSeeStr = string.format(options.forSeeForm, useStr, pagesStr)
local forSeeStr = string.format(options.forSeeForm, useStr, pagesStr)
forSeeStr = punctuationCollapse(forSeeStr)
forSeeStr = punctuationCollapse(forSeeStr)
第189行: 第208行:
end
end
end
end
if options.extratext then table.insert(strList, punctuationCollapse(options.extratext..'.')) end
if options.extratext then table.insert(strList, punctuationCollapse(options.extratext..'')) end
-- Return the concatenated list
-- Return the concatenated list
return table.concat(strList, ' ')
return table.concat(strList)
end
end


1,319

次編輯