Class HtmlStyler

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.String>

    public class HtmlStyler
    extends java.lang.Object
    implements java.lang.Iterable<java.lang.String>
    Converts plain text into syntax highlighted HTML.
    Since:
    3.4, replaces HTMLStyler from 3.3 with a different API
    Author:
    Chris Jennings ()
    • Constructor Summary

      Constructors 
      Constructor Description
      HtmlStyler​(CodeType type)
      Creates a new styler for the specified code type.
      HtmlStyler​(CodeType type, boolean noBackgroundColor, boolean noFontStyles, boolean matchTheme)
      Creates a new styler for the specified code type.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getLength()
      Returns the length of the text.
      int getLineCount()
      Returns the number of lines in the document.
      java.lang.String getText()
      Returns the current text.
      java.util.Iterator<java.lang.String> iterator()
      Returns an iterator that returns each line in sequence as styled HTML.
      void setText​(java.lang.String text)
      Sets the text to be styled.
      java.lang.String style​(int start, int end)
      Returns highlighted HTML for the specified character range.
      java.lang.String styleAll()
      Returns the entire text as highlighted HTML.
      java.lang.String styleLine​(int line)
      Returns highlighted HTML for the specified line.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • HtmlStyler

        public HtmlStyler​(CodeType type)
        Creates a new styler for the specified code type. It will initially contain the empty string.
        Parameters:
        type - the type of code to highlight
      • HtmlStyler

        public HtmlStyler​(CodeType type,
                          boolean noBackgroundColor,
                          boolean noFontStyles,
                          boolean matchTheme)
        Creates a new styler for the specified code type. It will initially contain the empty string.
        Parameters:
        type - the type of code to highlight
        noBackgroundColor - if true, the background color is not styled
        noFontStyles - if true, font style changes are ignored
        matchTheme - if true, the syntax styling will match the current theme
    • Method Detail

      • setText

        public void setText​(java.lang.String text)
        Sets the text to be styled.
        Parameters:
        text - the code to highlight
      • getText

        public java.lang.String getText()
        Returns the current text.
        Returns:
        the non-null text
      • styleAll

        public java.lang.String styleAll()
        Returns the entire text as highlighted HTML.
        Returns:
        an HTML representation of the document
      • style

        public java.lang.String style​(int start,
                                      int end)
        Returns highlighted HTML for the specified character range.
        Parameters:
        start - the start offset
        end - the end offset
        Returns:
        an HTML representation of the document range
      • styleLine

        public java.lang.String styleLine​(int line)
        Returns highlighted HTML for the specified line.
        Parameters:
        line - the zero-based line number
        Returns:
        an HTML representation of the document line
      • getLength

        public int getLength()
        Returns the length of the text. return the text length in characters
      • getLineCount

        public int getLineCount()
        Returns the number of lines in the document.
        Returns:
        the text length in lines
      • iterator

        public java.util.Iterator<java.lang.String> iterator()
        Returns an iterator that returns each line in sequence as styled HTML. If the text is modified before the iterator completes, the result is undefined.
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.String>
        Returns:
        an iterator over styled document lines