Template:Nowordbreak: Difference between revisions
Content added Content deleted
(+TR) |
imported>FrozenPlum m (Move the documentation to subpage) |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
<includeonly>{{#vardefine:n|{{{2|{{{length|0}}}}}}}}<!-- |
<onlyinclude><includeonly>{{#vardefine:n|{{{2|{{{length|0}}}}}}}}<!-- |
||
-->{{#vardefine:text|{{{1|{{{text|}}}}}}}}<!-- |
-->{{#vardefine:text|{{{1|{{{text|}}}}}}}}<!-- |
||
-->{{#vardefine:sub|{{#sub:{{#var:text}}|0|{{#var:n}} }} }}<!-- |
-->{{#vardefine:sub|{{#sub:{{#var:text}}|0|{{#var:n}} }} }}<!-- |
||
Line 7: | Line 7: | ||
|{{#var:text}} |
|{{#var:text}} |
||
|{{#rmatch:{{#var:sub}}|/[\W0-9]$/|{{#var:sub}}|{{#rmatch:{{#var:sub+}}|/[\W0-9]$/|{{#var:sub}}|{{#rmatch:{{#var:sub}}|/^(.*[\s]).*$/|$1|{{#var:sub}}}}}}}} |
|{{#rmatch:{{#var:sub}}|/[\W0-9]$/|{{#var:sub}}|{{#rmatch:{{#var:sub+}}|/[\W0-9]$/|{{#var:sub}}|{{#rmatch:{{#var:sub}}|/^(.*[\s]).*$/|$1|{{#var:sub}}}}}}}} |
||
}}</includeonly>< |
}}</includeonly></onlyinclude> |
||
{{Documentation}} |
|||
This template will return the first n characters of a string, without breaking words. Numbers however, will be broken apart. |
|||
Note: This template requires the [[mw:Extension:RegexFunctions|RegexFunctions Extension]]. |
|||
=== Usage examples === |
|||
{| |
|||
! Code !! Gives |
|||
|- |
|||
| <code><nowiki>{{nowordbreak|Testing, testing, 123|11}}</nowiki></code> |
|||
| {{nowordbreak|Testing, testing, 123|11}} |
|||
|- |
|||
| <code><nowiki>{{nowordbreak|Testing, testing, 123|20}}</nowiki></code> |
|||
| {{nowordbreak|Testing, testing, 123|20}} |
|||
|} |
|||
[[tr:Şablon:Nowordbreak]] |
|||
[[Category:Templates]] |
|||
</noinclude> |
Latest revision as of 03:18, 30 March 2022
This template will return the first n characters of a string, without breaking words. Numbers however, will be broken apart.
Note: This template requires the RegexFunctions extension and the Variables extension (whose future is uncertain).
Usage examples
Code | Gives |
---|---|
{{nowordbreak|Testing, testing, 123|11}}
|
11}}{{#vardefine:text|Testing, testing, 123}}{{#vardefine:sub|{{#sub:{{#var:text}}|0|{{#var:n}} }} }}{{#vardefine:n+|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:sub+|{{#sub:{{#var:text}}|0|{{#var:n+}} }} }}{{#rmatch:{{#var:sub}}|/[\W0-9]$/|{{#var:sub}}|{{#rmatch:{{#var:sub+}}|/[\W0-9]$/|{{#var:sub}}|{{#rmatch:{{#var:sub}}|/^(.*[\s]).*$/|$1|{{#var:sub}}}}}}}} |
{{nowordbreak|Testing, testing, 123|20}}
|
20}}{{#vardefine:text|Testing, testing, 123}}{{#vardefine:sub|{{#sub:{{#var:text}}|0|{{#var:n}} }} }}{{#vardefine:n+|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:sub+|{{#sub:{{#var:text}}|0|{{#var:n+}} }} }}{{#rmatch:{{#var:sub}}|/[\W0-9]$/|{{#var:sub}}|{{#rmatch:{{#var:sub+}}|/[\W0-9]$/|{{#var:sub}}|{{#rmatch:{{#var:sub}}|/^(.*[\s]).*$/|$1|{{#var:sub}}}}}}}} |
[view | edit | purge]The above documentation is transcluded from Template:Nowordbreak/doc.