<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AFormat_link%2Fdoc</id>
	<title>Module:Format link/doc - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AFormat_link%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Format_link/doc&amp;action=history"/>
	<updated>2026-04-16T18:56:13Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Format_link/doc&amp;diff=136311&amp;oldid=prev</id>
		<title>imported&gt;Nihiltres: Added missing &quot;Errors&quot; section</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Format_link/doc&amp;diff=136311&amp;oldid=prev"/>
		<updated>2022-01-08T22:33:15Z</updated>

		<summary type="html">&lt;p&gt;Added missing &amp;quot;Errors&amp;quot; section&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;!-- Add categories where indicated at the bottom of this page and interwikis at Wikidata --&amp;gt;&lt;br /&gt;
{{used in system|in [[MediaWiki:Perfcachedts]]}}&lt;br /&gt;
This module, migrated from origins in [[Module:Hatnote]], provides functionality for formatting links for display, including that powering the {{tl|format link}} template.&lt;br /&gt;
&lt;br /&gt;
It can pretty-format section links with the section symbol (&amp;quot;§&amp;quot;) and appropriate whitespace, it automatically escapes category and file names with the [[Help:Colon trick|colon trick]], and includes functionality for italicizing the page or section name, and for detecting and categorizing results that produce [[Wikipedia:Red link|red links]].&lt;br /&gt;
&lt;br /&gt;
== Use from wikitext ==&lt;br /&gt;
The functions in this module cannot be used directly from #invoke, and must be used through templates instead. Please see [[Template:Format link]] for documentation on usage of that template. &lt;br /&gt;
&lt;br /&gt;
== Use from other Lua modules==&lt;br /&gt;
To load this module from another Lua module, use the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local mFormatLink = require(&amp;#039;Module:Format link&amp;#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can then use the functions as documented below.&lt;br /&gt;
&lt;br /&gt;
=== _formatLink ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
mFormatLink._formatLink{&lt;br /&gt;
    link = &amp;#039;Link&amp;#039;,&lt;br /&gt;
    display = &amp;#039;Display&amp;#039;,&lt;br /&gt;
    target = &amp;#039;Target&amp;#039;,&lt;br /&gt;
    italicizePage = true,&lt;br /&gt;
    italicizeSection = true,&lt;br /&gt;
    categorizeMissing = &amp;#039;Pages using formatted red links&amp;#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Formats &amp;lt;var&amp;gt;link&amp;lt;/var&amp;gt; as a wikilink. Categories and files are automatically escaped with the [[Help:Colon trick|colon trick]], and links to sections are automatically formatted as &amp;#039;&amp;#039;page § section&amp;#039;&amp;#039;, rather than the MediaWiki default of &amp;#039;&amp;#039;page#section&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
Several options modify the output:&lt;br /&gt;
* If the &amp;lt;var&amp;gt;display&amp;lt;/var&amp;gt; value is present, then it will be used as a display value. Any manual piping (using the &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{!}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; magic word or similar) present in &amp;lt;var&amp;gt;link&amp;lt;/var&amp;gt; will be overridden by the &amp;lt;var&amp;gt;display&amp;lt;/var&amp;gt; value if present.&lt;br /&gt;
* If the &amp;lt;var&amp;gt;target&amp;lt;/var&amp;gt; value is present, then it will override &amp;lt;var&amp;gt;link&amp;lt;/var&amp;gt; as a target, but the result will still be &amp;#039;&amp;#039;displayed&amp;#039;&amp;#039; using either the value from &amp;lt;var&amp;gt;display&amp;lt;/var&amp;gt;, or the result of formatting &amp;lt;var&amp;gt;link&amp;lt;/var&amp;gt;.&lt;br /&gt;
* If &amp;lt;var&amp;gt;italicizePage&amp;lt;/var&amp;gt; is true, then the page portion of the link is italicized if present.&lt;br /&gt;
* If &amp;lt;var&amp;gt;italicizeSection&amp;lt;/var&amp;gt; is true, then the section portion of the link is italicized if present.&lt;br /&gt;
* If &amp;lt;var&amp;gt;categorizeMissing&amp;lt;/var&amp;gt; is a non-empty string, then that value is used as a category name, and that category will be applied if the resulting target of the link (no matter whether through &amp;lt;var&amp;gt;link&amp;lt;/var&amp;gt; or through &amp;lt;var&amp;gt;target&amp;lt;/var&amp;gt;) doesn&amp;#039;t exist.&lt;br /&gt;
&lt;br /&gt;
;Examples:&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; inline&amp;gt;mFormatLink._formatLink{link = &amp;#039;Foo#Bar&amp;#039;}&amp;lt;/syntaxhighlight&amp;gt; &amp;amp;rarr; &amp;lt;nowiki&amp;gt;[[:Foo#Bar|Foo §&amp;amp;amp;nbsp;Bar]]&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{format link|Foo#Bar}}&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; inline&amp;gt;mFormatLink._formatLink{link = &amp;#039;Baz&amp;#039;, display = &amp;#039;Qux&amp;#039;}&amp;lt;/syntaxhighlight&amp;gt; &amp;amp;rarr; &amp;lt;nowiki&amp;gt;[[:Baz|Qux]]&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{format link|Baz|Qux}}&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; inline&amp;gt;mFormatLink._formatLink{link = &amp;#039;Foo|Bar&amp;#039;, display = &amp;#039;Baz&amp;#039;}&amp;lt;/syntaxhighlight&amp;gt; &amp;amp;rarr; &amp;lt;nowiki&amp;gt;[[:Foo|Baz]]&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{format link|Foo{{!}}Bar|Baz}}&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; inline&amp;gt;mFormatLink._formatLink{link = &amp;#039;#Foo&amp;#039;, target = &amp;#039;Example#Foo&amp;#039;}&amp;lt;/syntaxhighlight&amp;gt; &amp;amp;rarr; &amp;lt;nowiki&amp;gt;[[:Example#Foo|§&amp;amp;amp;nbsp;Foo]]&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{format link|#Foo||Example#Foo}}&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; inline&amp;gt;mFormatLink._formatLink{link = &amp;#039;The Lord of the Rings#Plot&amp;#039;, italicizePage = true}&amp;lt;/syntaxhighlight&amp;gt; &amp;amp;rarr; &amp;lt;nowiki&amp;gt;[[:The Lord of the Rings#Plot|&amp;#039;&amp;#039;The Lord of the Rings&amp;#039;&amp;#039; §&amp;amp;amp;nbsp;Plot]]&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{format link|The Lord of the Rings#Plot|italicizepage=true}}&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; inline&amp;gt;mFormatLink._formatLink{link = &amp;#039;Cybercrime Prevention Act of 2012#Disini v. Secretary of Justice&amp;#039;, italicizeSection = true}&amp;lt;/syntaxhighlight&amp;gt; &amp;amp;rarr; &amp;lt;nowiki&amp;gt;[[:Cybercrime Prevention Act of 2012#Disini v. Secretary of Justice|Cybercrime Prevention Act of 2012 §&amp;amp;amp;nbsp;&amp;#039;&amp;#039;Disini v. Secretary of Justice&amp;#039;&amp;#039;]]&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{format link|Cybercrime Prevention Act of 2012#Disini v. Secretary of Justice|italicizesection=true}}&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; inline&amp;gt;mFormatLink._formatLink{link = &amp;#039;Nonexistent page&amp;#039;, categorizeMissing = &amp;#039;Example&amp;#039;}&amp;lt;/syntaxhighlight&amp;gt; &amp;amp;rarr; &amp;lt;nowiki&amp;gt;[[:Nonexistent page]][[Category:Example]]&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{format link|Nonexistent page}}&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; inline&amp;gt;mFormatLink._formatLink{link = &amp;#039;Existing&amp;#039;, categorizeMissing = &amp;#039;Example&amp;#039;}&amp;lt;/syntaxhighlight&amp;gt; &amp;amp;rarr; &amp;lt;nowiki&amp;gt;[[:Existing]]&amp;lt;/nowiki&amp;gt; &amp;amp;rarr; {{format link|Existing}}&lt;br /&gt;
&lt;br /&gt;
=== formatPages ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
mFormatLink.formatPages(options, pages)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This derived function is useful for lists that format many links. It formats an array of pages using the [[#_formatLink|_formatLink]] function, and returns the result as an array. Options in the &amp;lt;var&amp;gt;options&amp;lt;/var&amp;gt; table are applied, and use the same names as the options for &amp;lt;var&amp;gt;_formatLink&amp;lt;/var&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
;Example&lt;br /&gt;
:{{code|&amp;lt;nowiki&amp;gt;mFormatLink.formatPages({categorizeMissing = &amp;#039;Example&amp;#039;}, {&amp;#039;Foo#Bar&amp;#039;, &amp;#039;Nonexistent page&amp;#039;})&amp;lt;/nowiki&amp;gt;|lua}} &amp;amp;rarr; {{code|&amp;lt;nowiki&amp;gt;{&amp;#039;[[:Foo#Bar|Foo §&amp;amp;nbsp;Bar]]&amp;#039;, &amp;#039;[[:Nonexistent page]][[Category:Example]]&amp;#039;}&amp;lt;/nowiki&amp;gt;|lua}}&lt;br /&gt;
&lt;br /&gt;
== Errors ==&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;var&amp;gt;_formatLink&amp;lt;/var&amp;gt; is used and neither a &amp;lt;var&amp;gt;link&amp;lt;/var&amp;gt; nor a &amp;lt;var&amp;gt;target&amp;lt;/var&amp;gt; argument is provided, then the module will produce an error message instead of its usual output, as it &amp;#039;&amp;#039;cannot&amp;#039;&amp;#039; then produce valid output.&lt;br /&gt;
&lt;br /&gt;
You can solve this error by providing appropriate parameters to &amp;lt;var&amp;gt;_formatLink&amp;lt;/var&amp;gt;, or you may want to ensure that a more descriptive error is provided by a downstream template or module when it would otherwise call &amp;lt;var&amp;gt;_formatLink&amp;lt;/var&amp;gt; with inadequate arguments.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;includeonly&amp;gt;{{Sandbox other||&lt;br /&gt;
&amp;lt;!-- Categories below this line; interwikis at Wikidata --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</summary>
		<author><name>imported&gt;Nihiltres</name></author>
	</entry>
</feed>