Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Hatnote list: Difference between revisions

From Kenshi Wiki
Created page with "-------------------------------------------------------------------------------- -- Module:Hatnote list -- -- -- -- This module produces and formats lists for use in hatnotes. In particular, -- -- it implements the for-see list, i.e. lists of "For X, see Y" statements, -- -- as used in {{about}}, {{redirect}}, and their variants. Also introd..."
 
No edit summary
 
Line 63: Line 63:
end
end
end
end
-- Set the conjunction, apply Oxford comma, and force a comma if #1 has " "
-- Set the conjunction, apply Oxford comma, and force a comma if #1 has "§"
local conjunction = s .. options.conjunction .. s
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
conjunction = separator .. conjunction
conjunction = separator .. conjunction
end
end
Line 96: Line 96:
}
}


--Collapses duplicate punctuation
--Collapses duplicate punctuation at end of string, ignoring italics and links
local function punctuationCollapse (text)
local function punctuationCollapse (text)
local replacements = {
return text:match("[.?!]('?)%1(%]?)%2%.$") and text:sub(1, -2) or text
["%.%.$"] = ".",
["%?%.$"] = "?",
["%!%.$"] = "!",
["%.%]%]%.$"] = ".]]",
["%?%]%]%.$"] = "?]]",
["%!%]%]%.$"] = "!]]"
}
for k, v in pairs(replacements) do text = string.gsub(text, k, v) end
return text
end
end


Line 148: Line 139:
table.insert(forRow.pages, args[i + 1])
table.insert(forRow.pages, args[i + 1])
-- If the param after next is "and", do inner loop to collect params
-- If the param after next is "and", do inner loop to collect params
-- 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
Line 161: Line 152:
table.insert(forTable, forRow)
table.insert(forTable, forRow)
until terminated or i > maxArg
until terminated or i > maxArg
 
return forTable
return forTable
end
end