Tuesday, February 26, 2008

GNU Source-highlight 2.9

I've just released GNU Source-Highlight 2.9.

Apart the usual bug fixes, the major functional addition is the use of a file (called style.defaults) where you can specify that if a style is not defined for a specific element, then it defaults to another element. For instance, the element "preproc" if not specified will be highlighted as "keyword".

Furthermore, references for XHTML output files are not generated.

Then there were some additions concerning language definition files.

First of all, I've added c.lang for highlighting C programs (i.e., not C++). This was required in cases where in C you use names for variables that are keywords in C++ (e.g., "class").

As for programming languages, the new addition is the language definition for Haxe (provided by Jos Hirth); I actually didn't know this language, which is similar to Java.

/*
* test for haxe
*/
import Math;
class ShuffleBag{

var data:Array<Int>;
var cursor:Int;

//c'tor
public function new(){
data=[];
cursor=-1;

//pointless preprocessor tests :)
#if neko //nya :3
trace("neko");
#else flash9//no space

trace("flash9");
#end //foo

#if flash8
trace("flash8");

#end//no space
}
//add one or several item(s)
public function add(item:Int,?quantity:Int){

if(quantity==null){
data.push(item);

}else{
for(i in 0...quantity)
data.push(item);

}
cursor=data.length-1;
}
//returns the next item in the bag

public function next(){
if(cursor<1){

cursor=data.length-1;
return data[0];

}
var grab:Int=Math.floor(Math.random()*(cursor+1));

var temp:Int=data[grab];
data[grab]=data[cursor];

data[cursor]=temp;
cursor--;
return temp;

}
}

Then, I've added highlighting for some property/configuration files:
Property files:

# a comment
! a comment

source.favorites.jar = src/
output.favorites.jar = bin/
bin.includes = plugin.xml,\
META-INF/,\
favorites.jar,\
icons/
foo


a = "foo"
b = a string with escape sequences \t \n \r \\ \" \' \ (space) \u0123
c = a string with a continuation line \
continuation line
d.e.f = another string

.ini files:

[BrowserBar]
Width=295

# a comment

[Filebrowser]
Dir History=
Location=file://$HOME/

Separate Directories=false
Show Preview=false
Show hidden files=false
Sort by=Name
Sort case insensitively=true
Sort directories first=true

Sort reversed=false
View Style=Simple

[General]
HiddenOnExit=false
Timeout=20

[PlaylistColumnsLayout]
ColumnNames=Filename,Title,Artist,AlbumArtist,Composer,Year,Album,DiscNumber,Track,BPM,Genre,Comment,Directory,Type,Length,Bitrate,SampleRate,Score,Rating,PlayCount,LastPlayed,Mood,Filesize

ColumnOrder=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
ColumnWidths=0,184,92,0,0,100,92,0,0,0,0,0,73,0,80,0,0,0,0,0,0,0,0
ColumnsVersion=1
SortAscending=true
SortColumn=200

[Desktop Entry]

Encoding=UTF-8
Name=prova
Exec=prova %i %m -caption "%c"
Icon=prova
Type=Application
DocPath=prova/prova.html

Comment=A KDE KPart Application
Comment[fr]=Une application KPart pour KDE.
Comment[pt_BR]=Um Aplicativo KPart do KDE
Comment[it]=Applicazione KPart di KDE

.lsm files:

Begin3
Title: sourcehighlightide -- Some description
Version: 0.1
Entered-date:
Description:
Keywords: KDE Qt
Author: Lorenzo Bettini <http://www.lorenzobettini.it>

Maintained-by: Lorenzo Bettini <http://www.lorenzobettini.it>
Home-page:
Alternate-site:
Primary-site: ftp://ftp.kde.org/pub/kde/unstable/apps/utils
xxxxxx sourcehighlightide-0.1.tar.gz
xxx sourcehighlightide-0.1.lsm
Platform: Linux. Needs KDE

Copying-policy: GPL
End

.rpm spec files:

#
# spec file for package GNU Source Highlight (Version 1.x)
#
# Author: Christian W. Zuckschwerdt, Jan 2003
#

Summary: syntax highlighting for source documents

Name: source-highlight
Version: 2.9
Release: 2.9
License: GPL
Group: Utilities/Console

