• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

hightlight the syntax of any Source Code using Java

 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Team,

I want to hightlight the syntax of any Source Code using Java.We have web application developed using Spring MVC.User is uploading the Source Files.
Source code can be either Cobal or Java file. We are reading the source file and displaing the program in <div> tag.

Q1)I want the source code to hightligted?

Please help me
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean to identify the code, or parse its syntax and highlight the keywords?
 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're displaying the code in a browser, then there are a number of choices available to you for that:

  • Syntax Highlighter by Alex Gorbatchev
  • Pygments

  • We use Alex's Syntax Highlighter here at CodeRanch.com so you can see that it works quite nicely. I use Pygments on my personal blog and it's pretty good too. Both recommended.
     
    Satyajeet Kadam
    Ranch Hand
    Posts: 224
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Tim and Ritchie for your response.


    YES we are displaying the code in a broeser and it should highlight the syntax.Currently we are hightligting the cobol and java code only.

    Q1) I went through the examples in Use Pygments in Java.In examples they are using PythonInterpreter to hightlight Python code.Is there any api class in Java Pygments to hightligh Java and cobol code?

    Q2) Please suggested any other tolls which are free and can highlight any code using Java on browser?


    Thanks,
    Satyajeet
     
    Satyajeet Kadam
    Ranch Hand
    Posts: 224
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Ignore my last post message because gramatically mistake

    YES we are displaying the code in a broeser and it should highlight the syntax.Currently, we want to hightligting the cobol and java code only.In futher there might be other languages.

    Q1) I went through the examples in Use Pygments in Java.In examples they are using PythonInterpreter to hightlight Python code.Is there any api class in Java Pygments to hightligh Java and cobol code?

    Q2) Please suggested any other tolls which are free and can highlight any code using Java on browser?


    Thanks,
    Satyajeet
     
    Tim Cooke
    Sheriff
    Posts: 5555
    326
    IntelliJ IDE Python Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I don't really understand what your problem was with Pygments. It highlights Java and Cobol code just nicely in the browser, and can be configured for many many other languages too. Pygments is a client side library, not a server side Java library, so there is no Java class API for it. It wouldn't make sense for there to be either.
     
    Satyajeet Kadam
    Ranch Hand
    Posts: 224
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Cooke!.

    It highlights Java and Cobol code just nicely in the browser but how can we use python in JSP or how can i used them in application written in Java?

    Supposed i have String variable in my JSP






    So how can i used these Pygments lib to hightlight?
     
    Tim Cooke
    Sheriff
    Posts: 5555
    326
    IntelliJ IDE Python Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It looks like Pygments is a little more complicated than I thought. You could use Alex's Syntax Highlighter as it's purely client side. For example:
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic