<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.writediteach.com/index.php?action=history&amp;feed=atom&amp;title=Module%3AHtmlBuilder%2Fdoc</id>
	<title>Module:HtmlBuilder/doc - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.writediteach.com/index.php?action=history&amp;feed=atom&amp;title=Module%3AHtmlBuilder%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://www.writediteach.com/index.php?title=Module:HtmlBuilder/doc&amp;action=history"/>
	<updated>2026-04-08T12:21:45Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.7</generator>
	<entry>
		<id>https://www.writediteach.com/index.php?title=Module:HtmlBuilder/doc&amp;diff=409&amp;oldid=prev</id>
		<title>Shawndouglas: Created as needed.</title>
		<link rel="alternate" type="text/html" href="https://www.writediteach.com/index.php?title=Module:HtmlBuilder/doc&amp;diff=409&amp;oldid=prev"/>
		<updated>2017-09-11T22:39:53Z</updated>

		<summary type="html">&lt;p&gt;Created as needed.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
HtmlBuilder provides a way to construct complex HTML and CSS markup by creating a tree of nodes, similar to the Document Object Model. The result is a list of codes that are more comprehensible and maintainable than if you simply concatenated strings together.  It offers a fluent interface that should look familiar to any user of jQuery.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
First, you need to load the module:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;local HtmlBuilder = require(&amp;#039;Module:HtmlBuilder&amp;#039;)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, create the root HtmlBuilder instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;local builder = HtmlBuilder.create()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you can build HTML using the methods of the HtmlBuilder instance, listed below.&lt;br /&gt;
&lt;br /&gt;
Finally, get the resulting HTML markup as a string:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;local s = tostring(builder)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Methods ==&lt;br /&gt;
To allow chaining, all methods return a reference to the builder, unless otherwise stated.&lt;br /&gt;
&lt;br /&gt;
===tag===&lt;br /&gt;
&amp;lt;code&amp;gt;local div = builder.tag(&amp;#039;div&amp;#039;)&amp;lt;/code&amp;gt;&lt;br /&gt;
Appends a new child node to the builder, and returns an HtmlBuilder instance representing that new node.&lt;br /&gt;
&lt;br /&gt;
===done===&lt;br /&gt;
&amp;lt;code&amp;gt;builder = div.done()&amp;lt;/code&amp;gt;&lt;br /&gt;
Returns the parent node under which the current node was created.  Like [http://api.jquery.com/end/ jQuery.end], this is a convenience function to allow the construction of several child nodes to be chained together into a single statement.&lt;br /&gt;
&lt;br /&gt;
===allDone===&lt;br /&gt;
&amp;lt;code&amp;gt;builder = div.allDone()&amp;lt;/code&amp;gt;&lt;br /&gt;
Like &amp;lt;code&amp;gt;.done()&amp;lt;/code&amp;gt;, but traverses all the way to the root node of the tree and returns it.&lt;br /&gt;
&lt;br /&gt;
===wikitext===&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;div.wikitext(&amp;#039;This is some [[example]] text.&amp;#039;)&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
Appends some markup to the node. It may include plain text, wiki markup, and even HTML markup.&lt;br /&gt;
&lt;br /&gt;
===newline===&lt;br /&gt;
&amp;lt;code&amp;gt;div.newline()&amp;lt;/code&amp;gt;&lt;br /&gt;
Appends a newline character to the node. Equivalent to &amp;lt;code&amp;gt;.wikitext(&amp;#039;\n&amp;#039;)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===attr===&lt;br /&gt;
&amp;lt;code&amp;gt;div.attr(&amp;#039;title&amp;#039;, &amp;#039;Attr value&amp;#039;)&amp;lt;/code&amp;gt;&lt;br /&gt;
Set an HTML attribute on the node.&lt;br /&gt;
&lt;br /&gt;
===css===&lt;br /&gt;
&amp;lt;code&amp;gt;div.css(&amp;#039;color&amp;#039;, &amp;#039;#f00&amp;#039;)&amp;lt;/code&amp;gt;&lt;br /&gt;
Set a CSS property to be added to the node&amp;#039;s &amp;lt;code&amp;gt;style&amp;lt;/code&amp;gt; attribute.&lt;br /&gt;
&lt;br /&gt;
===cssText===&lt;br /&gt;
&amp;lt;code&amp;gt;div.cssText(&amp;#039;color:#f00; font-size:1.5em&amp;#039;)&amp;lt;/code&amp;gt;&lt;br /&gt;
Add some raw CSS to the node&amp;#039;s &amp;lt;code&amp;gt;style&amp;lt;/code&amp;gt; attribute. This is typically used when a template allows some CSS to be passed in as a parameter, such as the &amp;lt;code&amp;gt;liststyle&amp;lt;/code&amp;gt; parameter of {{tl|Navbox}}.&lt;br /&gt;
&lt;br /&gt;
===addClass===&lt;br /&gt;
&amp;lt;code&amp;gt;div.addClass(&amp;#039;even&amp;#039;)&amp;lt;/code&amp;gt;&lt;br /&gt;
Adds a class name to the node&amp;#039;s &amp;lt;code&amp;gt;class&amp;lt;/code&amp;gt; attribute. Spaces will be automatically added to delimit each added class name.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local HtmlBuilder = require(&amp;#039;Module:HtmlBuilder&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
local root = HtmlBuilder.create()&lt;br /&gt;
&lt;br /&gt;
root&lt;br /&gt;
    .wikitext(&amp;#039;Lorem &amp;#039;)&lt;br /&gt;
    .tag(&amp;#039;span&amp;#039;)&lt;br /&gt;
        .css(&amp;#039;color&amp;#039;, &amp;#039;red&amp;#039;)&lt;br /&gt;
        .attr(&amp;#039;title&amp;#039;, &amp;#039;ipsum dolor&amp;#039;)&lt;br /&gt;
        .wikitext(&amp;#039;sit amet&amp;#039;)&lt;br /&gt;
        .done()&lt;br /&gt;
    .tag(&amp;#039;div&amp;#039;)&lt;br /&gt;
        .wikitext(&amp;#039;consectetur adipisicing&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
local s = tostring(root)&lt;br /&gt;
-- s = &amp;#039;Lorem &amp;lt;span style=&amp;quot;color:red;&amp;quot; title=&amp;quot;ipsum dolor&amp;quot;&amp;gt;sit amet&amp;lt;/span&amp;gt;&amp;lt;div&amp;gt;consectetur adipisicing&amp;lt;/div&amp;gt;&amp;#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For more examples, please see the [[Module:HtmlBuilder/testcases|test cases page]] and the [[Module talk:HtmlBuilder/testcases|test cases results]].&lt;/div&gt;</summary>
		<author><name>Shawndouglas</name></author>
	</entry>
</feed>