Class HTMLTokenRenderer

  • All Implemented Interfaces:
    TokenRenderer

    public class HTMLTokenRenderer
    extends java.lang.Object
    implements TokenRenderer
    Renders Java source tokens as HTML tags. This renderer renders the parsed Java tokens with HTML styles. The styles of the tokens are determined by their types such as Java keywords, identifiers, comments etc. Moreover, an identifier can be a custom type if it matched a given list of identifiers. The actual HTML text is enclosed in <span id="style">token<\span> to apply the style. The styles are defined in a Cascaded Style Sheet (CSS). The cascaded style sheet by default is named java.css.
    The rendering takes care of line breaks and white space in the following way to work around some limitations of Swing based HTML editor kit's usage of CSS attributes.
  • Line Breaks: Swing Editor seems to require an explicit carriage return-line feed character to render in separate line. While a normal browser works with <br> tag alone.
  • White space: The CSS property white-space is sufficient for browsers to preserve white space within <span> tags. But Swing Editor seems to require explicit nbsp; for white spaces within <span> tags.
    Two boolean properties are provided to control these two properties.
  • Line Numbering: A boolean property controls whether line numbers will be printed. Line numbers are printed in 4 digits with leading zeros, by default.
  • Line Number Anchoring: An anchor can be specified at every line. The anchor is line.nnn where nnn is the actual line number without any leading zero.
  • JavaDoc comment : The JavaDoc comments can use characters that if reproduced exactly in HTML output can confuse the rendering process. On the other hand, the JavaDoc tags that define an anchor in the source code or creates a hyperlink should be preserved in the HTML output. The capacity and limitation of processing HTML tages inside JavaDoc comments are described in here.
Author:
Pinaki Poddar