Anonymous user
Module:Hatnote list: Difference between revisions
Updated from sandbox
m (Actually applied andList's formatted option in forSeeTableToString) |
(Updated from sandbox) |
||
Line 45:
-- Set the separator; if any item contains it, use the alternate 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
if
separator = options.altSeparator
break
Line 53 ⟶ 57:
-- Set the conjunction, apply Oxford comma, and force a comma if #1 has "§"
local conjunction = s .. options.conjunction .. s
if #list == 2 and
conjunction = separator .. conjunction
end
Line 60 ⟶ 64:
end
--DRY function
function
return stringifyList(list, {conjunction =
end
-- Stringifies
function p.
function p.orList (...) return conjList("or", ...) end
▲end
--------------------------------------------------------------------------------
Line 79 ⟶ 82:
--default options table used across the forSee family of functions
local forSeeDefaultOptions = {
andKeyword = 'and',
title = mw.title.getCurrentTitle().text,
otherText = 'other uses',
}▼
--Collapses duplicate punctuation
function punctuationCollapse (text)
local replacements = {
["%.%.$"] = ".",
["%?%.$"] = "?",
Line 90 ⟶ 98:
["%!%]%]%.$"] = "!]]"
}
for k, v in pairs(replacements) do text = string.gsub(text, k, v) end
▲}
return text
-- Structures arguments into a table for stringification, & options
Line 108 ⟶ 118:
if type(k) == 'number' and k > maxArg then maxArg = k end
end
-- Structure the data out from the parameter list:
-- * forTable is the wrapper table, with forRow rows
-- * Rows are tables of a "use" string
-- * Blanks are left empty for defaulting elsewhere, but can terminate list
local forTable = {}
local i = from
local terminated = false
--
repeat
-- New empty row
local forRow = {}
--
forRow.use = args[i]
if not args[i] then terminated = true end
-- New empty list of pages
forRow.pages = {}
--
table.insert(forRow.pages, args[i + 1])
-- If the
--
▲ while args[i + 2] == 'and' do
if args[i + 3] then
table.insert(forRow.pages, args[i + 3])
end
-- Increment to
i = i + 2
end
-- Increment to
i = i + 2
--
table.insert(forTable, forRow)
until terminated or i > maxArg
Line 145 ⟶ 154:
end
--
function p.forSeeTableToString (forSeeTable, options)
-- Type-checks and defaults
Line 154 ⟶ 163:
if options[k] == nil then options[k] = v end
end
--
local strList = {}
for k, v in pairs(forSeeTable) do
Line 160 ⟶ 169:
local pagesStr = p.andList(v.pages, true) or
mHatnote._formatLink(mHatnote.disambiguate(options.title))
local forSeeStr = string.format(options.
▲ forSeeStr = string.gsub(forSeeStr, k, v)
▲ end
table.insert(strList, forSeeStr)
end
Line 171 ⟶ 178:
-- Produces a "For X, see [[Y]]" string from arguments. Expects index gaps
-- but not blank
function p._forSee (args, from, options)
local forSeeTable = p.forSeeArgsToTable(args, from, options)
Line 178 ⟶ 184:
end
--
function p.forSee (frame, from, options)
mArguments = require('Module:Arguments')
|