Difference between revisions of "Template:Spaced en dash/doc"

From Timelines
Jump to: navigation, search
(Bolded name in the first sentence, and code marked as code.)
(Updated the documentation to reflect the new template code.)
Line 4: Line 4:
 
This is the '''ndash''' template, it looks like this " – ".  
 
This is the '''ndash''' template, it looks like this " – ".  
  
It works similarly to the html markup sequence "<code>'''&amp;nbsp;&amp;ndash;'''&nbsp;</code>". That is, a [[non-breaking space]], a short dash and a normal space. However this template includes some extra code that makes it behave slightly better than the html markup sequence.
+
It works similarly to the html markup sequence "<code>'''&amp;nbsp;&amp;ndash;'''&nbsp;</code>". That is, a [[non-breaking space]], a short dash and a normal space.  
  
 
[[Template:–|<nowiki>{{&ndash;}}</nowiki>]] redirects here and can be used as an alternative name for this template.
 
[[Template:–|<nowiki>{{&ndash;}}</nowiki>]] redirects here and can be used as an alternative name for this template.
Line 41: Line 41:
 
=== Incorrect usage ===
 
=== Incorrect usage ===
  
If the template is used slightly wrong it will in most cases still behave well. For instance if there are no or several spaces after the template. Like these examples:
+
If the template is used slightly wrong it will in some cases still behave well. For instance if there are no or several spaces after the template. Like these examples:
  
 
  <nowiki>[[Salt]]{{ndash}}[[Pepper]]</nowiki>
 
  <nowiki>[[Salt]]{{ndash}}[[Pepper]]</nowiki>
Line 53: Line 53:
 
:[[Pepper]]
 
:[[Pepper]]
  
But putting one or more spaces before the template can cause problems, like these examples:
+
But putting one or more spaces before the template will cause problems, like these examples:
 
  <nowiki>[[Salt]] {{ndash}}[[Pepper]]</nowiki>
 
  <nowiki>[[Salt]] {{ndash}}[[Pepper]]</nowiki>
 
  <nowiki>[[Salt]]  {{ndash}}[[Pepper]]</nowiki>
 
  <nowiki>[[Salt]]  {{ndash}}[[Pepper]]</nowiki>
Line 59: Line 59:
 
  <nowiki>[[Salt]]  {{ndash}}  [[Pepper]]</nowiki>
 
  <nowiki>[[Salt]]  {{ndash}}  [[Pepper]]</nowiki>
  
Then it will still only render just one space on each side of the dash, like this:
+
Then it will render with ''two'' spaces before the dash, and one after, like this:
:[[Salt]] &ndash; [[Pepper]]
+
:[[Salt]] &nbsp;&ndash; [[Pepper]]
  
But if it line breaks it might break ''before'' the dash, like this:
+
And if it line breaks it might break ''before'' the dash, like this:
 
:[[Salt]]  
 
:[[Salt]]  
:&ndash; [[Pepper]]
+
:&nbsp;&ndash; [[Pepper]]
  
 
=== Technical details ===
 
=== Technical details ===
  
The space before the dash is a "non-wrapping" but "collapsing" space. That means it will not line break, but it will collapse together with normal spaces that come before the template to form one single space. It is not simply a <code>&amp;nbsp;</code> since that one will not collapse.
+
The space before the dash is a [[non-breaking space]]. That means it will not line break and will not collapse together with normal spaces that come before the template.
  
The space after the dash is a normal space. That is it wraps and it collapses.
+
The space after the dash is a normal space. That means it wraps (allows line breaks) and it will collapse together with normal spaces that come after the template to form one single space.
  
 
=== Dot size reference list ===
 
=== Dot size reference list ===

Revision as of 06:06, 14 August 2007

Template:Template doc page viewed directly

This is the ndash template, it looks like this " – ".

It works similarly to the html markup sequence "&nbsp;&ndash; ". That is, a non-breaking space, a short dash and a normal space.

{{–}} redirects here and can be used as an alternative name for this template.

This template is used when you want something stronger than a bold middot "·" or a bullet "•", but shorter than a mdash "—".

Normal usage

The recommended usage is to use no space before the template and one space after the template, like this:

[[Salt]]{{ndash}} [[Pepper]]

It will render one space on each side of the dash, like this:

SaltPepper

If it line breaks then the line break will come after the dash, not before, like this:

Salt
Pepper

For long dashed lists each list item can be put on its own line, with no spaces between each item and the template. Like this:

 [[Salt]]{{ndash}}
 [[Pepper]]{{ndash}}
 [[Curry]]{{ndash}}
 [[Saffron]]

(It doesn't matter if there are no or some spaces at the end of the lines, after the templates.)

As before it will render one space on each side of the dashes, like this:

SaltPepperCurrySaffron

And if it line breaks then the line break will come after one of the dashes, not before, like this:

SaltPepper
CurrySaffron

Incorrect usage

If the template is used slightly wrong it will in some cases still behave well. For instance if there are no or several spaces after the template. Like these examples:

[[Salt]]{{ndash}}[[Pepper]]
[[Salt]]{{ndash}}   [[Pepper]]

Both of them will render exactly as before, with just one space on each side of the dash, like this:

SaltPepper

And it will still only line break after the dash, like this:

Salt
Pepper

But putting one or more spaces before the template will cause problems, like these examples:

[[Salt]] {{ndash}}[[Pepper]]
[[Salt]]   {{ndash}}[[Pepper]]
[[Salt]] {{ndash}} [[Pepper]]
[[Salt]]   {{ndash}}   [[Pepper]]

Then it will render with two spaces before the dash, and one after, like this:

Salt  – Pepper

And if it line breaks it might break before the dash, like this:

Salt
 – Pepper

Technical details

The space before the dash is a non-breaking space. That means it will not line break and will not collapse together with normal spaces that come before the template.

The space after the dash is a normal space. That means it wraps (allows line breaks) and it will collapse together with normal spaces that come after the template to form one single space.

Dot size reference list

· <small> middot
· middot
· <small> bold middot
· bold middot
<small> bullet
bullet
bold bullet
ndash
mdash

See also

There are several other templates with similar functionality:

  • {{·}} - Bold middot "·" is mostly used for dotted lists.
  • {{•}} - Bullet "•" is mostly used for dotted lists that use small font sizes.
  • {{mdash}} - Mdash "—" is a long dash.