模板:Ns/doc
| 此頁面是Template:Ns的模板文件。 此頁面可能包含了模板的使用說明、分類和其他內容。 |
| 這是 Ns 模板的說明文件頁面。 本文件並不是為直接瀏覽而撰寫。若是其中使用了跨維基計劃連結,某些連結可能會顯示損毀。請勿將這些連結替換為硬編碼的頁面名稱或網址。 |
| 此模板文件被許多頁面所引用。 為了避免造成大規模的影響,所有對此模板文件的編輯應先於沙盒、測試樣例或您的沙盒上測試。 測試後無誤的版本可以一次性地加入此模板文件中,但是修改前請務必於討論頁發起討論。 |
Template:ns is designed to insert between 0 and 83 non-breaking (non-linewrapping) spaces rapidly according to the number assigned as its first (unnamed) parameter. If this parameter is not supplied or its value is not numeric, it inserts a default three non-breaking spaces.
使用方法與範例
[編輯]| Three{{ns}}spaces{{ns}}between{{ns}}each{{ns}}word | produces: | Three spaces between each word |
| Ten{{ns|10}}eight{{ns|8}}six{{ns|6}}four{{ns|4}}! | produces: | Ten eight six four ! |
The effect of the count, such as in "{{ns|30}}" is identical to putting 30 copies of " " into the text.
In translation of text to uppercase letters, the spacing is retained. Compare:
- {{uc: Begin{{ns|4}}end }} → BEGIN END
- {{uc: Begin{{spaces|4}}end }} → BEGIN    END
For gaps wider than 83 spaces, then multiple instances can be used, such as "{{ns|80}}{{ns|10}}" to insert 90 non-breaking spaces.
Performance considerations
[編輯]Template:ns has been designed to rapidly insert a few, or numerous, non-breaking spaces where wrapping is not wanted, such as to pad table headings or align some entries in columns. It has been clocked to run faster than 1,530x times per second (in December 2012). The number of spaces, from 0 to 83, does not affect the speed of formatting. It invokes the parser function "padleft:" to repeat " " several, or dozens, of times. Also, the expansion depth has been kept limited, as only 5 levels deep, to allow use anywhere, to generate spaces in any complex templates or tables.
Beyond the maximum count of 83 spaces, the template truncates at 500-characters long (limited by padleft), with "&#" at the end. The default count, as 3 spaces, was chosen because a 1-or-2-space gap is often coded as simply " " and hence, 3 spaces is the first gap needing longer markup. The short template name, "ns" avoids transposing letters as "nsbp" for dyslexic users.
For gaps wider than 83 spaces, then multiple instances of {ns} can be used, such as "{{ns|80}}{{ns|10}}" to insert 90 non-breaking spaces.
TemplateData
[編輯]Inserts a given number of non breaking spaces.
| 參數 | 描述 | 類型 | 狀態 | |
|---|---|---|---|---|
| Number | 1 | The number of spaces to insert. Must be less than 83. The default is three spaces. | 字串 | 非必填 |
參見
[編輯]- Template:In5, to insert a mix of   and regular spaces which can wrap.
- Template:Gaps, to insert precisely-sized gaps between digits/words.
- Template:Spaces, to insert large, no-wrap span-tags to separate text 1-n spaces.
- Template:nowrap, to join text or wikilinks as non-wrapped.