How to "higlight code" / "preformat text" within the forum

forum
syntax-highlighting
code
preformatted
best-practice

#1

Dear all,

a question arose recently regarding code highlighting within post on the forum.

my colleague @oburri told me that I could use back-tick `, you open (and close) with three back-ticks (a markdown feature ; more infos on this page, section Code and Syntax Highlighting). But time to time I encountered bugs in display of the code.

There is also a button on the formatting tool bar : Preformatted text </> icon
but code display is a bit “limited”.

Is there any other proper way that I missed so far ?

Thank you,

Cheers,

Romain

PS : examples below

Formatted with back-ticks

// clear Results Table and ROI manager
run("Clear Results");
roiManager("Reset");
// ask for a path and get the file(s) list
path = getDirectory;
fileList = getFileList;
setBatchMode(true);
for (i = 0 ; i < lengthOf(fileList) ; i++){
	// open the image 
	open(fileList[i]);
	// process the image
	processImage();	
	//save output
	saveAs(path+"output_"+fileList[i]);
	run("Close All");					
}
setBatchMode(false);
showMessage("Jobs DONE!");

Formatted with the Preformatted text button on the tool bar

// clear Results Table and ROI manager
run("Clear Results");
roiManager("Reset");
// ask for a path and get the file(s) list
path = getDirectory;
fileList = getFileList;
setBatchMode(true);
for (i = 0 ; i < lengthOf(fileList) ; i++){
	// open the image 
	open(fileList[i]);
	// process the image
	processImage();	
	//save output
	saveAs(path+"output_"+fileList[i]);
	run("Close All");					
}
setBatchMode(false);
showMessage("Jobs DONE!");

How to put code in a post?
#2

It might be worth noting that there is no explicit option for ImageJ macro syntax highlighting. Please use javascript for ImageJ1 macro language.

 ```javascript
 // your macro code