Module:UtilsMarkup

From Zelda Wiki, the Zelda encyclopedia
Jump to navigation Jump to 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
1
bold("Fooloo Limpah")
"<b>Fooloo Limpah</b>"
Fooloo Limpah

class

class(class, text)

Returns

  • Text wrapped in a span tag with the given class string.

Examples

#InputOutputResultStatus
2
class("term error", "Fooloo Limpah")
'<span class="term error">Fooloo Limpah</span>'
Fooloo Limpah

code

code(text)

Parameters

  • text
    The text to render monospaced.

Returns

  • The formatted text.

Examples

#InputOutputResultStatus
3
code("code stuff")
"<code>code stuff</code>"
code stuff

heading

heading(level, text)

Parameters

Returns

  • string of text for the heading

Examples

#InputOutputStatus
4
heading(2, "Section")
"\n==Section==\n"
5
heading(3, "Sub-section")
"\n===Sub-section===\n"

italic

italic(text)

Parameters

  • text
    The text to italicize.

Returns

  • The italicized text.

Examples

#InputOutputResultStatus
6
italic("Fooloo Limpah")
"<i>Fooloo Limpah</i>"
Fooloo Limpah

inline

inline(text, [options])

Parameters

Returns

  • The formatted text.

Examples

#InputOutputResultStatus
7
inline(
  "Fooloo Limpah",
  {
    bold = true,
    italic = true,
    class = "error",
    tooltip = "Don't steal them!",
  }
)
"<span class=\"error\"><span title=\"Don't steal them!\" class=\"tooltip\"><b><i>Fooloo Limpah</i></b></span></span>"
Fooloo Limpah
8
inline(
  "{{Foo}}",
  {
    bold = true,
    nowiki = true,
    code = true,
  }
)
"<b><code>&#38;#123;&#38;#123;Foo&#38;#125;&#38;#125;</code></b>"
{{Foo}}

lua

lua(text, [options])

Parameters

Returns

  • A block of pre-formatted, syntax-highlighted Lua code

Examples

#InputResult
9
lua("function(foo) \n\t\treturn foo\n\tend")
function(foo) 
		return foo
	end

pre

pre(text, [options])

Parameters

Returns

  • A block of pre-formatted text.

Examples

#InputResult
10
pre("{{List\n\t |foo\n\t |bar\n\t |baz\n\t}}")
{{List
	 |foo
	 |bar
	 |baz
	}}

separateMarkup

separateMarkup(text)

Separates plain text from any wikitext markup that follows it. Used by list templates such as Template:Term List, Template:Gallery List, Template:Wares, etc.

Returns

  • text with trailing markup stripped off
  • Any trailing markup from text, or an empty string if there is none.

Examples

#InputOutputStatus
11
separateMarkup("Some Text <sup>Some Markup</sup>")
"Some Text"
" <sup>Some Markup</sup>"
12
separateMarkup("Some Text")
"Some Text"
""

tooltip

tooltip(baseText, tooltipText, type)

Parameters

Returns

  • Text with a tooltip.

Examples

#InputOutputResultStatus
13
tooltip("hover over me", "hello world!", nil)
'<span title="hello world!" class="tooltip">hover over me</span>'
hover over me


Links

anchor

anchor(id, [display])

Parameters

Returns

  • A link that refers to itself. Useful for linking to specific sections of a page without necessarily using headings.

Examples

#InputOutputResultStatus
14
anchor("foo")
'<span id="foo">[[#foo|foo]]</span>'
foo
15
anchor("bar", "Bar")
'<span id="bar">[[#bar|Bar]]</span>'
Bar
16
anchor("foo bar")
'<span id="foo bar">[[#foo bar|foo bar]]</span>'
foo bar

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
17
category("Items")
"[[Category:Items]]"
Category link from category name with namespace prefix
18
category("Category:Items")
"[[Category:Items]]"
Category link with sort key
19
category("Items", "*")
"[[Category:Items|*]]"

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
20
categories({"Link", "Category:Zelda", "Category:Ganon"})
"[[Category:Link]][[Category:Zelda]][[Category:Ganon]]"
21
categories({})
""

containsLink

containsLink(wikitext)

Returns

  • Given a string of wikitext, returns true if it contains an internal or interwiki link, false otherwise.

Examples

