Module:UtilsMarkup

From Zelda Wiki, the Zelda encyclopedia
Jump to: navigation, search

This module is for producing wikitext. See also Module:UtilsLayout.

This module exports the following functions.

Formatting

bold

bold(text)

Parameters
  • text
    The text to bold.
Returns
  • The bolded text.
Examples
InputOutputResultStatus
bold("Fooloo Limpah")
"<b>Fooloo Limpah</b>"
Fooloo Limpah
Green check.svg

caption

caption(text)

Returns
  • Text in caption font, which is slightly smaller.
Examples
InputOutputResultStatus
caption("Fooloo Limpah")
'<span class="caption">Fooloo Limpah</span>'
Fooloo Limpah
Green check.svg

class

class(class, text)

Returns
  • Text wrapped in a span tag with the given class string.
Examples
InputOutputResultStatus
class("term error", "Fooloo Limpah")
'<span class="term error">Fooloo Limpah</span>'
Fooloo Limpah
Green check.svg

code

code(text)

Parameters
  • text
    The text to render monospaced.
Returns
  • The formatted text.
Examples
InputOutputResultStatus
code("code stuff")
"<code>code stuff</code>"
code stuff
Green check.svg

heading

heading(level, text)

Parameters
Returns
  • string of text for the heading
Examples
InputOutputStatus
heading(2, "Section")
"\n==Section==\n"
Green check.svg
heading(3, "Sub-section")
"\n===Sub-section===\n"
Green check.svg

italic

italic(text)

Parameters
  • text
    The text to italicize.
Returns
  • The italicized text.
Examples
InputOutputResultStatus
italic("Fooloo Limpah")
"<i>Fooloo Limpah</i>"
Fooloo Limpah
Green check.svg

inline

inline(text, [options])

Parameters
Returns
  • The formatted text.
Examples
InputOutputResultStatus
inline(
  "Fooloo Limpah",
  {
    bold = true,
    italic = true,
    class = "error",
    tooltip = "Don't steal them!",
  }
)
"<span class=\"error\"><span title=\"Don't steal them!\" class=\"explain\"><b><i>Fooloo Limpah</i></b></span></span>"
Fooloo Limpah
Green check.svg
inline(
  "{{Foo}}",
  {
    bold = true,
    nowiki = true,
    code = true,
  }
)
"<b><code>&#123;&#123;Foo&#125;&#125;</code></b>"
{{Foo}}
Green check.svg

lua

lua(text, [options])

Parameters
Returns
  • A block of pre-formatted, syntax-highlighted Lua code
Examples
InputResult
lua("function(foo) \n\treturn foo\nend")
function(foo) 
	return foo
end

pre

pre(text, [options])

Parameters
Returns
  • A block of pre-formatted text.
Examples
InputResult
pre("{{List\n |foo\n |bar\n |baz\n}}")
{{List
 |foo
 |bar
 |baz
}}

tooltip

tooltip(baseText, tooltipText, [type])

Parameters
  • baseText
    The text to receive a tooltip.
  • tooltipText
    The text to display on hover.
  • [type]
    If "highlight", colors the base text to make the presence of tooltip text more evident.
Returns
  • Text with a tooltip.
Examples
InputOutputResultStatus
tooltip("hover over me", "hello world!")
'<span title="hello world!" class="explain">hover over me</span>'
hover over me
Green check.svg
tooltip("foo", "bar", "highlight")
'<span title="bar" class="explain" style="color:yellow">foo</span>'
foo
Green check.svg


Links

link

link(page, [display], [noBacklink])

Parameters
  • page
    The link target. Can be the name of a page on the wiki or an external URL.
  • [display=page]
    The text to display for the link.
  • [noBacklink]
    When true, renders an internal link such that it does not register on the Special:WhatLinksHere of the target page.

    Use only when certain that the page exists. This method cannot render red-links (i.e. distinguish non-existent pages).

Returns
  • A string of wikitext that evaluates to a link. Will display a red link if the target is an internal link to a page that doesn't exist.
