ATTENTION! The process of updating WiKi to version Eco 10.x has begun. Those wishing to participate can find out more Information on our ECO Contribution Wiki Discord.
From April 26 to May 12, errors may occur in the Wiki, as we will be carrying out a major update to the information processing modules.

Module:UtilsHTML

From Eco - English Wiki

This module provides utility functions that generate HTML code. They are used to shorten and make code in other modules more readable by providing functions to generate frequently used pieces of HTML code such as an abbr-tag or a unit of measure text like "ppm" (with an abbreviation tag that shows the name of the unit).

Usage[edit source]

Add the following line of code at the top of your file.

local HTMLUtils = require("Module:UtilsHTML")

-- You may then call functions from this module in your script. For example:
local unitKM = HTMLUtils.tagAbbr("km", "kilometers")

local p = {}

--- Create HTML <code>abbr</code>-tag (abbreviation).
-- @param #string abbreviation The abbreviation (visible text)
-- @param #string title Explanation of the abbreviation (show in tooltip when hovered)
-- @return #string HTML code: "&lt;abbr title="<code>abbreviation</code>"><code>text</code>&lt;/abbr>"
-- @author User:Demian
function p.tagAbbr(abbreviation, title)
	-- Cast to string to avoid errors from using the format string.
	return mw.ustring.format("<abbr style=\"text-decoration: underline dotted 0.0625em;\" title=\"%s\">%s</abbr>", tostring(title), tostring(abbreviation))
end

--- Create HTML code for table with two cells on the same row.
--
-- Intended for displaying two pieces of content side-by-side.
-- @param #string leftCell Content in left cell
-- @param #string rightCell Content in right cell
-- @return #string HTML code for a table with the specified content.
-- @author User:Demian
function p.twoCellTable(leftCell, rightCell)
	return mw.ustring.format("<table><tr><td>%s</td><td>%s</td></tr></table>", leftCell, rightCell)
end

return p