Source: ftp://ftp.gnu.org/gnu/source-highlight/%{name}-%{version}.tar.gz
URL: http://www.gnu.org/software/src-highlite/
BuildRoot: %{_tmppath}/%{name}-%{version}-root


%description
This program, given a source file, produces a document
with syntax highlighting. Both source languages and output formats
can be specified with a simple syntax and added dynamically. At the
moment this package can handle many programming languages, such as,
e.g., Java, C/C++, Prolog, Perl, Php3, Python, Flex, ChangeLog, etc.
as source languages, and some output formats such, as, e.g., HTML,
XHTML, LaTeX, etc.

%prep
%setup -q

%build
./configure $MYARCH_FLAGS \
--prefix=%{_prefix} \
--mandir=%{_mandir} \
--datadir=%{_datadir}

make

%install
rm -rf $RPM_BUILD_ROOT

make DESTDIR=$RPM_BUILD_ROOT install

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(644, root, root, 755)
%doc README COPYING ChangeLog TODO.txt AUTHORS THANKS
%doc doc/*.html doc/*.css
%attr(755,root,root) %{_prefix}/bin/*

%{_datadir}/%{name}/*
%{_mandir}/man?/*

9 comments:

Anonymous said...

Nice work, needs Cobol!

betto said...

yes, it's just that I don't know much about COBOL, if you could please provide some information...

Anonymous said...

Hi,

Thanks for this program. The highlighting part is really great.

One thing I noticed though is that when you add the --line-number option, the line numbers (e.g. "03: ") are simply added without any modification in front of each line of code and this makes it difficult for the viewer of the HTML page to copy and paste the code (i.e. tying out the piece of code on their machine) because those line numbers are also copied when they copy multiple lines, which means most cases.

(And yes, having line numbers is very important when publishing as HTML to get feedback. It is easier for the viewer to say, "the line 112 can be improved like this" instead of saying "this part of calculation in the middle of the page can be...")

It would be great if source-highlight separates the code part and the line number part by default. The following site does it very nicely:

http://dpaste.com/example/

I hope I made sense. Looking forward to your reply. Thanks.

Unknown said...

Hi,

in our TWiki installation, we're using the
SourceHighlightPlugin which is based on source-highlight. I've just started to use it, but it seems to work great, thanks for your work!

Is anybody aware of customizations for Lisp or Lisp-like languages?

Thanks!

Claus

betto said...

Hi Claus!

I actually didn't know about this plugin, thanks for letting me know!

as for Lisp, are you asking for lisp highlighting? I don't know lisp, so I'd need some pointers to write the lisp language definition for source-highlight.

cheers
Lorenzo

Unknown said...

Lorenzo,

the Lisp language definition is available from a number of places, such as http://www.lisp.org/HyperSpec/FrontMatter/Chapter-Index.html.

There are also a number of editors and tools out there which already support Lisp - maybe we could learn from their rules/definitions?

Examples:

http://search.cpan.org/dist/Syntax-Highlight-Engine-Kate/lib/Syntax/Highlight/Engine/Kate/Common_Lisp.pm

http://www.codento.com/people/mtr/genscript/

I'm love to help with the highlighting definitions, but haven't found the time yet to learn about extending source-highlight. Any pointers welcome!

Thanks!

Claus

betto said...

Hi Claus,

thanks for the pointers, I'll try to take a look at them :-)

in the meanwhile, if you're willing to learn source-highlight definition syntax, the documentation should provide enough information, especially this section, http://www.gnu.org/software/src-highlite/source-highlight.html#Language-Definitions and of course, you can always ask me for any problem :-)

cheers
Lorenzo

Unknown said...

Lorenzo,

I've installed source-highlight now on my Windows system (using Cygwin), and compiled it successfully.

Then I added a mapping to the /usr/local/share/source-highlight/lang.map file, and created a new language file (lisp.lang) in the same directory. I'm now starting with the docs which describe how to set up the regexes etc.

Thanks again,

Claus

Anonymous said...

Other highlighters:

scite:
http://www.scintilla.org/SciTE.html

.kld files in Kedit. Demo Version:


http://www.kedit.com/kwdemo.html