Module:ParseList/doc: Difference between revisions
No edit summary |
HiddenDragon (talk | contribs) m (→Output styles) |
||
(11 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
Doc page: [[Module:ParseList/doc]] | |||
This module allows you to process a list of values (separated by a comma by default) and display them in a variety of useful formats. | This module allows you to process a list of values (separated by a comma by default) and display them in a variety of useful formats. | ||
Line 16: | Line 18: | ||
! parameter !! default !! meaning | ! parameter !! default !! meaning | ||
|- | |- | ||
| <code> | | <code>style</code> || '<code>text</code>' | ||
| The desired output format, see below for possibilities. | | The desired output format, see below for possibilities. | ||
|- | |- | ||
| <code> | | <code>type</code> || | ||
| ''Deprecated synonym for <code>style</code>.'' | |||
|- | |- | ||
| <code> | | <code>delimiter</code> || '<code>,</code>' | ||
| | | The character that should serve as a delimiter of the input list. This can actually be a string of multiple characters which will all work as a delimiter, but that usage is discouraged as it may cause confusion. | ||
|- | |- | ||
| <code>makePlural</code> || ''(empty)'' | | <code>makePlural</code> || ''(empty)'' | ||
| If provided and not blank, means that each element will be turned into a plural word. | | If provided and not blank, means that each element will be turned into a plural word. | ||
|- | |||
| <code>makeSingular</code> || ''(empty)'' | |||
| If provided and not blank, means that each element will be turned into singular. | |||
|- | |||
| <code>makeLowercase</code> || ''(empty)'' | |||
| If provided and not blank, means that each element will be made all-lowercase. | |||
|- | |||
| <code>makeLinks</code> || ''(empty)'' || | |||
If provided and not blank, means that each element will be made into a link. | |||
If any transforms like plural, singular, or lowercase were specified, the original element will be the link destination, and the transformed version the link text. E.g., the list element "Apple" would become <code><nowiki>[[Apple|apples]]</nowiki></code> if <code>makePlural</code>, <code>makeLowercase</code>, and <code>makeLinks</code> were provided. | |||
|- | |||
| <code>useTemplate</code> || ''(empty)'' || | |||
If provided, will use the provided template on each element, i.e., turn every <code>X</code> into <code><nowiki>{{Template|X}}</nowiki></code>. | |||
This is done ''after'' any transforms like plural, singular and lowercase. E.g., the list element "Apple" would become <code><nowiki>{{Template|apples}}</nowiki></code> if <code>makePlural</code>, <code>makeLowercase</code>, and <code>useTemplate</code> were provided. | |||
|- | |||
| <code>useTemplate2</code> || ''(empty)'' || | |||
If provided, will use the provided template on each element and its transformed form as two template arguments. | |||
E.g., the list element "Apple" would become <code><nowiki>{{Template|Apple|apples}}</nowiki></code> if <code>makePlural</code>, <code>makeLowercase</code>, and <code>useTemplate</code> were provided. | |||
|- | |- | ||
| <code> | | <code>textDelim</code> || '<code>, </code>' || | ||
If <code>style</code> is <code>text</code>, this is used as the delimiter for the output list. | |||
Setting this causes the default value for <code>textLastDelim</code> to be changed to the same value, since the default value of <code>textLastDelim</code> is unlikely to be useful with anything other than the default value of <code>textDelim</code>. | |||
Note that the default value is not just a comma; it's a comma followed by a space character. | |||
|- | |||
| <code>textLastDelim</code> || ''(conditional)'' || | |||
If <code>style</code> is <code>text</code>, this is used as the delimiter between the last two elements of the output list. | |||
If <code>textDelim</code> is not set (i.e., left at its default value), then the default value for this is '<code>, and </code>' such that an input list "X, Y, Z" would be turned into "X, Y, and Z". You could leave <code>textDelim</code> unset, but set <code>textLastDelim = <nowiki>, or </nowiki></code> to get the output "X, Y, or Z" instead. | |||
If <code>textDelim</code> is set, then this defaults to the same value as that. E.g., specifying <code>textDelim = <nowiki> + </nowiki></code> would transform the input list "X, Y, Z" into "X + Y + Z" without needing to also change the value of <code>textLastDelim</code>. | |||
Note: The use of <code><nowiki></code> here is to prevent leading and trailing space characters from being ignored when setting <code>textDelim</code> or <code>textLastDelim</code> to a string that should start and/or end with a space character. | |||
|} | |} | ||
The automatic | The automatic plural/singular transforms are able to recognize certain irregular plurals and handle them correctly, such as "thieves" and "quarterstaves." This is handled partly through a table of explicit special conversions like <code>staff -> staves</code>, and partly through logical rules like <code>...f --> ...ves</code>. If you find a word that produces a wrong result, it should be added to the table of explicit conversions. | ||
The <code>makeLink</code>, <code>useTemplate</code>, and <code>useTemplate2</code> arguments are mutually exclusive; when several are provided, only the first will take effect. | |||
=== Output | === Output styles === | ||
The value of the <code> | The value of the <code>style</code> parameter can be the following: | ||
{| class="wikitable" | {| class="wikitable" | ||
! value !! example output | ! value !! example output | ||
|- | |- | ||
| <code> | | <code>text</code> | ||
| {{#invoke:ParseList|main|Fighter, Cleric, Wizard}} | | {{#invoke:ParseList | main | Fighter, Cleric, Wizard }} | ||
|- | |||
| <code>simpleList</code> | |||
| {{#invoke:ParseList | main | Fighter, Cleric, Wizard | style = simpleList }} | |||
|- | |- | ||
| <code>htmlList</code> | | <code>htmlList</code> | ||
| {{#invoke:ParseList|main|Fighter, Cleric, Wizard| | | {{#invoke:ParseList | main | Fighter, Cleric, Wizard | style = htmlList }} | ||
|- | |- | ||
| <code> | | <code>htmlListNoBullets</code> | ||
| {{#invoke:ParseList|main|Fighter, Cleric, Wizard| | | {{#invoke:ParseList | main | Fighter, Cleric, Wizard | style = htmlListNoBullets }} | ||
|- | |||
| <code>htmlListNoBulletsOrMargin</code> | |||
| {{#invoke:ParseList | main | Fighter, Cleric, Wizard | style = htmlListNoBulletsOrMargin }} | |||
|- | |||
| <code>tableList</code> | |||
| {{#invoke:ParseList | main | Fighter, Cleric, Wizard | style = tableList }} | |||
|- | |||
| <code>none</code> | |||
| {{#invoke:ParseList | main | Fighter, Cleric, Wizard | style = none }} | |||
|} | |} | ||
The style <code>none</code> is useful if each element is being transformed into an HTML element such that no textual delimiters are desired. | |||
== Examples == | == Examples == | ||
Line 86: | Line 138: | ||
<pre> | <pre> | ||
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes | | {{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes | textLastDelim = <nowiki>, or </nowiki> }} | ||
</pre> | </pre> | ||
Result: | Result: | ||
: {{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes | | : {{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes | textLastDelim = <nowiki>, or </nowiki> }} | ||
=== Make Plural Links, turn into HTML list === | === Make Plural Links, turn into HTML list === | ||
<pre> | <pre> | ||
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes | | {{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes | style = htmlList }} | ||
</pre> | </pre> | ||
Result: | Result: | ||
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes | | {{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes | style = htmlList }} |
Latest revision as of 23:07, 11 October 2024
Doc page: Module:ParseList/doc
This module allows you to process a list of values (separated by a comma by default) and display them in a variety of useful formats.
{{#invoke:ParseList|main|Fighter, Cleric, Wizard}}
Becomes:
- Fighter, Cleric, and Wizard
Parameters
The first parameter is the list to be processed. The remaining parameters are optional:
parameter | default | meaning |
---|---|---|
style |
'text '
|
The desired output format, see below for possibilities. |
type |
Deprecated synonym for style .
| |
delimiter |
', '
|
The character that should serve as a delimiter of the input list. This can actually be a string of multiple characters which will all work as a delimiter, but that usage is discouraged as it may cause confusion. |
makePlural |
(empty) | If provided and not blank, means that each element will be turned into a plural word. |
makeSingular |
(empty) | If provided and not blank, means that each element will be turned into singular. |
makeLowercase |
(empty) | If provided and not blank, means that each element will be made all-lowercase. |
makeLinks |
(empty) |
If provided and not blank, means that each element will be made into a link. If any transforms like plural, singular, or lowercase were specified, the original element will be the link destination, and the transformed version the link text. E.g., the list element "Apple" would become |
useTemplate |
(empty) |
If provided, will use the provided template on each element, i.e., turn every This is done after any transforms like plural, singular and lowercase. E.g., the list element "Apple" would become |
useTemplate2 |
(empty) |
If provided, will use the provided template on each element and its transformed form as two template arguments. E.g., the list element "Apple" would become |
textDelim |
', ' |
If Setting this causes the default value for Note that the default value is not just a comma; it's a comma followed by a space character. |
textLastDelim |
(conditional) |
If If If Note: The use of |
The automatic plural/singular transforms are able to recognize certain irregular plurals and handle them correctly, such as "thieves" and "quarterstaves." This is handled partly through a table of explicit special conversions like staff -> staves
, and partly through logical rules like ...f --> ...ves
. If you find a word that produces a wrong result, it should be added to the table of explicit conversions.
The makeLink
, useTemplate
, and useTemplate2
arguments are mutually exclusive; when several are provided, only the first will take effect.
Output styles
The value of the style
parameter can be the following:
value | example output |
---|---|
text
|
Fighter, Cleric, and Wizard |
simpleList
|
Fighter, Cleric, Wizard |
htmlList
|
|
htmlListNoBullets
|
|
htmlListNoBulletsOrMargin
|
|
tableList
|
Fighter
Cleric Wizard |
none
|
FighterClericWizard |
The style none
is useful if each element is being transformed into an HTML element such that no textual delimiters are desired.
Examples
Make Links
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes }}
Result:
Make plural
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makePlural = yes }}
Result:
- Fighters, Clerics, and Wizards
Make Plural Links
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes }}
Result:
Make Plural Links, end with "or"
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes | textLastDelim = <nowiki>, or </nowiki> }}
Result:
Make Plural Links, turn into HTML list
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes | style = htmlList }}
Result: