<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.runerealm.org/index.php?action=history&amp;feed=atom&amp;title=Module%3AMw.html_extension%2Fdoc</id>
	<title>Module:Mw.html extension/doc - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.runerealm.org/index.php?action=history&amp;feed=atom&amp;title=Module%3AMw.html_extension%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Module:Mw.html_extension/doc&amp;action=history"/>
	<updated>2026-04-30T09:04:35Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://wiki.runerealm.org/index.php?title=Module:Mw.html_extension/doc&amp;diff=33895&amp;oldid=prev</id>
		<title>Alex: Created page with &quot;{{Documentation}} {{Helper module |name = Mw.html extension  |fname1 = addClassIf(cond, class) |ftype1 = boolean, string |fuse1 = If &lt;code&gt;cond&lt;/code&gt; = &lt;code&gt;true&lt;/code&gt; it behaves the same as the normal &lt;code&gt;addClass&lt;/code&gt; function, otherwise it&#039;s a no-op. Ex.: &lt;code&gt;mw.html.create(&#039;div&#039;):addClassIf(true, &#039;align-left-1&#039;)&lt;/code&gt;  |fname2 = attrIf(cond, name, value) |ftype2 = boolean, string/table, string/nil |fuse2 = Similar to &lt;code&gt;addClassIf&lt;/code&gt;  |fname3 = cssIf...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Module:Mw.html_extension/doc&amp;diff=33895&amp;oldid=prev"/>
		<updated>2024-10-15T13:49:29Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Documentation}} {{Helper module |name = Mw.html extension  |fname1 = addClassIf(cond, class) |ftype1 = boolean, string |fuse1 = If &amp;lt;code&amp;gt;cond&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; it behaves the same as the normal &amp;lt;code&amp;gt;addClass&amp;lt;/code&amp;gt; function, otherwise it&amp;#039;s a no-op. Ex.: &amp;lt;code&amp;gt;mw.html.create(&amp;#039;div&amp;#039;):addClassIf(true, &amp;#039;align-left-1&amp;#039;)&amp;lt;/code&amp;gt;  |fname2 = attrIf(cond, name, value) |ftype2 = boolean, string/table, string/nil |fuse2 = Similar to &amp;lt;code&amp;gt;addClassIf&amp;lt;/code&amp;gt;  |fname3 = cssIf...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Documentation}}&lt;br /&gt;
{{Helper module&lt;br /&gt;
|name = Mw.html extension&lt;br /&gt;
&lt;br /&gt;
|fname1 = addClassIf(cond, class)&lt;br /&gt;
|ftype1 = boolean, string&lt;br /&gt;
|fuse1 = If &amp;lt;code&amp;gt;cond&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; it behaves the same as the normal &amp;lt;code&amp;gt;addClass&amp;lt;/code&amp;gt; function, otherwise it&amp;#039;s a no-op. Ex.: &amp;lt;code&amp;gt;mw.html.create(&amp;#039;div&amp;#039;):addClassIf(true, &amp;#039;align-left-1&amp;#039;)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|fname2 = attrIf(cond, name, value)&lt;br /&gt;
|ftype2 = boolean, string/table, string/nil&lt;br /&gt;
|fuse2 = Similar to &amp;lt;code&amp;gt;addClassIf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|fname3 = cssIf(cond, name, value)&lt;br /&gt;
|ftype3 = boolean, string/table, string/nil&lt;br /&gt;
|fuse3 = Similar to &amp;lt;code&amp;gt;addClassIf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|fname4 = doneIf(cond)&lt;br /&gt;
|ftype4 = boolean&lt;br /&gt;
|fuse4 = Similar to &amp;lt;code&amp;gt;addClassIf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|fname5 = tagIf(cond, tag)&lt;br /&gt;
|ftype5 = boolean, string&lt;br /&gt;
|fuse5 = Similar to &amp;lt;code&amp;gt;addClassIf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|fname6 = wikitextIf(cond, text)&lt;br /&gt;
|ftype6 = boolean, string&lt;br /&gt;
|fuse6 = Similar to &amp;lt;code&amp;gt;addClassIf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|fname7 = na()&lt;br /&gt;
|ftype7 = N/A&lt;br /&gt;
|fuse7 = Shortcut for &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;:tag(&amp;#039;td&amp;#039;):attr(&amp;#039;data-sort-value&amp;#039;, 0):attr(&amp;#039;class&amp;#039;,&amp;#039;table-na&amp;#039;):wikitext(&amp;#039;&amp;lt;small&amp;gt;N/A&amp;lt;/small&amp;gt;&amp;#039;):done()&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|fname8 = naIf(cond)&lt;br /&gt;
|ftype8 = boolean&lt;br /&gt;
|fuse8 = Similar to &amp;lt;code&amp;gt;addClassIf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|fname9 = &amp;lt;nowiki&amp;gt;tr([settings])&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|ftype9 = table/nil&lt;br /&gt;
|fuse9 = Shortcut for &amp;lt;code&amp;gt;:tag(&amp;#039;tr&amp;#039;)&amp;lt;/code&amp;gt; but also auto closes the previous &amp;#039;tr&amp;#039;, &amp;#039;th&amp;#039; or &amp;#039;td&amp;#039; tag (so you don&amp;#039;t need to add :done() before it). &amp;lt;samp&amp;gt;settings&amp;lt;/samp&amp;gt; is a table with keys:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;class&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;addClass&amp;lt;/code&amp;gt; - A string passed to &amp;lt;code&amp;gt;:addClass()&amp;lt;/code&amp;gt; &lt;br /&gt;
* &amp;lt;code&amp;gt;attr&amp;lt;/code&amp;gt; - A table passed to &amp;lt;code&amp;gt;:attr()&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;css&amp;lt;/code&amp;gt; - A table passed to &amp;lt;code&amp;gt;:css()&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;cssText&amp;lt;/code&amp;gt; - A string passed to &amp;lt;code&amp;gt;:cssText()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|fname10 = &amp;lt;nowiki&amp;gt;th([settings])&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|ftype10 = string/table/nil&lt;br /&gt;
|fuse10 = Shortcut for &amp;lt;code&amp;gt;:tag(&amp;#039;th&amp;#039;):wikitext(settings)&amp;lt;/code&amp;gt; if &amp;lt;samp&amp;gt;settings&amp;lt;/samp&amp;gt; is a string. Also auto closes the previous &amp;#039;th&amp;#039; or &amp;#039;td&amp;#039; tag. &amp;lt;samp&amp;gt;settings&amp;lt;/samp&amp;gt; can also be a table with keys:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;[1]&amp;lt;/code&amp;gt; (array) or &amp;lt;code&amp;gt;wikitext&amp;lt;/code&amp;gt; - A string passed to &amp;lt;code&amp;gt;:wikitext()&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;class&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;addClass&amp;lt;/code&amp;gt; - A string passed to &amp;lt;code&amp;gt;:addClass()&amp;lt;/code&amp;gt; &lt;br /&gt;
* &amp;lt;code&amp;gt;attr&amp;lt;/code&amp;gt; - A table passed to &amp;lt;code&amp;gt;:attr()&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;css&amp;lt;/code&amp;gt; - A table passed to &amp;lt;code&amp;gt;:css()&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;cssText&amp;lt;/code&amp;gt; - A string passed to &amp;lt;code&amp;gt;:cssText()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|fname11 = &amp;lt;nowiki&amp;gt;td([settings])&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
|ftype11 = string/table/nil&lt;br /&gt;
|fuse11 = Same as &amp;lt;code&amp;gt;:th()&amp;lt;/code&amp;gt;. Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;#039;lua&amp;#039;&amp;gt;&lt;br /&gt;
local tbl = mw.html.create(&amp;#039;table&amp;#039;)&lt;br /&gt;
tbl:tr{ class=&amp;#039;sortable&amp;#039; }&lt;br /&gt;
        :th{&amp;#039;foo&amp;#039;, attr={&amp;#039;data-sort-type&amp;#039;, &amp;#039;number&amp;#039;}}&lt;br /&gt;
        :th(&amp;#039;bar&amp;#039;)&lt;br /&gt;
    :tr()&lt;br /&gt;
        :td(&amp;#039;buz&amp;#039;)&lt;br /&gt;
            :attr(&amp;#039;data-sort-value&amp;#039;, 10)&lt;br /&gt;
        :td{&amp;#039;N/A&amp;#039;, class=&amp;#039;table-na&amp;#039;}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|fname12 = IF(cond)&lt;br /&gt;
|ftype12 = boolean&lt;br /&gt;
|fuse12 = Allows for if-blocks without breaking the chain. If the condition is true it is a no-op, if false everything inside the balanced IF-END block will be ignored. Can be nested. Ex.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
mw.html.create(&amp;#039;div&amp;#039;)&lt;br /&gt;
    :IF(true)&lt;br /&gt;
        :wikitext(&amp;#039;Conditional text&amp;#039;)&lt;br /&gt;
    :END()&lt;br /&gt;
    :...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Note: This only prevents elements from being added to your html object, it does not protect against statements that throw errors. I.e&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;#039;lua&amp;#039;&amp;gt;&lt;br /&gt;
mw.html.create(&amp;#039;div&amp;#039;)&lt;br /&gt;
    :IF(false)&lt;br /&gt;
        :wikitext(5 * nil) -- This will still throw an error&lt;br /&gt;
    :END()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|fname13 = ELSEIF(cond)&lt;br /&gt;
|ftype13 = boolean&lt;br /&gt;
|fuse13 = Used together with &amp;lt;code&amp;gt;IF()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
|fname14 = ELSE()&lt;br /&gt;
|ftype14 = N/A&lt;br /&gt;
|fuse14 = Used together with &amp;lt;code&amp;gt;IF()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
|fname15 = END()&lt;br /&gt;
|ftype15 = N/A&lt;br /&gt;
|fuse15 = Used together with &amp;lt;code&amp;gt;IF()&amp;lt;/code&amp;gt;. Make sure the IF-END tags are balanced, it wont throw an error if they are not.&lt;br /&gt;
&lt;br /&gt;
|fname16 = exec(func, ...)&lt;br /&gt;
|ftype16 = function, any&lt;br /&gt;
|fuse16 = Call a function without breaking the chain. See module docs for more info.&lt;br /&gt;
&lt;br /&gt;
|fname17 = addFunction(func, name)&lt;br /&gt;
|ftype17 = function, string&lt;br /&gt;
|fuse17 = Add a function to the mw.html class that can then be used on mw.html object. See module docs for more info.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
For all functions other than &amp;lt;code&amp;gt;addFunction()&amp;lt;/code&amp;gt; all you need to do is simply require this module:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
require(&amp;#039;Module:Mw.html extension&amp;#039;)&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
function p.main()&lt;br /&gt;
    ...&lt;br /&gt;
    local tbl = mw.html.create(&amp;#039;div&amp;#039;)&lt;br /&gt;
        :IF(true)&lt;br /&gt;
            :wikitext(&amp;#039;Conditional text&amp;#039;)&lt;br /&gt;
        :ELSE()&lt;br /&gt;
            :wikitext(&amp;#039;something else&amp;#039;)&lt;br /&gt;
        :END()&lt;br /&gt;
        :addClassIf(true, &amp;#039;wikitable&amp;#039;)&lt;br /&gt;
        :tag(&amp;#039;span)&amp;#039;&lt;br /&gt;
            :wikitext(&amp;#039;normal wikitext&amp;#039;)&lt;br /&gt;
        :done()&lt;br /&gt;
    ...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can mix the normal old functions with the newly added ones.&lt;br /&gt;
&lt;br /&gt;
===attrIf===&lt;br /&gt;
This accepts either a name-value pair or a table&lt;br /&gt;
* &amp;lt;code&amp;gt;:attrIf(true, &amp;#039;data-sort-value&amp;#039;, &amp;#039;0&amp;#039;)&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;:attrIf(true, {&amp;#039;data-sort-value&amp;#039; = &amp;#039;0&amp;#039;, ...})&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===cssIf===&lt;br /&gt;
This accepts either a name-value pair or a table similar to &amp;lt;code&amp;gt;attrIf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===exec===&lt;br /&gt;
The first parameter of the function will have the current state of the mw.html object passed into it, usually we call this parameter &amp;lt;code&amp;gt;self&amp;lt;/code&amp;gt;, the rest of the parameters can be anything you want. To not break the chaining the function must also return a mw.html object. Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local function repNa(self, times)&lt;br /&gt;
    for i = 1,times do&lt;br /&gt;
        self:na()&lt;br /&gt;
    end&lt;br /&gt;
    return self&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function can then be used as follows&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
mw.html.create(&amp;#039;div&amp;#039;):exec(repNa, 5)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===addFunction===&lt;br /&gt;
The function you want to add has to be of the same structure as in &amp;lt;code&amp;gt;exec()&amp;lt;/code&amp;gt;. Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local htmlExtension = require(&amp;#039;Module:Mw.html extension&amp;#039;)&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
local function repNa(self, times)&lt;br /&gt;
    for i = 1,times do&lt;br /&gt;
        self:na()&lt;br /&gt;
    end&lt;br /&gt;
    return self&lt;br /&gt;
end&lt;br /&gt;
htmlExtension.addFunction(repNa, &amp;#039;repNaName&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
function p.main()&lt;br /&gt;
    ...&lt;br /&gt;
    local tbl = mw.html.create(&amp;#039;div&amp;#039;):repNaName(5)&lt;br /&gt;
    ...&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tr, th and td===&lt;br /&gt;
The following three tables are the same:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;#039;lua&amp;#039;&amp;gt;&lt;br /&gt;
local tbl = mw.html.create(&amp;#039;table&amp;#039;)&lt;br /&gt;
tbl:tr{ class=&amp;#039;sortable&amp;#039; }&lt;br /&gt;
        :th{&amp;#039;foo&amp;#039;, attr={[&amp;#039;data-sort-type&amp;#039;]=&amp;#039;number&amp;#039;}} -- or attr={&amp;#039;data-sort-type&amp;#039;, &amp;#039;number&amp;#039;}&lt;br /&gt;
        :th(&amp;#039;bar&amp;#039;)&lt;br /&gt;
            :IF(expression)&lt;br /&gt;
                :addClass(&amp;#039;table-na&amp;#039;)&lt;br /&gt;
            :END()&lt;br /&gt;
    :tr()&lt;br /&gt;
        :td(&amp;#039;buz&amp;#039;)&lt;br /&gt;
        :td{&amp;#039;N/A&amp;#039;, class=&amp;#039;table-na&amp;#039;}&lt;br /&gt;
&lt;br /&gt;
local tbl2 = mw.html.create(&amp;#039;table&amp;#039;)&lt;br /&gt;
tbl2:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
        :addClass(&amp;#039;sortable&amp;#039;)&lt;br /&gt;
        :tag(&amp;#039;th&amp;#039;)&lt;br /&gt;
            :attr(&amp;#039;data-sort-type&amp;#039;, &amp;#039;number&amp;#039;)&lt;br /&gt;
            :wikitext(&amp;#039;foo&amp;#039;)&lt;br /&gt;
        :done()&lt;br /&gt;
        :tag(&amp;#039;th&amp;#039;)&lt;br /&gt;
            :wikitext(&amp;#039;bar&amp;#039;)&lt;br /&gt;
            :IF(expression)&lt;br /&gt;
                :addClass(&amp;#039;table-na&amp;#039;)&lt;br /&gt;
            :END()&lt;br /&gt;
        :done() -- This is needed because &amp;quot;tag(&amp;#039;tr&amp;#039;)&amp;quot; is used after this instead of &amp;quot;tr()&amp;quot;&lt;br /&gt;
    :done()&lt;br /&gt;
    :tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
        :tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
            :wikitext(&amp;#039;buz&amp;#039;)&lt;br /&gt;
        :done()&lt;br /&gt;
        :tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
            :wikitext(&amp;#039;N/A&amp;#039;)&lt;br /&gt;
            :addClass(&amp;#039;table-na&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
local tbl3 = mw.html.create(&amp;#039;table&amp;#039;)&lt;br /&gt;
tbl3:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
        :addClass(&amp;#039;sortable&amp;#039;)&lt;br /&gt;
        :tag(&amp;#039;th&amp;#039;)&lt;br /&gt;
            :attr(&amp;#039;data-sort-type&amp;#039;, &amp;#039;number&amp;#039;)&lt;br /&gt;
            :wikitext(&amp;#039;foo&amp;#039;)&lt;br /&gt;
        :th(&amp;#039;bar&amp;#039;)&lt;br /&gt;
            :IF(expression)&lt;br /&gt;
                :addClass(&amp;#039;table-na&amp;#039;)&lt;br /&gt;
            :END()&lt;br /&gt;
        :done()&lt;br /&gt;
    :done()&lt;br /&gt;
    :tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
        :td(&amp;#039;buz&amp;#039;)&lt;br /&gt;
        :td(&amp;#039;N/A&amp;#039;)&lt;br /&gt;
            :addClass(&amp;#039;table-na&amp;#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Alex</name></author>
	</entry>
</feed>