Jump to content

Template:Nowrap/doc

From Factory Town 2 Wiki

This code is adapted from Wikipedia.

For the original code, see the following pages: Template:Nowrap/doc

Script error: No such module "Template link". or Script error: No such module "Template link". stops wrapping of specific text (which can be inside of a link). Use this template sparingly. It prevents word wraps (line breaks) that might otherwise happen at spaces, hyphens ("-"), or, in some browsers, parentheses. The size of the nowrapped text becomes the minimum width of that paragraph and that can negatively influence the ability of the page to adapt to smaller screens, or alternate representations of the content.

Usage

[edit]
<syntaxhighlight lang="wikitext" inline>these words stay together</syntaxhighlight> → these words stay together
<syntaxhighlight lang="wikitext" inline>a, b, c, or d.</syntaxhighlight> → a, b, c, or d.
<syntaxhighlight lang="wikitext" inline> merry-go-round </syntaxhighlight> → merry-go-round
<syntaxhighlight lang="wikitext" inline> 4-part harmony </syntaxhighlight> → 4-part harmony
<syntaxhighlight lang="wikitext" inline> CSS </syntaxhighlight> → CSS
<syntaxhighlight lang="wikitext" inline> Examples section </syntaxhighlight> → Examples section
<syntaxhighlight lang="wikitext" inline>{{{1}}}</syntaxhighlight> → {{{1}}}
<syntaxhighlight lang="wikitext" inline>A very long sentence that should wrap when the window becomes smaller but which is prevented from wrapping by this template, which prevents normal line wrapping of long strings that are wrapped in the template.</syntaxhighlight> → A very long sentence that should wrap when the window becomes smaller but which is prevented from wrapping by this template, which prevents normal line wrapping of long strings that are wrapped in the template.


Examples

[edit]
"They held {{Nowrap|10 kg (22 lb)}} in total."


May render like this:

They held 10 kg (22 lb)
in total.


Or like this:

They held
10 kg (22 lb) in total.


But not render like this:

They held 10 kg (22
lb) in total.
"He encountered {{Nowrap|a tiger}} in the woods."


May render like this:

He encountered a tiger
in the woods.


Or like this:

He encountered
a tiger in the woods.


But not like this:

He encountered a
tiger in the woods.

Handling equal-sign or bar

[edit]

Templates have problems with parameter data that contains equal-signs "=" or vertical bars "|" (pipes). Note that this does not apply if the equal-sign "=" or vertical bar "|" is inside a wikilink or another template.

For text that includes an equal-sign "=", precede the text with 1=, use a triple-brace unnamed parameter <syntaxhighlight lang="wikitext" inline>=</syntaxhighlight>, or the <syntaxhighlight lang="wikitext" inline>=</syntaxhighlight> magic word. For example:

<syntaxhighlight lang="wikitext" inline>2 + 2 = 4</syntaxhighlight>,
<syntaxhighlight lang="wikitext" inline>2 + 2 = 4</syntaxhighlight>, or
<syntaxhighlight lang="wikitext" inline>2 + 2 = 4</syntaxhighlight>

which all render as this:

2 + 2 = 4.

For text that includes a vertical bar "|", escape the bar(s) with "<syntaxhighlight lang="wikitext" inline>|</syntaxhighlight>" or "<syntaxhighlight lang="wikitext" inline>|</syntaxhighlight>" or "<syntaxhighlight lang="wikitext" inline>|</syntaxhighlight>". For instance, put two bars "|6|" like this:

<syntaxhighlight lang="wikitext" inline>|6| < 7</syntaxhighlight>  or  <syntaxhighlight lang="wikitext" inline>|6| < 7</syntaxhighlight>  or  <syntaxhighlight lang="wikitext" inline>|6| < 7</syntaxhighlight>

Which renders this:

|6| < 7

Technical details

[edit]

The actual code that does the job is this HTML <span> tag that applies a class to the text inside the template:

<syntaxhighlight lang="html" inline="">This text will not wrap</syntaxhighlight>

The class nowrap receives the CSS property <syntaxhighlight lang="css" inline="">white-space: nowrap;</syntaxhighlight> in MediaWiki:Common.css.

TemplateData

[edit]

<templatedata>{

 "description": "Prevents word wraps (line breaks) within text or inside a link which contains spaces or hyphens (-).",
 "params": {
   "1": {
     "label": "Text",
     "description": "Text or link to be protected.",
     "type": "string",
     "required": true
   }
 }

}</templatedata>

See also

[edit]

Dependencies

[edit]

For this template to work properly, you need the following: