http://proplan.55bet-pro.com/wiki/index.php?action=history&feed=atom&title=M%C3%B3dulo%3AHatnote_listMódulo:Hatnote list - Histórico de revisão-55BET Pro2026-03-14T18:59:39ZHistórico de revisões para esta página neste wikiMediaWiki 1.42.7http://proplan.55bet-pro.com/wiki/index.php?title=M%C3%B3dulo:Hatnote_list&diff=109&oldid=prevMódulo:Hatnote list - Histórico de revisão-55BET Pro2024-06-27T11:11:56Z<p>uma edição</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<tr class="diff-title" lang="pt-BR">
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">← Edição anterior</td>
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">Edição das 08h11min de 27 de junho de 2024</td>
</tr><tr><td colspan="2" class="diff-notice" lang="pt-BR"><div class="mw-diff-empty">(Sem diferença)</div>
</td></tr></table>Henryzordhttp://proplan.55bet-pro.com/wiki/index.php?title=M%C3%B3dulo:Hatnote_list&diff=108&oldid=prevMódulo:Hatnote list - Histórico de revisão-55BET Pro2023-11-13T21:00:31Z<p>Updated from sandbox: added support for punctuation collapse when text is italicized. The update's content includes changes by users Johnuniq, Dexxor, and Nihiltres.</p>
<p><b>Página nova</b></p><div>--------------------------------------------------------------------------------<br />
-- Module:Hatnote list --<br />
-- --<br />
-- This module produces and formats lists for use in hatnotes. In particular, --<br />
-- it implements the for-see list, i.e. lists of "For X, see Y" statements, --<br />
-- as used in {{about}}, {{redirect}}, and their variants. Also introduced --<br />
-- are andList & orList helpers for formatting lists with those conjunctions. --<br />
--------------------------------------------------------------------------------<br />
<br />
local mArguments --initialize lazily<br />
local mFormatLink = require('Module:Format link')<br />
local mHatnote = require('Module:Hatnote')<br />
local libraryUtil = require('libraryUtil')<br />
local checkType = libraryUtil.checkType<br />
local p = {}<br />
<br />
--------------------------------------------------------------------------------<br />
-- List stringification helper functions<br />
--<br />
-- These functions are used for stringifying lists, usually page lists inside<br />
-- the "Y" portion of "For X, see Y" for-see items.<br />
--------------------------------------------------------------------------------<br />
<br />
--default options table used across the list stringification functions<br />
local stringifyListDefaultOptions = {<br />
conjunction = "and",<br />
separator = ",",<br />
altSeparator = ";",<br />
space = " ",<br />
formatted = false<br />
}<br />
<br />
--Searches display text only<br />
local function searchDisp(haystack, needle)<br />
return string.find(<br />
string.sub(haystack, (string.find(haystack, '|') or 0) + 1), needle<br />
)<br />
end<br />
<br />
-- Stringifies a list generically; probably shouldn't be used directly<br />
local function stringifyList(list, options)<br />
-- Type-checks, defaults, and a shortcut<br />
checkType("stringifyList", 1, list, "table")<br />
if #list == 0 then return nil end<br />
checkType("stringifyList", 2, options, "table", true)<br />
options = options or {}<br />
for k, v in pairs(stringifyListDefaultOptions) do<br />
if options[k] == nil then options[k] = v end<br />
end<br />
local s = options.space<br />
-- Format the list if requested<br />
if options.formatted then<br />
list = mFormatLink.formatPages(<br />
{categorizeMissing = mHatnote.missingTargetCat}, list<br />
)<br />
end<br />
-- Set the separator; if any item contains it, use the alternate separator<br />
local separator = options.separator<br />
for k, v in pairs(list) do<br />
if searchDisp(v, separator) then<br />
separator = options.altSeparator<br />
break<br />
end<br />
end<br />
-- Set the conjunction, apply Oxford comma, and force a comma if #1 has "§"<br />
local conjunction = s .. options.conjunction .. s<br />
if #list == 2 and searchDisp(list[1], "§") or #list > 2 then<br />
conjunction = separator .. conjunction<br />
end<br />
-- Return the formatted string<br />
return mw.text.listToText(list, separator .. s, conjunction)<br />
end<br />
<br />
--DRY function<br />
function p.conjList (conj, list, fmt)<br />
return stringifyList(list, {conjunction = conj, formatted = fmt})<br />
end<br />
<br />
-- Stringifies lists with "and" or "or"<br />
function p.andList (...) return p.conjList("and", ...) end<br />
function p.orList (...) return p.conjList("or", ...) end<br />
<br />
--------------------------------------------------------------------------------<br />
-- For see<br />
--<br />
-- Makes a "For X, see [[Y]]." list from raw parameters. Intended for the<br />
-- {{about}} and {{redirect}} templates and their variants.<br />
--------------------------------------------------------------------------------<br />
<br />
--default options table used across the forSee family of functions<br />
local forSeeDefaultOptions = {<br />
andKeyword = 'and',<br />
title = mw.title.getCurrentTitle().text,<br />
otherText = 'other uses',<br />
forSeeForm = 'For %s, see %s.',<br />
}<br />
<br />
--Collapses duplicate punctuation at end of string, ignoring italics and links<br />
local function punctuationCollapse (text)<br />
return text:match("[.?!]('?)%1(%]?)%2%.$") and text:sub(1, -2) or text<br />
end<br />
<br />
-- Structures arguments into a table for stringification, & options<br />
function p.forSeeArgsToTable (args, from, options)<br />
-- Type-checks and defaults<br />
checkType("forSeeArgsToTable", 1, args, 'table')<br />
checkType("forSeeArgsToTable", 2, from, 'number', true)<br />
from = from or 1<br />
checkType("forSeeArgsToTable", 3, options, 'table', true)<br />
options = options or {}<br />
for k, v in pairs(forSeeDefaultOptions) do<br />
if options[k] == nil then options[k] = v end<br />
end<br />
-- maxArg's gotten manually because getArgs() and table.maxn aren't friends<br />
local maxArg = 0<br />
for k, v in pairs(args) do<br />
if type(k) == 'number' and k > maxArg then maxArg = k end<br />
end<br />
-- Structure the data out from the parameter list:<br />
-- * forTable is the wrapper table, with forRow rows<br />
-- * Rows are tables of a "use" string & a "pages" table of pagename strings<br />
-- * Blanks are left empty for defaulting elsewhere, but can terminate list<br />
local forTable = {}<br />
local i = from<br />
local terminated = false<br />
-- If there is extra text, and no arguments are given, give nil value<br />
-- to not produce default of "For other uses, see foo (disambiguation)"<br />
if options.extratext and i > maxArg then return nil end<br />
-- Loop to generate rows<br />
repeat<br />
-- New empty row<br />
local forRow = {}<br />
-- On blank use, assume list's ended & break at end of this loop<br />
forRow.use = args[i]<br />
if not args[i] then terminated = true end<br />
-- New empty list of pages<br />
forRow.pages = {}<br />
-- Insert first pages item if present<br />
table.insert(forRow.pages, args[i + 1])<br />
-- If the param after next is "and", do inner loop to collect params<br />
-- until the "and"'s stop. Blanks are ignored: "1|and||and|3" → {1, 3}<br />
while args[i + 2] == options.andKeyword do<br />
if args[i + 3] then<br />
table.insert(forRow.pages, args[i + 3])<br />
end<br />
-- Increment to next "and"<br />
i = i + 2<br />
end<br />
-- Increment to next use<br />
i = i + 2<br />
-- Append the row<br />
table.insert(forTable, forRow)<br />
until terminated or i > maxArg<br />
<br />
return forTable<br />
end<br />
<br />
-- Stringifies a table as formatted by forSeeArgsToTable<br />
function p.forSeeTableToString (forSeeTable, options)<br />
-- Type-checks and defaults<br />
checkType("forSeeTableToString", 1, forSeeTable, "table", true)<br />
checkType("forSeeTableToString", 2, options, "table", true)<br />
options = options or {}<br />
for k, v in pairs(forSeeDefaultOptions) do<br />
if options[k] == nil then options[k] = v end<br />
end<br />
-- Stringify each for-see item into a list<br />
local strList = {}<br />
if forSeeTable then<br />
for k, v in pairs(forSeeTable) do<br />
local useStr = v.use or options.otherText<br />
local pagesStr =<br />
p.andList(v.pages, true) or<br />
mFormatLink._formatLink{<br />
categorizeMissing = mHatnote.missingTargetCat,<br />
link = mHatnote.disambiguate(options.title)<br />
}<br />
local forSeeStr = string.format(options.forSeeForm, useStr, pagesStr)<br />
forSeeStr = punctuationCollapse(forSeeStr)<br />
table.insert(strList, forSeeStr)<br />
end<br />
end<br />
if options.extratext then table.insert(strList, punctuationCollapse(options.extratext..'.')) end<br />
-- Return the concatenated list<br />
return table.concat(strList, ' ')<br />
end<br />
<br />
-- Produces a "For X, see [[Y]]" string from arguments. Expects index gaps<br />
-- but not blank/whitespace values. Ignores named args and args < "from".<br />
function p._forSee (args, from, options)<br />
local forSeeTable = p.forSeeArgsToTable(args, from, options)<br />
return p.forSeeTableToString(forSeeTable, options)<br />
end<br />
<br />
-- As _forSee, but uses the frame.<br />
function p.forSee (frame, from, options)<br />
mArguments = require('Module:Arguments')<br />
return p._forSee(mArguments.getArgs(frame), from, options)<br />
end<br />
<br />
return p</div>infobox>Nihiltres