Misplaced Pages

Template:Nowrap/doc: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
< Template:Nowrap Browse history interactively← Previous editContent deleted Content addedVisualWikitext
Revision as of 19:08, 14 December 2006 edit68.38.27.197 (talk)No edit summary← Previous edit Latest revision as of 03:01, 8 December 2024 edit undoCFA (talk | contribs)Extended confirmed users, Page movers, IP block exemptions, New page reviewers, Pending changes reviewers, Rollbackers41,964 editsm Reverted edits by 2806:2F0:1140:AFED:CC:3255:3B50:8EDD (talk): disruptive edits (HG) (3.4.13)Tags: Huggle Rollback 
(151 intermediate revisions by 99 users not shown)
Line 1: Line 1:
{{Documentation subpage}}
<includeonly>{{template doc page transcluded}}</includeonly><noinclude>{{template doc page viewed directly}}</noinclude>
<!-- Categories go where indicated at the bottom of this page, please; interwikis go to Wikidata (see also: ]) -->
<!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE -->
{{used in system|in ]}}
{{cascade-protected template}}
{{COinS safe|n}}
{{tsh|nobr|nobreak|nwr}}


{{tlx|Nowrap}} or {{tlx|nowrap}} stops ] 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.
; Syntax : <code><big><nowiki>{{nowrap|</nowiki>''-. --- .-- .-. .- .--. .-.-.- -.. --- -.-.''}}</big></code>


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


== Usage ==
<includeonly>
:: <code><nowiki>{{Nowrap|these words stay together}}</nowiki></code>
<!-- ADD CATEGORIES BELOW THIS LINE -->
:: <code><nowiki>{{Nowrap|a, b, c, or d.}}</nowiki></code>
]
:: <code><nowiki>{{Nowrap| merry-go-round }}</nowiki></code>
:: <code><nowiki>{{Nowrap| ] }}</nowiki></code>
:: <code><nowiki>{{Nowrap| ] }}</nowiki></code>
:: <code><nowiki>{{Nowrap| ] }}</nowiki></code>


=== Examples ===
<!-- ADD INTERWIKIS BELOW THIS LINE -->
{| class=wikitable
</includeonly>
|"<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&nbsp;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 ] for details.

=== Handling equal-sign or bar ===
] have problems with parameter data that contains ]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> magic word. 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 ].

== TemplateData ==
{{TemplateData header}}
<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 ==
{{List of nowrap-like templates}}

<includeonly>{{Sandbox other||
<!-- Categories go below this line, please; interwikis go to Wikidata, thank you! -->
]

}}</includeonly>

Latest revision as of 03:01, 8 December 2024

This is a documentation subpage for Template:Nowrap.
It may contain usage information, categories and other content that is not part of the original template page.
WarningThis template is used in MediaWiki:Histlegend, and on approximately 8,770,000 pages, or roughly 14% of all pages.
Changes to it can cause immediate changes to the Misplaced Pages user interface.
To avoid major disruption and server load, any changes should be tested in the template's /sandbox or /testcases subpages, or in your own user subpage. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them.
This template can only be edited by administrators because it is transcluded onto one or more cascade-protected pages.
This template should not be used in citation templates such as Citation Style 1 and Citation Style 2, because it includes markup that will pollute the COinS metadata they produce; see Misplaced Pages:COinS.
Shortcuts

{{Nowrap}} or {{nowrap}} 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.

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

Usage

{{Nowrap|these words stay together}}
{{Nowrap|a, b, c, or d.}}
{{Nowrap| merry-go-round }}
{{Nowrap| ] }}
{{Nowrap| ] }}
{{Nowrap| ] }}

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 {{=}} magic word. 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

This is the TemplateData for this template used by TemplateWizard, VisualEditor and other tools. See a monthly parameter usage report for Template:Nowrap in articles based on its TemplateData.

TemplateData for Nowrap

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

  • {{nowrap}} prevents wrapping within a single template (i.e. not suitable for relatively complex or lengthy content).
  • {{nowraplinks}} ... {{nowraplinks end}} prevents wraps inside links while allowing wraps between links and in normal text. Very useful for link lists and easy to use.
  • {{nowrap begin}} ... {{nowrap end}} prevents wraps in both text and links. For the trickier wrapping cases when you need full control, for instance in very complex link lists.
  • {{word joiner}} prevents wraps for both two adjacent characters.
  • {{avoid wrap}} prevents wraps unless the space is too narrow to display the text on one line.
    • {{inline block}} does the same and allows further style customization, but does not automatically add the "avoidwrap" CSS class.
  • {{spaces}} produces multiple non-breaking spaces (or a single one).
  • {{wrap}} can be used to provide a (brief) exception within a no-wrapping area.
    • {{normalwraplink}} allows links to wrap when they otherwise would not.
  • {{·}} and {{•}}, spaced and wrap-sensitive interpunct (dot) and bullet.
  • Help:Line-break handling, Misplaced Pages's how-to guide about word wrapping and line breaks.
    • In particular, to avoid line wrapping when quoting a passage such as a poem or computer code, see Template:Quote § Line breaks – e.g. Template:Blockquote with "poem" tag.