Template:Code: Difference between revisions

From FreeCAD Documentation
({{#tag:pre|{{{code|{{{1}}}|style="color:black"}}} }})
No edit summary
Line 6: Line 6:
<nowiki>{{Code|code=
<nowiki>{{Code|code=
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))
}}</nowiki>
}}</nowiki>


results in
REMARK:
{{Code|code=
# 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)
import FreeCAD, Draft
# If the macro code content the characters : "|" (Vertical bar) or "{ }" (Closing brace or Opening brace) not use this template (the macro code is dislocated an erroneous), use the HTML code <nowiki><pre> ... </pre> </nowiki>
Draft.makeLine(FreeCAD.Vector(0,0,0), FreeCAD.Vector(2,0,0))
}}




Note:
This template gives a different coloration depending on the used programming language. The default language is '''Python'''.
# 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>


Options:


This template gives a different coloration depending on the option passed to the template. The default option is '''python'''.
* lang=python
* lang=python
* lang=cpp
* lang=cpp
Line 23: Line 27:
* lang=pascal
* lang=pascal


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.
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.
See [http://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi <nowiki><syntaxhighlight></nowiki>] for a complete list of supported languages


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


Original template: {{#tag:syntaxhighlight|{{{code|{{{1}}}}}}|lang="{{{lang|{{{2|python}}}}}}"|enclose="div"}}</nowiki>
Modified cause the colour give one tab inappropriate if it not convenient republished this line i have forced the colour 26/09/2016 Mario52

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


[[Category:Administration]]
[[Category:Administration]]

Revision as of 23:21, 29 October 2018

{{{1}}} 

Use this template when you want to display code, for example :

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

results in

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


Note:

  1. 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)
  2. 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 <pre> ... </pre>


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> tag to show syntax-highlighted text. Unlike <syntaxhighlight>, text that does not fit on the screen will be wrapped. See <syntaxhighlight> for a complete list of supported languages.

Warning: 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"}}