Examples
InputOutputResultStatus
Internal link
link("Princess Zelda")
"[[Princess Zelda]]"
Princess Zelda
Green check.svg
Link to page that doesn't exist
link("Flippityfloppityfloo")
"[[Flippityfloppityfloo]]"
Flippityfloppityfloo
Green check.svg
Piped link
link("Princess Zelda", "Zelda")
"[[Princess Zelda|Zelda]]"
Zelda
Green check.svg
Category link
link("Category:Items")
"[[:Category:Items]]"
Category:Items
Green check.svg
Category link without prefix
link("Category:Items", "")
"[[:Category:Items|Items]]"
Items
Green check.svg
Category link with display text
link(
  "Category:Items in Breath of the Wild",
  "Items in ''Breath of the Wild''"
)
"[[:Category:Items in Breath of the Wild|Items in ''Breath of the Wild'']]"
Items in Breath of the Wild
Green check.svg
File link (to file description)
link("File:MM Deku Butler Artwork.png")
"[[:File:MM Deku Butler Artwork.png]]"
File:MM Deku Butler Artwork.png
Green check.svg
External link
link("https://www.mariowiki.com/Thwomp", "Thwomp")
"[https://www.mariowiki.com/Thwomp Thwomp]"
Thwomp
Green check.svg
Looks like an internal link, but it's actually an external link. This is to avoid Special:WhatLinksHere
link("Princess Zelda", "Zelda", true)
'<span class="plainlinks">[https://zelda.gamepedia.com/Princess_Zelda Zelda]</span>'
Zelda
Green check.svg
When noBacklink is set to true, red links are not rendered for pages which do not exist.
link("Flippityfloppityfloo", nil, true)
'<span class="plainlinks">[https://zelda.gamepedia.com/Flippityfloppityfloo Flippityfloppityfloo]</span>'
Flippityfloppityfloo
Green check.svg

sectionLink

sectionLink(page, [section], [display])

Parameters
Returns
  • A string of wikitext rendering a section link.
Examples
InputOutputResultStatus
sectionLink("Link", "Ocarina of Time", "Hero of Time")
"[[Link#Ocarina of Time|Hero of Time]]"
Hero of Time
Green check.svg
sectionLink("Link", nil, "Hero of Time")
"[[Link|Hero of Time]]"
Hero of Time
Green check.svg
sectionLink("Link", "")
"[[Link#]]"
Link#
Green check.svg

file

file(name, [options])

Parameters
Returns
  • A string of wikitext that renders a thumbnail for the file.
Examples
InputOutputResultStatus
file("File:ALttP Ganon Sprite.png")
"[[File:ALttP Ganon Sprite.png]]"
ALttP Ganon Sprite.png
Green check.svg
file(
  "ALttP Ganon Sprite.png",
  {
    caption = "Ganon",
    link = "",
  }
)
"[[File:ALttP Ganon Sprite.png|link=|Ganon]]"
Ganon
Green check.svg
file(
  "File:TWW Great Fairy Figurine Model.png",
  {
    size = "100px",
    link = "Great Fairy",
  }
)
"[[File:TWW Great Fairy Figurine Model.png|100px|link=Great Fairy]]"
TWW Great Fairy Figurine Model.png
Green check.svg
file(
  "File:TWW Great Fairy Figurine Model.png",
  {
    noBacklink = true,
    size = "100px",
    link = "Great Fairy",
  }
)
"[[File:TWW Great Fairy Figurine Model.png|100px|link=https://zelda.gamepedia.com/Great_Fairy]]"
TWW Great Fairy Figurine Model.png
Green check.svg

category

category(name, [sortKey])

Parameters
  • name
    The name of the category to link to (with or without namespace prefix).
  • [sortKey]
    A custom sort key for the category entry.
Returns
  • A category link—the kind that adds a category to a page. For the other kind that links to the actual category page, use link.
