Template:Code: Difference between revisions

From FreeCAD Documentation
No edit summary
(More information on the template)
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{#tag:pre|{{{code|{{{1}}}|style="color:black"}}} }}<noinclude>
{{#tag:pre|{{{code|{{{1}}}|style="color:black"}}}}}<noinclude>


----
----


Use this template when you want to display code, for example :
Use this template when you want to display a block of code.

<nowiki>{{Code|code=
Since a content that includes an equals sign (=) is interpreted as a variable, you must specify the <code>code=</code> parameter explicitly to avoid issues.

Example:

<nowiki>
{{Code|code=
import FreeCAD, Draft
import FreeCAD, Draft
Draft.makeLine(FreeCAD.Vector(0,0,0), FreeCAD.Vector(2,0,0))
Line = Draft.makeLine(FreeCAD.Vector(0,0,0), FreeCAD.Vector(2,0,0))
}}</nowiki>
}}</nowiki>


Result:
results in

{{Code|code=
{{Code|code=
import FreeCAD, Draft
import FreeCAD, Draft
Draft.makeLine(FreeCAD.Vector(0,0,0), FreeCAD.Vector(2,0,0))
Line = Draft.makeLine(FreeCAD.Vector(0,0,0), FreeCAD.Vector(2,0,0))
}}
}}


----


If the block of code contains the characters: <code>|</code> (vertical bar) or <code>{ }</code> (closing brace or opening brace) do not use this template, as the template won't be parsed correctly. In this cases, you must use the HTML tags <nowiki><pre> ... </pre></nowiki>.
Note:
# Since a content that includes an equals sign (=) is interpreted as a variable, you must specify the '''code=''' parameter explicitly to avoid issues (as in the above example)
# If the macro code contains the characters: "|" (vertical bar) or "{ }" (closing brace or opening brace) do not use this template, as the macro won't be parsed correctly; for this cases, you must use the HTML tags <nowiki><pre> ... </pre></nowiki>


<nowiki><pre>
<nowiki>
<pre>
import FreeCAD, Draft
import FreeCAD, Draft
Draft.makeLine(FreeCAD.Vector(0,0,0), FreeCAD.Vector(2,0,0))
Draft.makeLine(FreeCAD.Vector(0,0,0), FreeCAD.Vector(2,0,0))
Line 30: Line 37:
</pre>
</pre>


----
This template gives a different coloration depending on the option passed to the template. The default option is '''python'''.

* lang=python
''(2018) Note:'' This template was modified in the past because the wiki software couldn't handle syntax highlighting correctly. The following information refers to that older template. If the wiki software supports it once more, the template may be redefined to support syntax highlighting again.
* lang=cpp

* lang=java
----
* lang=pascal

This template gives a different coloration depending on the option passed to the template. The default option is <code>python</code>.
* <code>lang=python</code>
* <code>lang=cpp</code>
* <code>lang=java</code>
* <code>lang=pascal</code>

Other options are be supported.

The template is a simple wrapper around the <nowiki><syntaxhighlight> ... </syntaxhighlight></nowiki> tags to show highlighted text. Unlike <nowiki><syntaxhighlight></nowiki>, text that does not fit on the screen will be wrapped. See [https://www.mediawiki.org/wiki/Extension:SyntaxHighlight Extension:SyntaxHighlight] for a complete list of supported languages.

'''Warning:''' The Extension:SyntaxHighlight was disabled because it didn't work anymore on our host.


Original template:
Other options are be supported: the template is a simple wrapper around the <nowiki><syntaxhighlight> ... </syntaxhighlight></nowiki> tag to show syntax-highlighted text. Unlike <nowiki><syntaxhighlight></nowiki>, text that does not fit on the screen will be wrapped. See [http://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi <nowiki><syntaxhighlight></nowiki>] for a complete list of supported languages.


<nowiki>
'''Warning:''' <nowiki>SyntaxHighlight was disabled because it didn't work anymore on our host.
{{#tag:syntaxhighlight|{{{code|{{{1}}}}}}|lang="{{{lang|{{{2|python}}}}}}"|enclose="div"}}</nowiki>


'''26/09/2016 Mario52'''
Original template: {{#tag:syntaxhighlight|{{{code|{{{1}}}}}}|lang="{{{lang|{{{2|python}}}}}}"|enclose="div"}}</nowiki>
The template was modified because the colour gives one inappropriate tab


<nowiki>
26/09/2016 Mario52
The template was modified because the colour gives one inappropriate tab <nowiki>{{#tag:syntaxhighlight|{{{code|{{{1}}}}}}|enclose="div"}} </nowiki>
{{#tag:syntaxhighlight|{{{code|{{{1}}}}}}|enclose="div"}}</nowiki>


[[Category:Template:Text Format]]
[[Category:Administration]]
[[Category:Administration]]



Revision as of 03:18, 9 December 2018

{{{1}}}

Use this template when you want to display a block of code.

Since a content that includes an equals sign (=) is interpreted as a variable, you must specify the code= parameter explicitly to avoid issues.

Example:

{{Code|code=
import FreeCAD, Draft
Line = Draft.makeLine(FreeCAD.Vector(0,0,0), FreeCAD.Vector(2,0,0))
}}

Result:

import FreeCAD, Draft
Line = Draft.makeLine(FreeCAD.Vector(0,0,0), FreeCAD.Vector(2,0,0))

If the block of code contains the characters: | (vertical bar) or { } (closing brace or opening brace) do not use this template, as the template won't be parsed correctly. In this cases, you must use the HTML tags <pre> ... </pre>.

<pre>
import FreeCAD, Draft
Draft.makeLine(FreeCAD.Vector(0,0,0), FreeCAD.Vector(2,0,0))
</pre>
import FreeCAD, Draft
Draft.makeLine(FreeCAD.Vector(0,0,0), FreeCAD.Vector(2,0,0))

(2018) Note: This template was modified in the past because the wiki software couldn't handle syntax highlighting correctly. The following information refers to that older template. If the wiki software supports it once more, the template may be redefined to support syntax highlighting again.


This template gives a different coloration depending on the option passed to the template. The default option is python.

  • lang=python
  • lang=cpp
  • lang=java
  • lang=pascal

Other options are be supported.

The template is a simple wrapper around the <syntaxhighlight> ... </syntaxhighlight> tags to show highlighted text. Unlike <syntaxhighlight>, text that does not fit on the screen will be wrapped. See Extension:SyntaxHighlight for a complete list of supported languages.

Warning: The Extension:SyntaxHighlight was disabled because it didn't work anymore on our host.

Original template:

{{#tag:syntaxhighlight|{{{code|{{{1}}}}}}|lang="{{{lang|{{{2|python}}}}}}"|enclose="div"}}

26/09/2016 Mario52 The template was modified because the colour gives one inappropriate tab

{{#tag:syntaxhighlight|{{{code|{{{1}}}}}}|enclose="div"}}