الگو:Code/توضیحات

از ویکی‌پدیا، دانشنامهٔ آزاد

استفاده[ویرایش]

یک متن کوتاه را در برچسب <code> می‌پیچاند (بروید به mw:Extension:SyntaxHighlight). این الگو برای نمونه‌های کوتاه کاربردی است و برای نمونه‌های طولانی‌تر از <pre>...</pre> یا <syntaxhighlight>...</syntaxhighlight> استفاده کرد. برای توضیح در مورد آنچه برچسب های مختلف انجام می دهد، به راهنما: نشانه‌گذاری ویکی مراجعه کنید.

If the content includes an equals sign (=), you must specify the parameter explicitly: {{code|1=date=30 Feb 2010}}.

The template uses the <syntaxhighlight> tag with the attribute enclose="none". This works like the combination of the <code> and <nowiki> tags, applied to the expanded wikitext. For example, {{code|some '''wiki''' text}} will not render the word "wiki" in bold, and will render the tripled-single-quotes:

some '''wiki''' text

However, {{code|a {{الگوی}} call}} will still invoke the template:

a &#123;&#123;[[الگو:{{{1}}}|{{{1}}}]]&#125;&#125; call

Use <nowiki>...</nowiki> around the template name to avoid this problem:

a {{الگوی}} call

When used inline with regular text, {{code}} generally looks best and is easiest to read when it is explicitly spaced apart from the regular text:

foo &nbsp;{{code|bar baz}}&nbsp; quux.

is well spaced:

foo  bar baz  quux.

versus:

foo {{code|bar baz}} quux.

which is going to be visually confusing for many:

foo bar baz quux.

because "foo" and "bar" will seem more closely associated than "bar" and "baz"; the width of the space character in a monospaced font is almost always larger than in a proportional font.

Use parameter {{{2}}} (unnamed, as |2=, or more explicitly as |lang=) to specify a language for Extension:SyntaxHighlight GeSHi. This option defaults to plain-text, i.e. no highlighting. There is no highlighting option for wikitext as a markup language, though html4strict and html5 are valid values, as are php, perl, css, javascript, mysql and many others. Attempting to use an invalid one causes a list of valid ones to be displayed in place of the template output, when the page is previewed or saved.

This template does not need to be substituted.

Finally, embedded templates do not function inside {{code}}; for longer, free-form blocks of code, which can contain templates such as {{var}} and {{samp}}, use <code>...</code> as a wrapper instead of this template.

Examples[ویرایش]

input output
Lorem {{code|ipsum '''dolor'''}} sit amet
Lorem ipsum '''dolor''' sit amet
The declaration {{code |lang=cpp |int foo(const std::string& bar, const std::vector<long double*>& baz);}} is the prototype for a function defined later.
The declaration int foo(const std::string& bar, const std::vector<long double*>& baz); is the prototype for a function defined later.
If the code contains an [[equals sign]], such as {{code |lang=javascript |code=var img = document.getElementsByTagName("img");}}, you must identify the first parameter explicitly as {{{1}}} or {{{code}}}; see also [[:bugzilla:5138]].
If the code contains an equals sign, such as var img = document.getElementsByTagName("img");, you must identify the first parameter explicitly as {{{1}}} or {{{code}}}; see also bugzilla:5138.

See also[ویرایش]

