Coder Social home page Coder Social logo

subinkrishna / java-prettify Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 2.0 1.2 MB

This library is a java port of Google Prettify, the current version ported is 4-Mar-2013. The copyright holder of the Google Prettify is Mike Samuel ([email protected]). It is licensed under the Apache License Version 2. This port is distributed under Apache License Version 2.

Home Page: https://code.google.com/archive/p/java-prettify/

License: Apache License 2.0

Java 97.94% HTML 0.47% Common Lisp 1.04% Shell 0.19% Perl 0.08% Python 0.24% Tcl 0.05%
java syntax-highlighting prettify

java-prettify's Introduction

Java Prettify

[TOC]

This library is a java port of Google Prettify, the current version ported is 4-Mar-2013. The copyright holder of the Google Prettify is Mike Samuel ([email protected]). It is licensed under the Apache License Version 2. This port is distributed under Apache License Version 2.

If you need an editor more than a highlighter, please find jsyntaxpane.

Alternatives

Java SyntaxHighlighter

Requirement

Java SE 6 or up

Language Supported

The comments in prettify.parser.Prettify are authoritative but the lexer should work on a number of languages including C and friends, Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, Makefiles and Rust. It works passably on Ruby, PHP, VB, and Awk and a decent subset of Perl and Ruby, but, because of commenting conventions, doesn't work on Smalltalk, or CAML-like languages.

LISPy languages are supported via an extension: prettify.lang.LangLisp.

And similarly for Clojure, CSS, Go, Haskell, Lua, OCAML, SML, F#, Matlab, Nemerle, Protocol Buffers, Scala, SQL, TeX, LaTeX, VHDL, Visual Basic, WikiText, XQuery, and YAML.

If you'd like to add an extension for your favorite language, please look at prettify.lang.LangLisp.

Themes

Default, Desert, Sons of Obsidian, Sunburst

Configurations

  • Allows you to change the first (starting) line number.
  • Allows you to turn gutter with line numbers on and off.
  • Allows you to highlight one or more lines to focus user's attention.

Example

Note that this highlighter extends Swing component, so all operations are better be executed inside Swing dispatching thread.

import java.io.*;
import java.util.Arrays;
import java.util.logging.*;
import javax.swing.*;
import prettify.PrettifyParser;
import prettify.theme.ThemeDefault;
import syntaxhighlight.*;

public class Example {

  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {

      @Override
      public void run() {
        // the Prettify parser
        Parser parser = new PrettifyParser();

        // initialize the highlighter and use Default theme
        SyntaxHighlighter highlighter = new SyntaxHighlighter(parser, new ThemeDefault());
        // set the line number count from 10 instead of 1
        highlighter.setFirstLine(10);
        // set to highlight line 13, 27, 28, 38, 42, 43 and 53
        highlighter.setHighlightedLineList(Arrays.asList(13, 27, 28, 38, 42, 43, 53));
        try {
          highlighter.setContent(new File("test.html"));
        } catch (IOException ex) {
          Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex);
        }

        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setContentPane(highlighter);
        frame.setLocationByPlatform(true);
        frame.pack();
        frame.setVisible(true);
      }
    });
  }
}

Sample Screenshot

sample screenshot

Support & Discussion

Support & Discussion Group

Known Issues

  • Perl formatting is really crappy. Partly because Perl is hard to parse.

java-prettify's People

Contributors

cws1989 avatar mstrap avatar spearce avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.