Examples
InputOutputStatus
Category link from category name
category("Items")
"[[Category:Items]]"
Green check.svg
Category link from category name with namespace prefix
category("Category:Items")
"[[Category:Items]]"
Green check.svg
Category link with sort key
category("Items", "*")
"[[Category:Items|*]]"
Green check.svg

categories

categories(names)

Parameters
  • names
    An array of category names, with or without the namespace prefix.
Returns
  • A concatenated string of category links.
Examples
InputOutputStatus
categories({"Link", "Category:Zelda", "Category:Ganon"})
"[[Category:Link]][[Category:Zelda]][[Category:Ganon]]"
Green check.svg
categories({})
""
Green check.svg

containsLink

containsLink(wikitext)

Returns
  • Given a string of wikitext, returns true if it contains a link, false otherwise.
Examples
InputOutputStatus
containsLink("There is a [[Link]]")
true
Green check.svg
containsLink("[Link] is not a link but rather an idication of replaced words in a quote.")
false
Green check.svg

killBacklinks

killBacklinks(wikitext)

Parameters
Returns
  • The same wikitext but with all the internal links formatted as external links, to avoid additions to Special:WhatLinksHere.
Examples
InputOutputResultStatus
Escapes both normal links and red links
killBacklinks("[[Link]], [[Princess Zelda|Zelda]], and [[Jean-Guy Rubber Boots]]")
Expected
'<span class="plainlinks">[https://zelda.gamepedia.com/Link Link]</span>, <span class="plainlinks">[https://zelda.gamepedia.com/Princess_Zelda Zelda]</span>, and <span class="plainlinks new">[https://zelda.gamepedia.com/Jean-Guy_Rubber_Boots?action=edit&redlink=1 Jean-Guy Rubber Boots]</span>'
Actual
'<span class="plainlinks">[https://zelda.gamepedia.com/Link Link]</span>, <span class="plainlinks">[https://zelda.gamepedia.com/Princess_Zelda Zelda]</span>, and <span class="plainlinks">[https://zelda.gamepedia.com/Jean-Guy_Rubber_Boots Jean-Guy Rubber Boots]</span>'
Link, Zelda, and Jean-Guy Rubber Boots
TFH Red Link desperate.png
Does not escape file links or category links
killBacklinks("[[Category:Link]] and [[File:SS Blessed Butterfly Icon.png]]")
"[[Category:Link]] and [[File:SS Blessed Butterfly Icon.png]]"
and SS Blessed Butterfly Icon.png
Green check.svg
Escapes visible file and category links
killBacklinks("[[:Category:Link]], [[:Category:Princess Zelda|Zelda]], and [[:File:SS Blessed Butterfly Icon.png]]")
'<span class="plainlinks">[https://zelda.gamepedia.com/Category:Link Category:Link]</span>, <span class="plainlinks">[https://zelda.gamepedia.com/Category:Princess_Zelda Zelda]</span>, and <span class="plainlinks">[https://zelda.gamepedia.com/File:SS_Blessed_Butterfly_Icon.png File:SS Blessed Butterfly Icon.png]</span>'
Category:Link, Zelda, and File:SS Blessed Butterfly Icon.png
Green check.svg
Does not affect interwiki links
killBacklinks("[[metroidwiki:Chozo|Chozo]]")
"[[metroidwiki:Chozo|Chozo]]"
Chozo
Green check.svg

stripCategories

stripCategories(wikitext)

Parameters
Returns
  • The string of wiki markup with all the category links removed (not including visual links to category description pages).
  • A table array of direct links to the removed categories.
Examples
InputOutputStatus
Basic use case
stripCategories("<[[Category:Link]][[Category:Princess Zelda]][[Category:Link]]>")
"<>"
Green check.svg
{
  "[[:Category:Link]]",
  "[[:Category:Princess Zelda]]",
}
Green check.svg
Does not affect visual links to category description pages
stripCategories("[[:Category:Link]] and [[:Category:Princess Zelda]]")
"[[:Category:Link]] and [[:Category:Princess Zelda]]"
Green check.svg
{}
Green check.svg