Template Example output Use
{{strong}} strong semantic emphasis To indicate <strong> emphasis instead of (or as well as) simple typographical boldfacing.
{{strongbad}} "Never use..." Same as {{strong}} but in red.
{{stronggood}} "Only use..." Same as {{strong}} but in green.
{{em}} mild semantic emphasis As per {{strong}} but for the milder <em> emphasis (instead of / as well as typographical italicization).
{{var}} strIllustratePrefix To indicate text is a variable name. Use for any variables except those whose names include "I" (uppercase&nbsp;i) and/or "l" (lowercase&nbsp;L), where {{varserif}} below should be used instead to ensure a distinction between these letters is noticeable.
{{varserif}} strIllustratePrefix (see {{var}} above).
{{wikivar}}
purge rev-ID : -   b: c: m: n: q: s: t: w: wikt: ?version all messages
$wgMagicWordsEn at CVS Language.php   meta:help:Variable, meta:Global variables
method a method b generates
common namespaces [-2 - 15] / used at all MediaWiki projects
{{ns:-2}} {{ns:Media}}  مدیا
{{ns:-1}} {{ns:Special}}  ویژه
(Main) – MediaWiki:Blanknamespace – ‏(مقاله)
{{ns:1}} {{ns:Talk}}  بحث
{{ns:2}} {{ns:User}}  کاربر
{{ns:3}} {{ns:User_talk}}  بحث کاربر
{{ns:4}} {{ns:Project}}  ویکی‌پدیا
{{ns:5}} {{ns:Project_talk}}  بحث ویکی‌پدیا
{{ns:6}} {{ns:Image}}  پرونده
{{ns:7}} {{ns:Image_talk}}  بحث پرونده
{{ns:8}} {{ns:MediaWiki}}  مدیاویکی
{{ns:9}} {{ns:MediaWiki_talk}}  بحث مدیاویکی
{{ns:10}} {{ns:Template}}  الگو
{{ns:11}} {{ns:Template_talk}}  بحث الگو
{{ns:12}} {{ns:Help}}  راهنما
{{ns:13}} {{ns:Help_talk}}  بحث راهنما
{{ns:14}} {{ns:Category}}  رده
{{ns:15}} {{ns:Category_talk}}  بحث رده
reserved namespaces
{{ns:16}}    
{{ns:17}}    
{{ns:98}}    
{{ns:99}}    
custom namespaces
{{ns:100}}    درگاه
{{ns:101}}    بحث درگاه
{{ns:102}}    
{{ns:103}}    
{{ns:104}}    
{{ns:105}}    
{{ns:106}}    
{{ns:107}}    
{{ns:121}}    
{{ns:122}}    
{{ns:127}}    
{{ns:128}}    
{{ns:2147483646}}    
{{ns:2147483647}}    
variables
{{CURRENTDAY}}  ۲۰
{{CURRENTDAY2}}  ۲۰
{{CURRENTDAYNAME}}  شنبه
{{CURRENTDOW}}  ۶
{{CURRENTMONTH}}  ۰۴
{{CURRENTMONTHABBREV}}  آوریل
{{CURRENTMONTHNAME}}  آوریل
{{CURRENTMONTHNAMEGEN}}  آوریل
{{CURRENTTIME}}  ‏۰۲:۳۷
{{CURRENTWEEK}}  ۱۶
{{CURRENTYEAR}}  ۲۰۲۴
{{FULLPAGENAME}}  الگو:Code/توضیحات
{{FULLPAGENAMEE}}  %D8%A7%D9%84%DA%AF%D9%88:Code/%D8%AA%D9%88%D8%B6%DB%8C%D8%AD%D8%A7%D8%AA 1
{{NAMESPACE}}  الگو
{{NAMESPACEE}}  %D8%A7%D9%84%DA%AF%D9%88 1
{{NUMBEROFARTICLES}}  ۹۹۹٬۶۱۹
{{NUMBEROFFILES}}  ۹۰٬۳۱۲
{{PAGENAME}}  Code/توضیحات
{{PAGENAMEE}}  Code/%D8%AA%D9%88%D8%B6%DB%8C%D8%AD%D8%A7%D8%AA 1
{{SCRIPTPATH}}  /w 1
{{SERVER}}  //fa.wikipedia.org
{{SERVERNAME}}  fa.wikipedia.org
{{SITENAME}}  ویکی‌پدیا
predefined templates
{{FULLURL:}}  
{{FULLURLE:}}  
{{GRAMMAR:}}  GRAMMAR CVS /languages/
{{INT:}}  
{{LC:}}  
{{LCFIRST:}}  
{{LOCALURL:}}  
{{LOCALURLE:}}  
{{MSG:}}  
{{MSGNW:}}  
{{NS:}}  
{{PLURAL:}}  
{{REVISIONID:}}  
{{REVISIONID}}  -
{{SUBST:}}  
{{UC:}}  
{{UCFIRST:}}  
1 this documentation displays this value LTR (left to right)
 | common reserved custom namespacesvariablespredefined templates
  
