Module:ParseList/doc: Difference between revisions

From bg3.wiki
Jump to navigation Jump to search
(Created page with "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. <pre> {{#invoke:ParseList|main|Fighter, Cleric, Wizard}} </pre> Becomes: : {{#invoke:ParseList|main|Fighter, Cleric, Wizard}} == Parameters == The first parameter is the list to be processed. The remaining parameters are optional: {| class="wikitable" ! parameter !! default !! meaning |- | <code>type</code> || <code>sentence</code>...")
 
No edit summary
Line 25: Line 25:
| If provided and not blank, means that each element will be made into a link.
| If provided and not blank, means that each element will be made into a link.
|-
|-
| <code>pluralize</code> || ''(empty)''
| <code>makePlural</code> || ''(empty)''
| If provided and not blank, means that each element will be turned into a plural word.  This happens ''after'' turning them into links, so e.g. the word "Apple" would become <code><nowiki>[[Apple]]s</nowiki></code>.
| If provided and not blank, means that each element will be turned into a plural word.  This happens ''after'' turning them into links, so e.g. the word "Apple" would become <code><nowiki>[[Apple]]s</nowiki></code>.
|-
|-
| <code>joiningWord</code> || <code>and</code>
| <code>joinWord</code> || <code>and</code>
| If <code>type</code> is <code>sentence</code>, this defines whether to use "and" or "or" (or any other word) for the last two elements of the list.  E.g., the default would be to turn "X, Y" into "X and Y" and "X, Y, Z" into "X, Y, and Z", but by providing <code>joiningWord = or</code> you can make these become "X or Y" and "X, Y, or Z" respectively.
| If <code>type</code> is <code>sentence</code>, this defines whether to use "and" or "or" (or any other word) for the last two elements of the list.  E.g., the default would be to turn "X, Y" into "X and Y" and "X, Y, Z" into "X, Y, and Z", but by providing <code>joinWord = or</code> you can make these become "X or Y" and "X, Y, or Z" respectively.
|}
|}


Line 63: Line 63:
: {{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes }}
: {{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes }}


=== Pluralize ===
=== Make plural ===


<pre>
<pre>
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | pluralize = yes }}
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makePlural = yes }}
</pre>
</pre>


Result:
Result:


: {{#invoke: ParseList | main | Fighter, Cleric, Wizard | pluralize = yes }}
: {{#invoke: ParseList | main | Fighter, Cleric, Wizard | makePlural = yes }}


=== Make Links & Pluralize ===
=== Make Plural Links ===


<pre>
<pre>
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | pluralize = yes }}
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes }}
</pre>
</pre>


Result:
Result:


: {{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | pluralize = yes }}
: {{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes }}


=== Make Links & Pluralize, end with "or" ===
=== Make Plural Links, end with "or" ===


<pre>
<pre>
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | pluralize = yes | joiningWord = or }}
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes | joinWord = or }}
</pre>
</pre>


Result:
Result:


: {{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | pluralize = yes | joiningWord = or }}
: {{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes | joinWord = or }}


=== Make Links & Pluralize, turn into HTML list ===
=== Make Plural Links, turn into HTML list ===


<pre>
<pre>
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | pluralize = yes | type = htmlList }}
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes | type = htmlList }}
</pre>
</pre>


Result:
Result:


{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | pluralize = yes | type = htmlList }}
{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes | type = htmlList }}

Revision as of 00:50, 24 July 2023

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
type sentence The desired output format, see below for possibilities.
delimiter , The character that should serve as a delimiter of the 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.
makeLinks (empty) If provided and not blank, means that each element will be made into a link.
makePlural (empty) If provided and not blank, means that each element will be turned into a plural word. This happens after turning them into links, so e.g. the word "Apple" would become [[Apple]]s.
joinWord and If type is sentence, this defines whether to use "and" or "or" (or any other word) for the last two elements of the list. E.g., the default would be to turn "X, Y" into "X and Y" and "X, Y, Z" into "X, Y, and Z", but by providing joinWord = or you can make these become "X or Y" and "X, Y, or Z" respectively.

The automatic pluralization is able to recognize certain irregular plurals and handle them correctly, such as "thieves" and "quarterstaves." This is handled through a simple table in the code mapping words to their irregular plural form. If you find a word that's not supported yet, you can simply add it to the table.

Output types

The value of the type parameter can be the following:

value example output
sentence Fighter, Cleric, and Wizard
htmlList
  • Fighter
  • Cleric
  • Wizard
simpleList Fighter, Cleric, Wizard

Examples

Make Links

{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes }}

Result:

Fighter, Cleric, and Wizard

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:

Fighters, Clerics, and Wizards

Make Plural Links, end with "or"

{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes | joinWord = or }}

Result:

Fighters, Clerics, and Wizards

Make Plural Links, turn into HTML list

{{#invoke: ParseList | main | Fighter, Cleric, Wizard | makeLinks = yes | makePlural = yes | type = htmlList }}

Result: