HandWiki:Help/SourceCode
HandWiki uses [[1]] extension to highlights source code.
Showing source code
To show programming code, use the "source" tag (and specify the language). Here is an example for a Java code:
Java="OK"; File F = new File();
which is programmed as:
<source lang="java"> Java="OK"; File F = new File(); </source>
Another option is to use "syntaxhighlight" instead of the "source" code.
Instead of "java", you can use "python" (Python), "php" (PHP), "cpp" (C++), "js" (JavaScript) etc. tags that define the programming language.
HaneWiki is bundled with highlight.js version 9.12 and the following languages (the keyword is given in brackets):
Common languages in HandWiki:
- Object-C ("objectivec")
- C ("c-like")
- C# ("csharp")
- C++ ("cpp")
- PHP ("php")
- Bash ("bash")
- CSS ("css")
- Go ("go")
- Groovy ("groovy")
- Python ("python")
- Shell ("shell")
- Java ("java")
- JavaScript ("javascript")
- Fortran ("fortran")
- Matlab ("matlab")
- HTML,XML ("xml")
- R ("r")
- Plaintext ("plaintext)
As in the case of HTML, pre-formatted text can be shown with the tag "pre". This is a good way to show the output of the program:
Text in a pre element is displayed in a fixed-width font, and it preserves both spaces and line breaks
Showing code inline
The attribute indicates that the source code should be inline as part of a paragraph (as opposed to being its own block). For example,
let us show a programming code with a syntax highlighting in the same line where the text is.
This is PHP code <?php echo "Done!"; ?>
on one line. It is programmed as:
<source lang="php" inline><?php echo "Done!"; ?></source>
This code above assumes syntax highlighting. However, you can use the tag "code" that does not apply syntax highlighting and cane used inline. Here is an example of a class name java.lang.String
which is programmed as:
<code>java.lang.String</code>
Note that the code is inside the white box.
Another option is to use the "tt" tag which does not apply the white background (and it looks more organic with the main text). Here is an example of the "tt" tag: java.lang.String. It is programmed as:
<tt>java.lang.String</tt>
Examples from DataMelt
For showing source code examples from DataMelt project, use the "jcode" statement. The first word should be "dmelt", the second - id of the example.
from jhplot import * f1 = F1D("2*exp(-x*x/50)+sin(pi*x)/x", 1.0, 10.0) c1 = HPlot("Example of function") c1.visible() c1.setAutoRange() c1.draw(f1)
which is programmed as:
<jcode lang="python"> dmelt 27777667.py </jcode>
If the example is protected, you will see a yellow box instead. You can also type code inside "jcode", but this will be less efficient than using the "source" statement assuming the Java syntax.
You can also show code using the "pycode" tag (Python syntax). This is a more protected approach since it shows a yellow box if not a member:
To display this code request membership or login if you are already member. |
This code is equivalent to <source lang="python">:
def quickSort(arr): less = [] pivotList = [] more = [] if len(arr) <= 1: return arr else: pass
codded as:
<source lang="python"> def quickSort(arr): less = [] pivotList = [] more = [] if len(arr) <= 1: return arr else: pass </source>
Here when one uses "js" (JavaScript) tag:
console.log('Some JavaScript code');
Here when one uses "java" (Java) tag:
console.log('Some Java code');
Here when one uses "python" (Python) tag:
console.log('Some Python code');
If you do not need syntax highlighting, the best way to show outputs is to use "pre" tag.
Showing documentation
Javadoc API
Native Java classes can be identified automatically as "Java documentation" links. For example,
is programmed as:
<javadoc>jhplot.H1D</javadoc>
Here is another example: java.lang.String which is programmed as:
<javadoc>java.lang.String</javadoc>
One can reference up to 50,000 Java classes (restrictions for some proprietary documentation may apply).
Python API
Python classes and libraries classes can be identified automatically as "Python documentation" links. For example,
is programmed as:
<pydoc>string</pydoc>
By default, Python3 is assumed.