Module:Hatnote list: Difference between revisions
Content deleted Content added
Updated from sandbox to use Module:Format link, and export conjList (credit Jackmcbarn), and tag functions local, and extract searchDisp as a nested function |
Undid revision 1062157581 by Nihiltres (talk) Temp undo as Template:See also now throws errors like "Lua error: bad argument #1 to 'title.new' (number or string expected, got nil)." (for example in article Bronshtein and Semendyayev). |
||
Line 9:
local mArguments --initialize lazily
local mHatnote = require('Module:Hatnote')
local libraryUtil = require('libraryUtil')
Line 30 ⟶ 29:
formatted = 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")
Line 50 ⟶ 42:
local s = options.space
-- Format the list if requested
if options.formatted then list = mHatnote.formatPages(unpack(list)) 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 searchDisp(v, separator) then
Line 73 ⟶ 65:
--DRY function
function
return stringifyList(list, {conjunction = conj, formatted = fmt})
end
-- Stringifies lists with "and" or "or"
function p.andList (...) return
function p.orList (...) return
--------------------------------------------------------------------------------
Line 97 ⟶ 89:
--Collapses duplicate punctuation
local replacements = {
["%.%.$"] = ".",
Line 179 ⟶ 171:
for k, v in pairs(forSeeTable) do
local useStr = v.use or options.otherText
▲ link = mHatnote.disambiguate(options.title)
local forSeeStr = string.format(options.forSeeForm, useStr, pagesStr)
forSeeStr = punctuationCollapse(forSeeStr)
|