#InputOutputResult
22
containsLink("There is a [[Link]]")
true
23
containsLink("[Link] is not a link but rather an indication of replaced words in a quote.")
false

file

file(name, [options])

Parameters

Returns

  • A string of wikitext that renders a thumbnail for the file.

Examples

#InputOutputResultStatus
24
file("File:ALttP Ganon Sprite.png")
"[[File:ALttP Ganon Sprite.png]]"
25
file(
  "ALttP Ganon Sprite.png",
  {
    caption = "Ganon",
    link = "",
  }
)
"[[File:ALttP Ganon Sprite.png|link=|Ganon]]"
Ganon
26
file(
  "File:TWW Great Fairy Figurine Model.png",
  {
    size = "100px",
    link = "Great Fairy",
  }
)
"[[File:TWW Great Fairy Figurine Model.png|100px|link=Great Fairy]]"
27
file(
  "File:TWW Great Fairy Figurine Model.png",
  {
    noBacklink = true,
    size = "100px",
    link = "Great Fairy",
  }
)
"[[File:TWW Great Fairy Figurine Model.png|100px|link=//zeldawiki.wiki/Great_Fairy]]"
28
file(
  "File:TWW Great Fairy Figurine Model.png",
  {
    class = "notpageimage",
    size = "100px",
    link = "Great Fairy",
  }
)
"[[File:TWW Great Fairy Figurine Model.png|100px|link=Great Fairy|class=notpageimage]]"

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 basic article links - unfortunately non-existent pages are not rendered as red links for performance reasons
29
killBacklinks("[[Link]], [[Princess Zelda|Zelda]], and [[Jean-Guy Rubber Boots]]")
'<span class="plainlinks">[//zeldawiki.wiki/Link Link]</span>, <span class="plainlinks">[//zeldawiki.wiki/Princess_Zelda Zelda]</span>, and <span class="plainlinks">[//zeldawiki.wiki/Jean-Guy_Rubber_Boots Jean-Guy Rubber Boots]</span>'
Link, Zelda, and Jean-Guy Rubber Boots
Does not escape file links or category links
30
killBacklinks("[[Category:Link]] and [[File:SS Blessed Butterfly Icon.png]]")
"[[Category:Link]] and [[File:SS Blessed Butterfly Icon.png]]"
and
Escapes visible file and category links
31
killBacklinks("[[:Category:Link]], [[:Category:Princess Zelda|Zelda]], and [[:File:SS Blessed Butterfly Icon.png]]")
'<span class="plainlinks">[//zeldawiki.wiki/Category:Link Category:Link]</span>, <span class="plainlinks">[//zeldawiki.wiki/Category:Princess_Zelda Zelda]</span>, and <span class="plainlinks">[//zeldawiki.wiki/File:SS_Blessed_Butterfly_Icon.png File:SS Blessed Butterfly Icon.png]</span>'
Category:Link, Zelda, and File:SS Blessed Butterfly Icon.png
Does not affect interwiki links
32
killBacklinks("[[metroidwiki:Chozo|Chozo]]")
"[[metroidwiki:Chozo|Chozo]]"
Chozo

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
33
link("Princess Zelda")
"[[Princess Zelda]]"
Princess Zelda
Piped link
34
link("Princess Zelda", "Zelda")
"[[Princess Zelda|Zelda]]"
Zelda
Category link
35
link("Category:Items")
"[[:Category:Items]]"
Category:Items
Category link without prefix
36
link("Category:Items", "")
"[[:Category:Items|Items]]"
Items
Category link with display text
37
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
File link (to file description)
38
link("File:MM Deku Butler Artwork.png")
"[[:File:MM Deku Butler Artwork.png]]"
File:MM Deku Butler Artwork.png
External link
39
link("https://www.mariowiki.com/Thwomp", "Thwomp")
"[https://www.mariowiki.com/Thwomp Thwomp]"
Thwomp
Looks like an internal link, but it's actually an external link. This is to avoid Special:WhatLinksHere
40
link("Princess Zelda", "Zelda", true)
'<span class="plainlinks">[//zeldawiki.wiki/Princess_Zelda Zelda]</span>'
Zelda
When noBacklink is set to true, red links are not rendered for pages which do not exist, for performance reasons.
41
link("Flippityfloppityfloo", nil, true)
'<span class="plainlinks">[//zeldawiki.wiki/Flippityfloppityfloo Flippityfloppityfloo]</span>'
Flippityfloppityfloo

