Module:Multiformat
| This module is rated as alpha. It is ready for limited use and third-party feedback. It may be used on a small number of pages, but should be monitored closely. Suggestions for new features or adjustments to input and output are welcome. |
| Editing of this module by new or unregistered users is currently disabled. See the protection policy and protection log for more details. If you cannot edit this module and you wish to make a change, you can submit an edit request, discuss changes on the talk page, request unprotection, log in, or create an account. |
| This module depends on the following other modules: |
| Description | Formats multiple numbered arguments and outputs them in order, etc. |
|---|---|
| Status | Alpha |
| Updated | June 1, 2026 (4 days ago) |
| Dependencies | Module:Escape_input |
Formats multiple numbered arguments and outputs them in order, etc.
This module allows for formatting of multiple numbered arguments together in an output string.
Syntax:
- Many typical Lua character sequences (i.e.
\n) will insert the relevant character into the output. - %ARG% is the argument value
- %ARGNUM% is the argument number'
| Sequence | Result |
|---|---|
\{
|
{
|
\}
|
}
|
\[
|
[
|
\]
|
]
|
\p
|
|
|
\e
|
=
|
\_
|
|
Documentation
Package items
multiformat._main( pargs, cargs )(function)- Main entrypoint for formatting output string
- Parameters:
pargsThe arguments from the template call (table)cargsThe arguments from the module call (table)cargs.startAllthe beginning formatting string sequence (string)cargs.endAllthe ending formatting string sequence (string)cargs.formatthe format string (string)cargs.firstArgthe first numbered argument to begin formatting (number)cargs.prefixthe argument prefix (string)cargs.suffixthe argument suffix (string)cargs.nowikiWhether the module is encased in nowiki tags (boolean)cargs.emptyThe message to give if no arguments are specified (string)
- Returns: Output to preprocess
multiformat.main( frame )(function)- Template call
- Parameter:
framecalling frame (Frame) - Returns: Output wikitext
- Usage:
{{#invoke:Multiformat|main|startAll=start|endAll=end|formatString=String with %ARG% to replace with current arguments|firstArg=number of first arg}} multiformat._nArgs( pargs, cargs )(function)- Counts the number of arguments which match a particular format
- Parameters:
- Returns: Number of numbered parameters supplied
multiformat.nArgs( frame )(function)- Template call
- Parameter:
framecalling frame (Frame) - Returns: Output wikitext
- Usage:
{{#invoke:Multiformat|nArgs}}
--- Formats multiple numbered arguments and outputs them in order, etc.
--
-- @module multiformat
-- @alias p
-- @require Module:Escape_input
-- @release alpha
local p = {}
local yn = require("Module:Yesno")
--- Main entrypoint for formatting output string
--
-- @param {table} pargs The arguments from the template call
-- @param {table} cargs The arguments from the module call
-- @param {string} cargs.startAll the beginning formatting string sequence
-- @param {string} cargs.endAll the ending formatting string sequence
-- @param {string} cargs.format the format string
-- @param {number} cargs.firstArg the first numbered argument to begin formatting
-- @param {string} cargs.prefix the argument prefix
-- @param {string} cargs.suffix the argument suffix
-- @param {boolean} cargs.nowiki Whether the module is encased in nowiki tags
-- @param {string} cargs.empty The message to give if no arguments are specified
-- @return Output to preprocess
function p._main(pargs, cargs)
local nowiki = yn(cargs.nowiki) or false
local escape
if nowiki then
escape = function( s ) return mw.text.unstripNoWiki( s ) end
else
escape = require("Module:Escape input").escape
end
local startAll = escape(cargs.startAll or '')
local endAll = escape(cargs.endAll or '')
local formatString = escape(cargs.format)
local currArg = tonumber(cargs.firstArg) or 1
local argPrefix = escape(cargs.prefix or '')
local argSuffix = escape(cargs.suffix or '')
local outArr = {}
if pargs[argPrefix .. currArg .. argSuffix] == nil then return escape(cargs.empty or '') end
table.insert(outArr, startAll)
while pargs[argPrefix .. currArg .. argSuffix] ~= nil do
table.insert(outArr, tostring(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(formatString, '%%ARGNUM%%', currArg), '%%ARG%%', pargs[argPrefix .. currArg .. argSuffix]), '\\%%', '%')))
currArg = currArg + 1
end
table.insert(outArr, endAll)
return table.concat(outArr)
end
--- Template call
--
-- @param {Frame} frame calling frame
-- @return Output wikitext
-- @usage {{#invoke:Multiformat|main|startAll=start|endAll=end|formatString=String with %ARG% to replace with current arguments|firstArg=number of first arg}}
function p.main(frame)
local pargs = frame:getParent() ~= nil and frame:getParent().args or error("Error occurred while fetching wrapping template arguments for multiformat", 0)
local cargs = frame.args
return frame:preprocess(p._main(pargs, cargs))
end
--- Counts the number of arguments which match a particular format
--
-- @param {table} pargs The arguments from the template call
-- @param {table} cargs The arguments from the module call
-- @param {number} cargs.firstArg the first numbered argument to begin formatting
-- @param {string} cargs.prefix the argument prefix
-- @param {string} cargs.prefix the argument suffix
-- @return Number of numbered parameters supplied
function p._nArgs(pargs, cargs)
local currArg = tonumber(cargs.firstArg) or 1
local nowiki = yn(cargs.nowiki) or false
local escape
if nowiki then
escape = function( s ) return mw.text.unstripNoWiki( s ) end
else
escape = require("Module:Escape input").escape
end
local argPrefix = escape(cargs.prefix or '')
local argSuffix = escape(cargs.suffix or '')
local count = 0
while pargs[argPrefix .. currArg .. argSuffix] ~= nil do
count = count + 1
currArg = currArg + 1
end
return count
end
--- Template call
--
-- @param {Frame} frame calling frame
-- @return Output wikitext
-- @usage {{#invoke:Multiformat|nArgs}}
function p.nArgs(frame)
local pargs = frame:getParent() ~= nil and frame:getParent().args or error("Error occurred while fetching wrapping template arguments for multiformat", 0)
local cargs = frame.args
return p._nArgs(pargs, cargs)
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.