http://proplan.55bet-pro.com/wiki/index.php?action=history&feed=atom&title=M%C3%B3dulo%3AHatnote_list Módulo:Hatnote list - Histórico de revisão-55BET Pro 2026-03-14T18:59:39Z Histórico de revisões para esta página neste wiki MediaWiki 1.42.7 http://proplan.55bet-pro.com/wiki/index.php?title=M%C3%B3dulo:Hatnote_list&diff=109&oldid=prev Módulo:Hatnote list - Histórico de revisão-55BET Pro 2024-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> Henryzord http://proplan.55bet-pro.com/wiki/index.php?title=M%C3%B3dulo:Hatnote_list&diff=108&oldid=prev Módulo:Hatnote list - Histórico de revisão-55BET Pro 2023-11-13T21:00:31Z <p>Updated from sandbox: added support for punctuation collapse when text is italicized. The update&#039;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 &quot;For X, see Y&quot; statements, --<br /> -- as used in {{about}}, {{redirect}}, and their variants. Also introduced --<br /> -- are andList &amp; orList helpers for formatting lists with those conjunctions. --<br /> --------------------------------------------------------------------------------<br /> <br /> local mArguments --initialize lazily<br /> local mFormatLink = require(&#039;Module:Format link&#039;)<br /> local mHatnote = require(&#039;Module:Hatnote&#039;)<br /> local libraryUtil = require(&#039;libraryUtil&#039;)<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 &quot;Y&quot; portion of &quot;For X, see Y&quot; for-see items.<br /> --------------------------------------------------------------------------------<br /> <br /> --default options table used across the list stringification functions<br /> local stringifyListDefaultOptions = {<br /> conjunction = &quot;and&quot;,<br /> separator = &quot;,&quot;,<br /> altSeparator = &quot;;&quot;,<br /> space = &quot; &quot;,<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, &#039;|&#039;) or 0) + 1), needle<br /> )<br /> end<br /> <br /> -- Stringifies a list generically; probably shouldn&#039;t be used directly<br /> local function stringifyList(list, options)<br /> -- Type-checks, defaults, and a shortcut<br /> checkType(&quot;stringifyList&quot;, 1, list, &quot;table&quot;)<br /> if #list == 0 then return nil end<br /> checkType(&quot;stringifyList&quot;, 2, options, &quot;table&quot;, 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 &quot;§&quot;<br /> local conjunction = s .. options.conjunction .. s<br /> if #list == 2 and searchDisp(list[1], &quot;§&quot;) or #list &gt; 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 &quot;and&quot; or &quot;or&quot;<br /> function p.andList (...) return p.conjList(&quot;and&quot;, ...) end<br /> function p.orList (...) return p.conjList(&quot;or&quot;, ...) end<br /> <br /> --------------------------------------------------------------------------------<br /> -- For see<br /> --<br /> -- Makes a &quot;For X, see [[Y]].&quot; 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 = &#039;and&#039;,<br /> title = mw.title.getCurrentTitle().text,<br /> otherText = &#039;other uses&#039;,<br /> forSeeForm = &#039;For %s, see %s.&#039;,<br /> }<br /> <br /> --Collapses duplicate punctuation at end of string, ignoring italics and links<br /> local function punctuationCollapse (text)<br /> return text:match(&quot;[.?!](&#039;?)%1(%]?)%2%.$&quot;) and text:sub(1, -2) or text<br /> end<br /> <br /> -- Structures arguments into a table for stringification, &amp; options<br /> function p.forSeeArgsToTable (args, from, options)<br /> -- Type-checks and defaults<br /> checkType(&quot;forSeeArgsToTable&quot;, 1, args, &#039;table&#039;)<br /> checkType(&quot;forSeeArgsToTable&quot;, 2, from, &#039;number&#039;, true)<br /> from = from or 1<br /> checkType(&quot;forSeeArgsToTable&quot;, 3, options, &#039;table&#039;, 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&#039;s gotten manually because getArgs() and table.maxn aren&#039;t friends<br /> local maxArg = 0<br /> for k, v in pairs(args) do<br /> if type(k) == &#039;number&#039; and k &gt; 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 &quot;use&quot; string &amp; a &quot;pages&quot; 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 &quot;For other uses, see foo (disambiguation)&quot;<br /> if options.extratext and i &gt; 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&#039;s ended &amp; 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 &quot;and&quot;, do inner loop to collect params<br /> -- until the &quot;and&quot;&#039;s stop. Blanks are ignored: &quot;1|and||and|3&quot; → {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 &quot;and&quot;<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 &gt; 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(&quot;forSeeTableToString&quot;, 1, forSeeTable, &quot;table&quot;, true)<br /> checkType(&quot;forSeeTableToString&quot;, 2, options, &quot;table&quot;, 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..&#039;.&#039;)) end<br /> -- Return the concatenated list<br /> return table.concat(strList, &#039; &#039;)<br /> end<br /> <br /> -- Produces a &quot;For X, see [[Y]]&quot; string from arguments. Expects index gaps<br /> -- but not blank/whitespace values. Ignores named args and args &lt; &quot;from&quot;.<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(&#039;Module:Arguments&#039;)<br /> return p._forSee(mArguments.getArgs(frame), from, options)<br /> end<br /> <br /> return p</div> infobox>Nihiltres