sectionLink

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

Parameters

Returns

  • A string of wikitext rendering a section link.

Examples

#InputOutputResultStatus
42
sectionLink("Link", "Ocarina of Time", "Hero of Time")
"[[Link#Ocarina of Time|Hero of Time]]"
Hero of Time
43
sectionLink("Link", nil, "Hero of Time")
"[[Link|Hero of Time]]"
Hero of Time
44
sectionLink("Link", "")
"[[Link#]]"
Link#

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
45
stripCategories("<[[Category:Link]][[Category:Princess Zelda]][[Category:Link]]>")
"<>"
{
  "[[:Category:Link]]",
  "[[:Category:Princess Zelda]]",
}
Does not affect visual links to category description pages
46
stripCategories("[[:Category:Link]] and [[:Category:Princess Zelda]]")
"[[:Category:Link]] and [[:Category:Princess Zelda]]"
{}


Lists

list

list(items)

Parameters

  • items
    An array of strings (list items).

Returns

  • An unordered list with the plainlist class.

Examples

#InputOutputResultStatus
47
list({})
""
48
list({"single item"})
'<ul class="plainlist"><li>single item</li></ul>'
  • single item
49
list({"multiple", "items", ""})
'<ul class="plainlist"><li>multiple</li><li>items</li><li></li></ul>'
  • multiple
  • items

bulletList

bulletList(items, [attributes])

Parameters

  • items
    An array of strings (list items).
  • [attributes]
    [class]
    Sets the class attribute of HTML list tag. Note that this is recursively applied to sub-lists.

Returns

  • A string representation of an unordered list using HTML syntax.

Examples

#InputOutputResultStatus
50
bulletList({})
""
51
bulletList({"single item"})
"<ul><li>single item</li></ul>"
  • single item
52
bulletList({"multiple", "items", ""})
"<ul><li>multiple</li><li>items</li><li></li></ul>"
  • multiple
  • items
53
bulletList(
  {
    "list",
    {
      "with",
      {"nested", "items"},
      "inside",
    },
  },
  { class = "custom-class" }
)
'<ul class="custom-class"><li>list</li><ul class="custom-class"><li>with</li><ul class="custom-class"><li>nested</li><li>items</li></ul><li>inside</li></ul></ul>'
  • list
    • with
      • nested
      • items
    • inside

numberList

numberList(items, [attributes])

Parameters

  • items
    An array of strings (list items).
  • [attributes]
    [class]
    Sets the class attribute of HTML list tag. Note that this is recursively applied to sub-lists.
    [start]
    Sets the starting value.

Returns

  • A string representation of an ordered list using HTML syntax.

Examples

#InputOutputResultStatus
54
numberList({})
""
55
numberList({"single item"})
"<ol><li>single item</li></ol>"
  1. single item
56
numberList({"multiple", "items", ""})
"<ol><li>multiple</li><li>items</li><li></li></ol>"
  1. multiple
  2. items
57
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
58
numberList(
  {"Eight", "Nine", "Ten"},
  {
    start = 8,
    class = "custom-class",
  }
)
'<ol start="8" class="custom-class"><li>Eight</li><li>Nine</li><li>Ten</li></ol>'
  1. Eight
  2. Nine
  3. Ten

definitionList

definitionList(pairs, [attributes])

Parameters

  • pairs
    Array of table of pairs where the first pair item is a term and the value is a definition.
  • [attributes]
    [class]
    Sets the class attribute of HTML list tag. Note that this is recursively applied to sub-lists.

Returns

  • A string representation of a definition list using HTML syntax.

Examples

#InputResultStatus
59
definitionList({})
60
definitionList({
  {"key1", "value1"},
})
key1
value1
61
definitionList({
  {"key1", "value1"},
  {"key2", "value2"},
})
key1
value1
key2
value2
62
definitionList({
  {"", "value1"},
  {[2] = "value2" },
  {"key3", ""},
  {"key4"},
})
value1
value2
key3
key4
63
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
64
definitionList(
  {
    {
      "key 1",
      "value 1.1",
      {
        {"key 1.1", "value 1.2"},
        {"key 1.2", "value 1.2"},
      },
    },
  },
  { class = "custom-class" }
)
key 1
value 1.1
key 1.1
value 1.2
key 1.2
value 1.2

local utilsPackage = require("Module:UtilsPackage")

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