purge rev-ID : -   b: c: m: n: q: s: t: w: wikt: ?version all messages
$wgMagicWordsEn at CVS Language.php   meta:help:Variable, meta:Global variables
method a method b generates
common namespaces [-2 - 15] / used at all MediaWiki projects
{{ns:-2}} {{ns:Media}}  مدیا
{{ns:-1}} {{ns:Special}}  ویژه
(Main) – MediaWiki:Blanknamespace – ‏(مقاله)
{{ns:1}} {{ns:Talk}}  بحث
{{ns:2}} {{ns:User}}  کاربر
{{ns:3}} {{ns:User_talk}}  بحث کاربر
{{ns:4}} {{ns:Project}}  ویکی‌پدیا
{{ns:5}} {{ns:Project_talk}}  بحث ویکی‌پدیا
{{ns:6}} {{ns:Image}}  پرونده
{{ns:7}} {{ns:Image_talk}}  بحث پرونده
{{ns:8}} {{ns:MediaWiki}}  مدیاویکی
{{ns:9}} {{ns:MediaWiki_talk}}  بحث مدیاویکی
{{ns:10}} {{ns:Template}}  الگو
{{ns:11}} {{ns:Template_talk}}  بحث الگو
{{ns:12}} {{ns:Help}}  راهنما
{{ns:13}} {{ns:Help_talk}}  بحث راهنما
{{ns:14}} {{ns:Category}}  رده
{{ns:15}} {{ns:Category_talk}}  بحث رده
reserved namespaces
{{ns:16}}    
{{ns:17}}    
{{ns:98}}    
{{ns:99}}    
custom namespaces
{{ns:100}}    درگاه
{{ns:101}}    بحث درگاه
{{ns:102}}    
{{ns:103}}    
{{ns:104}}    
{{ns:105}}    
{{ns:106}}    
{{ns:107}}    
{{ns:121}}    
{{ns:122}}    
{{ns:127}}    
{{ns:128}}    
{{ns:2147483646}}    
{{ns:2147483647}}    
variables
{{CURRENTDAY}}  ۲۰
{{CURRENTDAY2}}  ۲۰
{{CURRENTDAYNAME}}  شنبه
{{CURRENTDOW}}  ۶
{{CURRENTMONTH}}  ۰۴
{{CURRENTMONTHABBREV}}  آوریل
{{CURRENTMONTHNAME}}  آوریل
{{CURRENTMONTHNAMEGEN}}  آوریل
{{CURRENTTIME}}  ‏۰۲:۳۷
{{CURRENTWEEK}}  ۱۶
{{CURRENTYEAR}}  ۲۰۲۴
{{FULLPAGENAME}}  الگو:Code/توضیحات
{{FULLPAGENAMEE}}  %D8%A7%D9%84%DA%AF%D9%88:Code/%D8%AA%D9%88%D8%B6%DB%8C%D8%AD%D8%A7%D8%AA 1
{{NAMESPACE}}  الگو
{{NAMESPACEE}}  %D8%A7%D9%84%DA%AF%D9%88 1
{{NUMBEROFARTICLES}}  ۹۹۹٬۶۱۹
{{NUMBEROFFILES}}  ۹۰٬۳۱۲
{{PAGENAME}}  Code/توضیحات
{{PAGENAMEE}}  Code/%D8%AA%D9%88%D8%B6%DB%8C%D8%AD%D8%A7%D8%AA 1
{{SCRIPTPATH}}  /w 1
{{SERVER}}  //fa.wikipedia.org
{{SERVERNAME}}  fa.wikipedia.org
{{SITENAME}}  ویکی‌پدیا
predefined templates
{{FULLURL:}}  
{{FULLURLE:}}  
{{GRAMMAR:}}  GRAMMAR CVS /languages/
{{INT:}}  
{{LC:}}  
{{LCFIRST:}}  
{{LOCALURL:}}  
{{LOCALURLE:}}  
{{MSG:}}  
{{MSGNW:}}  
{{NS:}}  
{{PLURAL:}}  
{{REVISIONID:}}  
{{REVISIONID}}  -
{{SUBST:}}  
{{UC:}}  
{{UCFIRST:}}  
1 this documentation displays this value LTR (left to right)
 | common reserved custom namespacesvariablespredefined templates
To display wikicode variables and magic words as they would appear in code.
{{para}} |title=  |year=2008 To display template parameters with or without values.
{{param}} {{{title}}}  {{{title|alt}}}  etc. To display parameters as used in code (i.e. with triple braces), especially to indicate relationships between them. May be combined with {{para}} above.
{{tlx}} etc. {{Template|first parameter|...}} To display a template call (with or without parameters and values) as code.
{{tag}} "With HTML <img>...</img> tags..." To render عنصر اچ‌تی‌ام‌الs ("tags") as prose.
{{code}} "Always include the alt= parameter..." To indicate text is source code. To nest other templates within {{code}}, use <code>...</code>.
{{syntaxhighlight}} (or {{sxhl}})  Wrapper for <syntaxhighlight>...</syntaxhighlight>, but will wrap overflowing text.
{{deprecated code}} "Do not use <blink>...</blink>..." (or {{dc2}})&nbsp; To indicate deprecated source code in template documentation, articles on HTML specs, etc.
{{pre}} For larger blocks of source code and other pre-formatted text.
{{bq}} For indented blocks of content, such as block quotations, examples, poems, etc.
{{kbd}} user input To indicate user input.
{{key press}} CtrlX To indicate specific keystroke/s input.
{{pskeypress}} × To indicate PlayStation-style gamepad key presses.
{{samp}} example output To indicate sample or example output.