Module:HTMLParse/doc: Difference between revisions

Jump to navigation Jump to search
2,226 bytes added ,  02:47, 5 January 2021
document capitalize
(Created page with "{{doc/start}} <!-- Documentation here --> This module parses and manipulates HTML strings. There is currently only 1 function: * pluralize ==Pluralize== ===Usage=== <nowiki...")
 
(document capitalize)
 
(9 intermediate revisions by one other user not shown)
Line 3: Line 3:
This module parses and manipulates HTML strings.
This module parses and manipulates HTML strings.


There is currently only 1 function:
There is currently 4 functions:
* pluralize
* pluralize
* make_possessive
* strip_formatting
* capitalize




==Pluralize==
== pluralize ==
Pluralizes an HTML string by inserting an "s" between the final alphabetic character and closing tag &lt;/
 
For example, <code><nowiki><span>book</span></nowiki></code> becomes <code><nowiki><span>books</span></nowiki></code>.
 
Notes:
* Won't pluralize anything that already ends in "s".
* Won't pluralize anything that doesn't lua pattern match <code>%a</</code>
* If passing a template that uses a cargo query as the '''html''' parameter, be sure that the cargo query is marked with <code>no html</code> or this Module might not be able to expand the template correctly.
===Usage===
===Usage===
<nowiki>{{#invoke: HTMLParse | pluralize | (html string here) }}</nowiki>
<nowiki>{{#invoke: HTMLParse | pluralize | html = (html string here) }}</nowiki>
===Examples===
===Examples===
{| class="wikitable" |
{| class="wikitable"
|<nowiki>{{#invoke: HTMLParse | pluralize | html = {{favilink | antimatter cell}} }}</nowiki>
!style="padding:10px;text-align:left;"|wikitext
|{{#invoke: HTMLParse | pluralize | html = {{favilink | antimatter cell}} }}
!style="padding:10px;text-align:left;"|result
|-
|-
|<nowiki>{{#invoke: HTMLParse | pluralize | html = <span style="color:red">big </span><span style="color:blue">book</span> }}</nowiki>
|style="padding:10px;"|<syntaxhighlight lang="html">{{#invoke: HTMLParse | pluralize | html = {{Qud text|&Cultra-light &brobot| notxml }} }}</syntaxhighlight>
|{{#invoke: HTMLParse | pluralize | html = <span style="color:red">big </span><span style="color:green">book</span> }}
|style="padding:10px;"|{{#invoke: HTMLParse | pluralize | html = {{Qud text|&Cultra-light &brobot| notxml }} }}
|-
|style="padding:10px;"|<syntaxhighlight lang="html">{{#invoke: HTMLParse | pluralize | html = <span style="color:red">big </span><span style="color:blue">book</span> }}</syntaxhighlight>
|style="padding:10px;"|{{#invoke: HTMLParse | pluralize | html = <span style="color:red">big </span><span style="color:green">book</span> }}
|-
|-
|}
|}
== make_possessive ==
Identical to <code>pluralize</code> except that instead of inserting an <code>s</code>, make_possessive inserts an <code>'s</code>
== strip_formatting ==
Strips HTML tags from the input string. For example, <code><nowiki><span style="color:red;">help!</span></nowiki></code> becomes <code>help!</code>.
Example:
<pre>{{#invoke: HTMLParse | strip_formatting | html = <span style="color: #d74200;">c</span><span style="color: #cfc041;">r</span><span style="color: #00c420;">a</span><span style="color: #0096ff;">y</span><span style="color: #da5bd6;">o</span><span style="color: #77bfcf;">n</span><span style="color: #FFFFFF;">s</span> }}</pre>
Result:
{{#invoke: HTMLParse|strip_formatting|html=<span style="color: #d74200;">c</span><span style="color: #cfc041;">r</span><span style="color: #00c420;">a</span><span style="color: #0096ff;">y</span><span style="color: #da5bd6;">o</span><span style="color: #77bfcf;">n</span><span style="color: #FFFFFF;">s</span>}}
== capitalize ==
Capitalizes the word while preserving HTML formatting. It only takes one argument.
<pre><nowiki>{{#invoke: HTMLParse | capitalize | html = {{qud text|&Cbrinestalk &Gstalks}} }}</nowiki></pre>
{{qud text|&Cbrinestalk &Gstalks}} turns into:
{{#invoke: HTMLParse | capitalize | html = {{qud text|&Cbrinestalk &Gstalks}} }}
<includeonly>
<includeonly>
<!-- Template categories/interwiki here -->
<!-- Template categories/interwiki here -->

Navigation menu