Lists

list

list(items)

Parameters
  • items
    An array of strings (list items).
Returns
  • An unordered list with the plainlist class.
Examples
InputOutputResultStatus
list({})
""
Green check.svg
list({"single item"})
'<ul class="plainlist"><li>single item</li></ul>'
  • single item
Green check.svg
list({"multiple", "items", ""})
'<ul class="plainlist"><li>multiple</li><li>items</li><li></li></ul>'
  • multiple
  • items
Green check.svg

bulletList

bulletList(items)

Parameters
  • items
    An array of strings (list items).
Returns
  • A string representation of an unordered list using HTML syntax.
Examples
InputOutputResultStatus
bulletList({})
""
Green check.svg
bulletList({"single item"})
"<ul><li>single item</li></ul>"
  • single item
Green check.svg
bulletList({"multiple", "items", ""})
"<ul><li>multiple</li><li>items</li><li></li></ul>"
  • multiple
  • items
Green check.svg
bulletList({
  "list",
  {
    "with",
    {"nested", "items"},
    "inside",
  },
})
"<ul><li>list</li><ul><li>with</li><ul><li>nested</li><li>items</li></ul><li>inside</li></ul></ul>"
  • list
    • with
      • nested
      • items
    • inside
Green check.svg

numberList

numberList(items)

Parameters
  • items
    An array of strings (list items).
Returns
  • A string representation of an ordered list using HTML syntax.
Examples
InputOutputResultStatus
numberList({})
""
Green check.svg
numberList({"single item"})
"<ol><li>single item</li></ol>"
  1. single item
Green check.svg
numberList({"multiple", "items", ""})
"<ol><li>multiple</li><li>items</li><li></li></ol>"
  1. multiple
  2. items
Green check.svg
numberList({
  "list",
  {
    "with",
    {"nested", "items"},
    "inside",
  },
})
"<ol><li>list</li><ol><li>with</li><ol><li>nested</li><li>items</li></ol><li>inside</li></ol></ol>"
  1. list
    1. with
      1. nested
      2. items
    2. inside
Green check.svg
numberList({"Eight", "Nine", "Ten", start = 8})
'<ol start="8"><li>Eight</li><li>Nine</li><li>Ten</li></ol>'
  1. Eight
  2. Nine
  3. Ten
Green check.svg

definitionList

definitionList(pairs)

Parameters
  • pairs
    Array of table of pairs where the first pair item is a term and the value is a definition.
Returns
  • A string representation of a definition list using HTML syntax.
Examples
InputResultStatus
definitionList({})
Green check.svg
definitionList({
  {"key1", "value1"},
})
key1
value1
Green check.svg
definitionList({
  {"key1", "value1"},
  {"key2", "value2"},
})
key1
value1
key2
value2
Green check.svg
definitionList({
  {"", "value1"},
  {[2] = "value2" },
  {"key3", ""},
  {"key4"},
})
value1
value2
key3
key4
Green check.svg
definitionList({
  {
    "key 1",
    {
      {
        "key 1.1",
        {
          {"key 1.1.1", "value 1.1.1"},
        },
      },
      {"key 1.2", "value 1.2"},
    },
  },
  {"key2", "value2"},
})
key 1
key 1.1
key 1.1.1
value 1.1.1
key 1.2
value 1.2
key2
value2
Green check.svg
definitionList({
  {
    "key 1",
    "value 1.1",
    {
      {"key 1.1", "value 1.2"},
      {"key 1.2", "value 1.2"},
    },
  },
})
key 1
value 1.1
key 1.1
value 1.2
key 1.2
value 1.2
Green check.svg

local utilsPackage = require("Module:UtilsPackage")

return utilsPackage.submodules({
	"Module:UtilsMarkup/Format",
	"Module:UtilsMarkup/Link",
	"Module:UtilsMarkup/List",
}, {
	"Formatting", 
	"Links",
	"Lists",
})