Difference between revisions of "Template:Code"

From Audacity Wiki
Jump to: navigation, search
(Possible new template for code snippets)
 
(Make code less garish)
 
(20 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<noinclude>{{Wip}}
+
<noinclude>{{Intro|The '''''Code'' Template''' is intended to enclose '''lines or blocks of programming code, mathematical formulas, regular expressions''' and similar inside a thin box with pink text of slightly larger size than the rest of the page content. |}}
  
  
The '''Menu Code''' can be used to format a string of text in a consistent way across the Wiki with a background and foreground colour which will make it stand out amongst surrounding text. It should be used only for '''code snippets''' (either in programs or in scripts). ''(Other templates may become available for other uses, see [[Templates]].)''
+
The template provides a replacement for placing code inside <nowiki><code></code></nowiki> tags which produces an extremely faint pink background color:
 +
:<code> this is not distinct enough </code>
  
 +
This template also avoids the troublesome excessive line length that can result from the traditional Wiki method of showing code by adding a space in front of a line thus:
  
'''Usage of Template Code''':<br>
+
this is going to become far too long...
 +
{{Hint|Wrapping code inside <nowiki><code></code></nowiki> tags may look better than using Template:Code if your code is inside a colored div such as provided by [[Template:Hint]] or [[Template:Advice]].}}
 +
 
 +
Although part of the line length saving comes from a smaller character spacing, the text does wrap, so this template is not appropriate if the code you are representing depends on unbroken lines.
 +
 
 +
 
 +
'''''NOTE:''''' This template should be used '''only for ''code, formulas, regular expressions and closely related content.''''' Other templates are available for other uses, see [[:Category:Templates]].''
 +
 
 +
 
 +
'''Usage of [[Template:Code]]''':<br>
 +
 
 +
<nowiki>{{</nowiki>code|''text to be formatted''<nowiki>}}</nowiki>
  
<nowiki>{{</nowiki>code:''text to be formatted''<nowiki>}}</nowiki>
 
  
 
For example, typing this:  
 
For example, typing this:  
  <nowiki>See e.g. line 123: {{</nowiki>code:foreach($pics as $p)<nowiki>}}.</nowiki>
+
  <nowiki> {{code|$c: // (-%7)}}</nowiki>
 +
 
  
 
will cause the following to be displayed:
 
will cause the following to be displayed:
  
:See e.g. line 123: <span style="color:red"><code>foreach($pics as $p)</code></span>
+
{{code|$c: // (-%7)}}
 +
 
 +
 
 +
'''Breaks and spaces:''' This template is a left-indented HTML table, so:
 +
* text will automatically wrap round to the next line when it <br>reaches the end of the line.  
 +
* if you want to force a break in the text, use <nowiki><BR></nowiki> in preference,<br> because entering a carriage return may give variable results.<br> A carriage return will enforce a new paragraph, so give a greater<br> space between lines than <nowiki><BR></nowiki>, but further down the table <br> you may need to use two carriage returns to force a new paragraph.
 +
* more than one space in the text will be ignored, so use the '''&amp;nbsp;'''<br> entity to force an extra space between characters.
 +
 +
 
 +
'''''IMPORTANT NOTE:''''' Wiki parsing issues mean that using some symbols inside a template "call" might cause your intended code to not display properly. The equals sign (=) is a known offender. If you have problems, enclose the text part of the call inside  <nowiki><nowiki></nowiki></nowiki> tags. For example, to display this:
 +
 
 +
{{code|<nowiki>$c = (%7) + (%4)</nowiki>}}
 +
 
 +
 
 +
you need to type this:
 +
 
 +
<nowiki>{{</nowiki>code|<nowiki><nowiki>$c = (%7) + (%4)</nowiki></nowiki>}}
 +
 
 +
 
 +
or alternatively if an equals sign is the problem, type "1=" (without quotes) after the pipe:
 +
 
 +
<nowiki>{{code|1=$c = (%7) + (%4)}} </nowiki>
 +
 
 +
 
 +
'''Using [[Template:Code]] in bulleted or ordered lists:'''
 +
 
 +
Optionally you can use:
 +
 
 +
<nowiki>{{</nowiki>codelist|''text to be formatted''<nowiki>}}</nowiki>
 +
 
 +
instead of [[:Template:Code]] when inserting code in lists. Using the codelist template, the code will be indented a little further into the body of the page. 
 +
 
 +
 
 +
[[Category:Templates]]
  
  
Line 20: Line 66:
 
''Ignore the following, it's only a representation of formatting and a parameter dummy.''
 
''Ignore the following, it's only a representation of formatting and a parameter dummy.''
  
</noinclude><span style="color:red"><code>{{{1}}}</code></span>
+
</noinclude>{|style="margin-left:10px;line-height:1.1em;letter-spacing:-0.04em;background-color:#F4F4FE;font-family:monospace;font-size:1.1em;border:1px dashed black" cellpadding="5px"
 +
|{{{1}}}
 +
|}

Latest revision as of 11:45, 4 June 2020

The Code Template is intended to enclose lines or blocks of programming code, mathematical formulas, regular expressions and similar inside a thin box with pink text of slightly larger size than the rest of the page content.


The template provides a replacement for placing code inside <code></code> tags which produces an extremely faint pink background color:

this is not distinct enough

This template also avoids the troublesome excessive line length that can result from the traditional Wiki method of showing code by adding a space in front of a line thus:

this is going to become far too long...
Wrapping code inside <code></code> tags may look better than using Template:Code if your code is inside a colored div such as provided by Template:Hint or Template:Advice.

Although part of the line length saving comes from a smaller character spacing, the text does wrap, so this template is not appropriate if the code you are representing depends on unbroken lines.


NOTE: This template should be used only for code, formulas, regular expressions and closely related content. Other templates are available for other uses, see Category:Templates.


Usage of Template:Code:

{{code|text to be formatted}}


For example, typing this:

 {{code|$c: // (-%7)}}


will cause the following to be displayed:

$c: // (-%7)


Breaks and spaces: This template is a left-indented HTML table, so:

  • text will automatically wrap round to the next line when it
    reaches the end of the line.
  • if you want to force a break in the text, use <BR> in preference,
    because entering a carriage return may give variable results.
    A carriage return will enforce a new paragraph, so give a greater
    space between lines than <BR>, but further down the table
    you may need to use two carriage returns to force a new paragraph.
  • more than one space in the text will be ignored, so use the &nbsp;
    entity to force an extra space between characters.


IMPORTANT NOTE: Wiki parsing issues mean that using some symbols inside a template "call" might cause your intended code to not display properly. The equals sign (=) is a known offender. If you have problems, enclose the text part of the call inside <nowiki></nowiki> tags. For example, to display this:

$c = (%7) + (%4)


you need to type this:

{{code|<nowiki>$c = (%7) + (%4)</nowiki>}}


or alternatively if an equals sign is the problem, type "1=" (without quotes) after the pipe:

{{code|1=$c = (%7) + (%4)}} 


Using Template:Code in bulleted or ordered lists:

Optionally you can use:

{{codelist|text to be formatted}}  

instead of Template:Code when inserting code in lists. Using the codelist template, the code will be indented a little further into the body of the page.



Ignore the following, it's only a representation of formatting and a parameter dummy.

{{{1}}}