Template:Nowrap/doc View history

m (Updated doc page)
(Expanded doc before merge)
 
Line 1: Line 1:
{{doc subpage}}
{{Documentation subpage}}
<!-- ADD DOCUMENTATION BELOW THIS LINE -->
<!-- Categories go where indicated at the bottom of this page -->
Template to add no-break spaces and no-break hyphens between words.<br/>


==Syntax==
The {{tlx|nowrap}} template stops line 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&nbsp;("-"), 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.
<code><nowiki>{{nowrap</nowiki>|''text''}}</code><br />
If the <code>text</code> happens to contain an equality sign "=", specify <code><nowiki>{{nowrap</nowiki>|'''1='''''text''}}</code>.  


==Examples==
To achieve the opposite effect of <code>&#123;&#123;nowrap&#125;&#125;</code>, you can use {{tlx|wbr}}. For more information about wrapping and breaking sentences, see [[Wikipedia:Line-break handling]].
{| style="background:transparent;"
 
|<code><nowiki>{{nowrap|This text will not wrap.}} {{nowrap|This text will not wrap.}} {{nowrap|This text will not wrap.}} {{nowrap|This text will not wrap.}} {{nowrap|This text will not wrap.}}</nowiki></code>
== Usage ==
| style="width: 225px;"|{{nowrap|This text will not wrap.}} {{nowrap|This text will not wrap.}} {{nowrap|This text will not wrap.}} {{nowrap|This text will not wrap.}} {{nowrap|This text will not wrap.}}
:: <code><nowiki>{{Nowrap|these words stay together}}</nowiki></code>
|-
:: <code><nowiki>{{Nowrap|a, b, c, or d.}}</nowiki></code>
|<code><nowiki>This text will wrap. This text will wrap. This text will wrap. This text will wrap. This text will wrap. </nowiki></code>
:: <code><nowiki>{{Nowrap| merry-go-round }}</nowiki></code>
| This text will wrap. This text will wrap. This text will wrap. This text will wrap. This text will wrap.  
:: <code><nowiki>{{Nowrap| [[4-part harmony]] }}</nowiki></code>
:: <code><nowiki>{{Nowrap| [[Cascading Style Sheets|CSS]] }}</nowiki></code>
:: <code><nowiki>{{Nowrap| [[#Examples|Examples section]] }}</nowiki></code>
 
=== Examples ===
{| class=wikitable
|"<code>They held <nowiki>{{Nowrap|10 kg (22 lb)}}</nowiki> in total.</code>"
<br/> May render like this:
:They held {{Nowrap|10 kg (22 lb)}} <br/>in total.
<br/> Or like this:
:They held <br/>10 kg (22 lb) in total.
<br/> But ''not'' render like this:
:They held 10 kg (22 <br/>lb) in total.
 
| "<code>He encountered <nowiki>{{Nowrap|a tiger}}</nowiki> in the woods.</code>"
<br/> May render like this:
:He encountered a tiger <br/>in the woods.
<br/> Or like this:
:He encountered <br/>a tiger in the woods.
<br/> But ''not'' like this:
:He encountered a <br/>tiger in the woods.
|}
|}
=== Controlling line-breaking in infoboxes ===
This template may be used with {{tlx|Wbr}} and {{tlx|Spaces}} to control line-breaking in bulletless lists in infoboxes, to prevent wrapped long entries from being confused with multiple entries. See [[Template:Wbr/doc#Controlling line-breaking in infoboxes]] for details.
=== Handling equal-sign or bar ===
[[Help:Template|Templates]] have problems with parameter data that contains [[equal-sign]]s "<code>=</code>" or vertical bars "<code>|</code>" (pipes). Note that this does not apply if the equal-sign "<code>=</code>" or vertical bar "<code>|</code>" is inside a wikilink or another template.  In the case that there is a bare equal-sign "<code>=</code>" or vertical bar "<code>|</code>", consider using {{tl|Nowrap begin}} + {{tl|Nowrap end}} instead. However, there are also other workarounds:
For text that includes an equal-sign "=", precede the text with <code>1=</code>, use a triple-brace unnamed parameter <code><nowiki>{{{|=}}}</nowiki></code>, or the <code><nowiki>{{=}}</nowiki></code> template. For example:
:<code><nowiki>{{Nowrap|</nowiki>1=2 + 2 = 4}}</code>, <br /><code><nowiki>{{Nowrap|2 + 2 {{{|=}}} 4}}</nowiki></code>, or <br /><code><nowiki>{{Nowrap|2 + 2 {{=}} 4}}</nowiki></code>
which all render as this:
:{{Nowrap|1=2 + 2 = 4}}.
For text that includes a vertical bar "|", escape the bar(s) with "<code><nowiki>&amp;#124;</nowiki></code>" or "<code><nowiki>{{pipe}}</nowiki></code>" or "<code><nowiki>{{abs}}</nowiki></code>". For instance, put two bars "|6|" like this:
:<code><nowiki>{{Nowrap|</nowiki>&amp;#124;6&amp;#124; < 7}}</code> &nbsp;or&nbsp; <code><nowiki>{{Nowrap|{{pipe}}6{{pipe}} < 7}}</nowiki></code> &nbsp;or&nbsp; <code><nowiki>{{Nowrap|{{abs|6}} < 7}}</nowiki></code>
Which renders this:
:{{Nowrap|&#124;6&#124; < 7}}
== Technical details ==
The actual code that does the job is this HTML {{tag|span|open|link=yes}} tag that applies a class to the text inside the template:
:{{code|lang=html|1=<span class="nowrap">This text will not wrap</span>}}
The class <code>nowrap</code> receives the CSS property {{code|lang=css|white-space: nowrap;}} in [[MediaWiki:Common.css]].
== TemplateData ==
<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==
==See also==
Line 22: Line 77:
<!-- ADD CATEGORIES BELOW THIS LINE -->
<!-- ADD CATEGORIES BELOW THIS LINE -->
[[Category:Formatting templates]]
[[Category:Formatting templates]]
[[Category:Line-handling templates]]
[[Category:Incomplete templates]]
<!-- ADD INTERWIKIS BELOW THIS LINE -->
<!-- ADD INTERWIKIS BELOW THIS LINE -->


</includeonly>
</includeonly>

Latest revision as of 22:02, 24 August 2022

This is a documentation subpage for Template:Nowrap.
It contains usage information, categories and other content that is not part of the original template page.

The {{nowrap}} template stops line 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.

To achieve the opposite effect of {{nowrap}}, you can use {{wbr}}. For more information about wrapping and breaking sentences, see Wikipedia:Line-break handling.

Usage

{{Nowrap|these words stay together}}
{{Nowrap|a, b, c, or d.}}
{{Nowrap| merry-go-round }}
{{Nowrap| [[4-part harmony]] }}
{{Nowrap| [[Cascading Style Sheets|CSS]] }}
{{Nowrap| [[#Examples|Examples section]] }}

Examples

"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.

Controlling line-breaking in infoboxes

This template may be used with {{Wbr}} and {{Spaces}} to control line-breaking in bulletless lists in infoboxes, to prevent wrapped long entries from being confused with multiple entries. See Template:Wbr/doc#Controlling line-breaking in infoboxes for details.

Handling equal-sign or bar

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. In the case that there is a bare equal-sign "=" or vertical bar "|", consider using {{Nowrap begin}} + {{Nowrap end}} instead. However, there are also other workarounds:

For text that includes an equal-sign "=", precede the text with 1=, use a triple-brace unnamed parameter {{{|=}}}, or the {{=}} template. For example:

{{Nowrap|1=2 + 2 = 4}},
{{Nowrap|2 + 2 {{{|=}}} 4}}, or
{{Nowrap|2 + 2 {{=}} 4}}

which all render as this:

2 + 2 = 4.

For text that includes a vertical bar "|", escape the bar(s) with "&#124;" or "{{pipe}}" or "{{abs}}". For instance, put two bars "|6|" like this:

{{Nowrap|&#124;6&#124; < 7}}  or  {{Nowrap|{{pipe}}6{{pipe}} < 7}}  or  {{Nowrap|{{abs|6}} < 7}}

Which renders this:

|6| < 7

Technical details

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

<span class="nowrap">This text will not wrap</span>

The class nowrap receives the CSS property white-space: nowrap; in MediaWiki:Common.css.

TemplateData

Prevents word wraps (line breaks) within text or inside a link which contains spaces or hyphens (-).

Template parameters

ParameterDescriptionTypeStatus
Text1

Text or link to be protected.

Stringrequired

See also

  • {{nowrapcode}}, to use the code tags without linewrap.