模板:Nowrap begin/doc

来自决策链云智库
< 模板:Nowrap begin
Zeroclanzhang讨论 | 贡献2024年1月22日 (一) 15:44的版本 (创建页面,内容为“{{Documentation subpage}} <!-- PLEASE ADD CATEGORIES WHERE INDICATED THE BOTTOM OF THIS PAGE --> This template prevents word wraps (line breaks) in text and links with spaces in. It is designed to handle the really tricky wrapping cases where you need full control. It works similarly to {{tl|nowrap}} and {{tl|nowraplinks}}. This template takes no parameters; instead, it works in tandem with {{tl|nowrap end}}. {{Ambox |text='''Note:''' The use of these templat…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

This template prevents word wraps (line breaks) in text and links with spaces in. It is designed to handle the really tricky wrapping cases where you need full control. It works similarly to {{nowrap}} and {{nowraplinks}}. This template takes no parameters; instead, it works in tandem with {{nowrap end}}.

Helper templates

This template has a number of helper templates which allows you to tell the web browser exactly where line breaks may occur:

Note: These helper templates may only be used in sections surrounded by {{nowrap begin}} and {{nowrap end}} or they may cause weird behaviour of your page.

  • {{wrap}} – Marks where a wrap may occur.

Usage

{{nowrap begin}}

[[Salt]] and{{wrap}} [[Pepper]] and{{wrap}} [[Curry]]
and{{wrap}} [[Saffron]].{{wrap}}
[[Salt]] and{{wrap}} [[Pepper]] and{{wrap}} [[Curry]]
and{{wrap}} [[Saffron]].

{{nowrap end}}

It will render something like this:

Salt and Pepper and Curry and
Saffron. Salt and Pepper and
Curry and Saffron.

But it will not render like this:

Salt and Pepper and Curry
and Saffron. Salt and Pepper
and Curry and Saffron.

To make your code readable and easy to edit, you can put each wrappable "line" on its own line. And let's use some dots too. Like this:

{{nowrap begin}}

[[Salt]] and [[Pepper]]{{·}}{{wrap}}
[[Pepper]] and [[Curry]]{{·}}{{wrap}}
[[Curry]] and [[Saffron]]{{·}}{{wrap}}
[[Saffron]] and [[Salt]]

{{nowrap end}}

It will render something like this:

Salt and Pepper · Pepper and Curry ·
Curry and Saffron · Saffron and Salt

But it will not render like this:

Salt and Pepper · Pepper
and Curry · Curry and Saffron
· Saffron and Salt

Examples

Here are the above examples in actual running code in a table. Try dragging the width of your web browser window so it becomes smaller and smaller and watch how the line wrapping behaves:

Salt and模板:Wrap Pepper and模板:Wrap Curry and模板:Wrap Saffron.模板:Wrap Salt and模板:Wrap Pepper and模板:Wrap Curry and模板:Wrap Saffron. 模板:Nowrap end

Salt and Pepper模板:·模板:Wrap Pepper and Curry模板:·模板:Wrap Curry and Saffron模板:·模板:Wrap Saffron and Salt 模板:Nowrap end

An example demonstrating all the helper templates:

Salt模板:Wrap Pepper模板:Wrap Curry模板:·模板:Wrap Saffron模板:·模板:Wrap Salt • 模板:Wrap Pepper • 模板:Wrap Curry – 模板:Wrap Saffron – 模板:Wrap Salt |模板:Wrap Pepper |模板:Wrap Curry模板:·模板:Wrap Saffron模板:·模板:Wrap Salt 模板:Nowrap end

Salt模板:Wrap Pepper模板:Wrap Curry模板:·模板:Wrap Saffron模板:·模板:Wrap Salt • 模板:Wrap Pepper • 模板:Wrap Curry – 模板:Wrap Saffron – 模板:Wrap Salt |模板:Wrap Pepper |模板:Wrap Curry模板:·模板:Wrap Saffron模板:·模板:Wrap Salt 模板:Nowrap end

Technical details

The actual code that does the job is this HTML+CSS code:

<span class="nowrap"> Text and links <span class="wrap"> </span> More text and links </span>

{{·}} and the other helper templates should not have any spaces or newlines before them or they will render two spaces before the dot. They tolerate anything from no to several spaces and even a newline after them and they will still only render one space after the dot. If a wrap occurs then the wrap will come after the dot, even if there are spaces before the helper template.

The {{·}} causes problems if inside sections of bolded and/or italicised text. Do end the bold text before the {{·}} and continue the bold text after it to avoid the problems. {{}} and the other helper templates only have this problem if the section is bolded and italicised at the same time.

See also

模板:List of nowrap-like templates