Note: If you're looking for examples of macro source code, you can download the source for most plugins on Atlassian's SubVersion Repository.
Overview:
The {code} macro is used to display syntax highlited source code...
This macro is an extension to the noformat macro which has the ability to apply syntax highlighting to various types of source code:
Java (default)
JavaScript
ActionScript
XML
HTML
SQL
As you can imagine, the macro is mainly aimed at techies, but it's useful if you need to show snippets of HTML such as how to include a link to your site, etc.
Parameters:
To syntax-highlight code, simply wrap it in {code} macro tags and specify the language to use:
{code:language}Your source code{code}
Parameter
Required
Default
Notes
default
Java
The "language" default parameter defines what type of syntax highligting to use:
{code:ActionScript}
// checks that the value is a number
validation.isNumeric = function (f) {
return function (o) {
if (Number(o.value).toString()=="NaN") {
o.diagnostic+="FAILURE: value is not a number.";
o.success=false;
} else {
o.diagnostic+="Value is a number. ";
o.success=true;
if (f!=null) o=f(o);
}
return o;
};
};
{code}
Which results in:
// checks that the value is a number
validation.isNumeric = function (f) {
returnfunction (o) {
if (Number(o.value).toString()=="NaN") {
o.diagnostic+="FAILURE: value is not a number.";
o.success=false;
} else {
o.diagnostic+="Value is a number. ";
o.success=true;
if (f!=null) o=f(o);
}
returno;
};
};
JavaScript (used in your web browser)
Display some JavaScript as follows:
{code:JavaScript}
document.gmap = new GMap(document.getElementById("googlemap"));
document.gmap.addControl(new GLargeMapControl());
document.gmap.addControl(new GMapTypeControl());
var l = document.mapLocs["adaptavist2"];
document.gmap.centerAndZoom(new GPoint(Number(l.longitude), Number(l.latitude)), 15);
function createMarker(point, htm) {
var marker = new GMarker(point);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(htm);
});
return marker;
}
{code}
Which results in:
document.gmap = new GMap(document.getElementById("googlemap"));
document.gmap.addControl(new GLargeMapControl());
document.gmap.addControl(new GMapTypeControl());
var l = document.mapLocs["adaptavist2"];
document.gmap.centerAndZoom(new GPoint(Number(l.longitude), Number(l.latitude)), 15);
function createMarker(point, htm) {
var marker = new GMarker(point);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(htm);
});
return marker;
}
Hints and Tips
The macro is ideal for including snippets of code on your pages because the syntax highlighting makes them easier to read (to us techies at least!)
Comments (1)
Jul 18, 2008
Matus says:
Why isn't overflow:auto used by default? It's annoying to put it everywhere wher...Why isn't overflow:auto used by default? It's annoying to put it everywhere where lines are longer than code area.