As you know there is a Syntax highlighter for PHP called GeSHi which supports a great number of Programming Languages or Code formats.
However, I couldn't find such a library for Java which supports programming languages that I need (ADA, ASP, BNF, Bash, Brainfuck, C, C++, C#, CSS, Cobol, ColdFusion, D, Fortran, Haskell, HTML, INI (Config), Java, JavaScript, Lisp, Make, Objective C, PASCAL, Perl, PHP, PLSQL, Prolog, Python, Ruby, Scheme, SQL, VB.NET, Verilog, VHDL, Visual Basic, XML.)
Do you know one or should I prefer inefficient way which is retrieving the highlighted code from a remote PHP server via http transaction? Any ideas?
Thanks.
Two related questions:
What code highlighting libs are there for Java?
Where can I find a syntax highlighting library for Java?
And one library I found: http://colorer.sourceforge.net/
Have a look at JHighlighter or jEdit Syntax Package. All mentioned languages aren't supported out of the box. However, you have the sources, so I guess it should be possible to add language support.
Not a direct answer but, if client-side syntax highlighting is an option, the SyntaxHighlighter library from Alex Gorbatchev is an awesome javascript library, supports lots of languages and is highly extensible.
You could use Pygments through Jython. Won't be as fast as a Java solution, but much faster than interacting with a remote server.
Barring that, you could run Geshi locally and pipe source code through it, that would also beat an HTTP round trip.
It seems that it is possible to run GeSHi from Java: GeSHi4J it seems to be a wrapper that run the PHP library on the JVM.
There is a port of prettify.js for Java: java-prettify.
It can be used to produce HTML (computed in Java), as I discussed here:
Use the java-prettify parser to create HTML
jedit is a text editor with syntax highlighting support for some 170+ languages via "modes". It also allows you to specify your own syntaxes. You can use the StandaloneTextArea component in your own application as follows:
Extract source (eg: jedit4.3source.tar.bz2 to d:\source\jedit)
Use ant to copy all the textarea files to ..\textarea eg:
D:\Source\jedit\jEdit> ant prepare-textArea
However, it misses the file BufferUndoListener.java. Copy this manually by executing
D:\Source\jedit\jEdit> copy org\gjt\sp\jedit\buffer\BufferUndoListener.java ..\textarea\src\org\gjt\sp\jedit\buffer\
In Eclipse create a Java Project from existing source in the directory D:\Source\jedit\textarea
Navigate to org.gjt.sp.jedit.textarea.StandaloneTextArea.java
Change the line
mode.setProperty("file","modes/xml.xml");
to
mode.setProperty("file","src/modes/xml.xml");
Run. Copy and paste an XML into the editor and see the syntax highlighting is working.
Related
Coming from Node.js and now working with Java I'm wondering about how to achieve with Java what I did with Node.js, more specifically: How to compile my templates into JS functions.
What I did before was using EJS templates, then they were compiled into a single JS file that exposed functions to call from JS with parameters, these functions returned a HTML string that I could use as it to update my view.
The great thing about this is that I could write my templates in separated files, (EJS) then dynamically Grunt/EJS (I guess, that's from Sails.js internal logic) was converting the template into a function, merged all of them and finally generating a single file usable in my app, I just had to call a function, provide arguments and that's it: I get a view dynamically generated.
I want to achieve the same in a Java environment, using Ant, maybe maven, but I don't know how to do it neither where to look for since I'm a Java novice.
Edit:
I'm talking about client-side templating, I just want to avoid the -ugly-traditionnal way to write HTML code inside JS strings and split them in separated files so I can maintain them easier. I only need to use them from JS, not from Java, but I need to "compile" them from a Java environment, using Ant.
This is somewhat similar to this post, and this one, so you may have a look there to see if there are other useful answers.
A consensus seems to be that Mustache, which has a Java-implemented compiler (among other flavors) could be executed as an Ant target. It's a logic-less template, so you may want to find another solution.
Because it is possible to call Node.js scripts from Ant, it seems like an artificial restriction to not have Node.js. You will have much more choice and flexibility in template choice if you can persuade your team to allow Node.js.
Node.js is not in an either-or relationship with Java tools. There is plenty of room for both on a project, and I've worked on C# projects that use Node.js, just as I've worked on projects that use JRuby, Java, and Rails. None of those technologies excludes the others.
Note that I'm not recommending that you try to persuade people to switch to Node.js as an environment, migrate existing code, or use Grunt, but if it's a useful tool that you're familiar with, I can't think of a single good reason why you should be denied its use.
Another solution is to use this library I discovered yesterday. I've tried it and it seems to work well, some features are also quite useful for development mode, like the watcher on the templates.
http://jcruncher.org/
I think I'll go with it, just wondering about the author and his implication, and hope to see a Handlebars 3.0.0 compatible version soon, as well as the source code on GitHub.
P.S: You can find the handlebars compiler on the CDN (select the 2.0.0 version):
http://cdnjs.com/libraries/handlebars.js/
https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0/handlebars.runtime.min.js
I need to extract from c/c++ source code files, function/class/macro names and their locations in their files. I need to do this in java and over a lot of files (~100/150). How can I do this?
So basically I need something similar to ctags but in java.
The easiest thing to do would probably be to write a Java Native Interface wrapper for ctags!
You could also look at finding a C++ parser in Java. Maybe abduct the parser Eclipse uses for syntax highlighting. Writing your own parser will be extremely painful since it's not a LALR grammar (I know this from experience).
Working on a code generation tool to help creating boiler code for our project.
The generator is written in ruby with erb templates, the project itself is in Java.
Now I am looking for a ruby gem/library for parsing java source files, given a string from a .java files, get the imports, methods, fields, class name etc etc, that would enable me to navigate to a certain method and appending code to it etc (kinda like jQuery selector).
I am wondering if there are already solutions that I can use, kinda like the javaclass-rb library, but that is for parsing bytecodes from .class files.
I know I could use ANTLR and a ruby adapter, but I hope there are existing solutions.
Thanks!
JRuby is a Ruby implementation on top of the JVM that make interaction between Ruby and Java objects trivial. If you decide to use this, you can use any Java library to solve the task, like javaparser.
GWT is pretty cool: write in Java, we build an Ajax app.
Is there something similar for Flash? Code in Java, we convert it to Actionscript?
Thanks!
I haven't use any myself but found these from osflash.org
This seems to be doing something of the sort. http://www.flagstonesoftware.com/transform/. Then there is haxe which doesn't do Java as far as I know but might be worth looking into.
UPDATE:
I just found out that ANTLR will also talks ActionScript. You'll have to define a formal grammar that translates other languages into ActionScript (http://www.antlr.org/wiki/display/ANTLR3/Antlr3ActionScriptTarget)
I'm not sure is available yet, but Joa Ebert showed a Java to SWF compiler at last Flash on the Beach. You can read about it in Compiling Java and C# to SWF.
Cheers,
i need to compress my css as part of my ant build. i noticed that csstidy does this, but it would not be easy to include this in my ant build because i would need to use a different binary on different platforms.
so, is there a java css compressor that people use?
Check out the Yahoo YUI compressor.
It compresses CSS as well as Javascript, and it's written in Java.
Edit: You should be using some sort of HTTP compression as well, like mod_deflate or mod_gzip.
I recently released CSS Compressor. It's a code fork of YUI Compressor, but adds more compression enhancements that make it more similar to csstidy, particularly with regards to grouping selectors that share the same rules. Obviously it's Java, and can be called via the command-line or used as a library within your own Java app.