Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Dump/doc
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Dump of a formatted html string == A module can use [[:mw:Extension:Scribunto/Lua reference manual#HTML library|mw.html]] to generate html. For testing, it may be useful to display the formatted result. The following shows how a module can create and dump html text. <syntaxhighlight lang="Lua"> local function main() local tbl = mw.html.create('table') tbl :addClass('wikitable') :tag('caption'):wikitext('Table demonstration'):done() :tag('tr') :tag('th'):wikitext('Month'):done() :tag('th'):wikitext('Amount'):done() :done() :tag('tr') :tag('td'):wikitext('January'):done() :tag('td'):wikitext('$100<br>loss'):done() :done() :tag('tr') :tag('td'):wikitext('February'):done() :tag('td'):wikitext('$200') local html = tostring(tbl) local dumphtml = require('Module:Dump')._dumphtml return dumphtml(html) end return { main = main } </syntaxhighlight> With the above code in Module:Example, the result could be displayed by previewing: :<code><nowiki>{{#invoke:example|main}}</nowiki></code> The result is: <pre> <table class="wikitable"> <caption>Table demonstration</caption> <tr> <th>Month</th> <th>Amount</th> </tr> <tr> <td>January</td> <td>$100<br>loss</td> </tr> <tr> <td>February</td> <td>$200</td> </tr> </table> </pre> The <code>main()</code> function in the code above could be modified to return the html table by replacing the last two lines with: <syntaxhighlight lang="Lua"> return html </syntaxhighlight> In that case, the result could be displayed by previewing the following (the <code>1=</code> is needed if the text contains "<code>=</code>"): :<code><nowiki>{{#invoke:dump|dumphtml|1={{#invoke:example|main}}}}</nowiki></code> === Dumping a navbox === Previewing the following examples in a sandbox may be useful to examine the results of a template, such as {{tl|navbox}}, that generates html. <pre> {{#invoke:dump|dumphtml|1= {{navbox/sandbox |group1 = Group1 |list1 = List1 |group2 = Group2 |list2 = List2 |group3 = Group3 |list3 = List3 }} }} </pre> The dumphtml procedure only works reliably with valid html. In the following example, extra text (<code><div></code>) is inserted at the start because the output from a subgroup (child) navbox starts with <code></div></code>. <pre> {{#invoke:dump|dumphtml|1=<div> {{navbox/sandbox|subgroup |group1 = Group1 |list1 = List1 |group2 = Group2 |list2 = List2 |group3 = Group3 |list3 = List3 }} }} </pre>
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)