Class HtmlFoldParser

  • All Implemented Interfaces:
    FoldParser

    public class HtmlFoldParser
    extends java.lang.Object
    implements FoldParser
    Fold parser for HTML 5, PHP and JSP. For HTML, we currently don't fold everything possible, just the "big" stuff. For PHP, we only fold the "big" HTML stuff and PHP regions, not code blocks in the actual PHP. For JSP we only fold the "big" HTML stuff and JSP blocks, not anything in the actual Java code.
    Version:
    1.0
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  HtmlFoldParser.TagCloseInfo
      A simple wrapper for the token denoting the closing of a tag (i.e.
    • Constructor Summary

      Constructors 
      Constructor Description
      HtmlFoldParser​(int language)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<Fold> getFolds​(RSyntaxTextArea textArea)
      Returns a list of all folds in the text area.
      private int getTagCloseInfo​(Token tagNameToken, RSyntaxTextArea textArea, int line, HtmlFoldParser.TagCloseInfo info)
      Grabs the token representing the closing of a tag (i.e.
      private static boolean isEndOfLastFold​(java.util.Stack<java.lang.String> tagNameStack, Token tagNameToken)
      Returns whether a closing tag ("</...>") with a specific name is the closing tag of our current fold region.
      private static boolean isFoldableTag​(Token tagNameToken)
      Returns whether a tag is one we allow as a foldable region.
      private static void removeFold​(Fold fold, java.util.List<Fold> folds)
      If this fold has a parent fold, this method removes it from its parent.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LANGUAGE_HTML

        public static final int LANGUAGE_HTML
        Constant denoting we're folding HTML.
        See Also:
        Constant Field Values
      • LANGUAGE_PHP

        public static final int LANGUAGE_PHP
        Constant denoting we're folding PHP.
        See Also:
        Constant Field Values
      • LANGUAGE_JSP

        public static final int LANGUAGE_JSP
        Constant denoting we're folding JSP.
        See Also:
        Constant Field Values
      • language

        private final int language
        The language we're folding.
      • FOLDABLE_TAGS

        private static final java.util.Set<java.lang.String> FOLDABLE_TAGS
        The set of tags we allow to be folded. These are tags that must have explicit close tags in both HTML 4 and HTML 5.
      • MARKUP_CLOSING_TAG_START

        private static final char[] MARKUP_CLOSING_TAG_START
      • MLC_START

        private static final char[] MLC_START
      • MLC_END

        private static final char[] MLC_END
      • PHP_START

        private static final char[] PHP_START
      • PHP_END

        private static final char[] PHP_END
      • JSP_START

        private static final char[] JSP_START
      • JSP_END

        private static final char[] JSP_END
      • LANG_START

        private static final char[][] LANG_START
      • LANG_END

        private static final char[][] LANG_END
      • JSP_COMMENT_START

        private static final char[] JSP_COMMENT_START
      • JSP_COMMENT_END

        private static final char[] JSP_COMMENT_END
    • Constructor Detail

      • HtmlFoldParser

        public HtmlFoldParser​(int language)
        Constructor.
        Parameters:
        language - The language to fold, such as LANGUAGE_PHP.
    • Method Detail

      • getFolds

        public java.util.List<Fold> getFolds​(RSyntaxTextArea textArea)
        Description copied from interface: FoldParser
        Returns a list of all folds in the text area.
        Specified by:
        getFolds in interface FoldParser
        Parameters:
        textArea - The text area whose contents should be analyzed.
        Returns:
        The list of folds. If this method returns null, it is treated as if no folds were found.
      • getTagCloseInfo

        private int getTagCloseInfo​(Token tagNameToken,
                                    RSyntaxTextArea textArea,
                                    int line,
                                    HtmlFoldParser.TagCloseInfo info)
        Grabs the token representing the closing of a tag (i.e. ">" or "/>"). This should only be called after a tag name has been parsed, to ensure the "closing" of other tags is not identified.
        Parameters:
        tagNameToken - The token denoting the name of the tag.
        textArea - The text area whose contents are being parsed.
        line - The line we're currently on.
        info - On return, information about the closing of the tag is returned in this object.
        Returns:
        The line number of the closing tag token.
      • isEndOfLastFold

        private static boolean isEndOfLastFold​(java.util.Stack<java.lang.String> tagNameStack,
                                               Token tagNameToken)
        Returns whether a closing tag ("</...>") with a specific name is the closing tag of our current fold region.
        Parameters:
        tagNameStack - The stack of fold regions.
        tagNameToken - The tag name of the most recently parsed closing tag.
        Returns:
        Whether it's the end of the current fold region.
      • isFoldableTag

        private static boolean isFoldableTag​(Token tagNameToken)
        Returns whether a tag is one we allow as a foldable region.
        Parameters:
        tagNameToken - The tag's name token. This may be null.
        Returns:
        Whether this tag can be a foldable region.
      • removeFold

        private static void removeFold​(Fold fold,
                                       java.util.List<Fold> folds)
        If this fold has a parent fold, this method removes it from its parent. Otherwise, it's assumed to be the most recent (top-level) fold in the folds list, and is removed from that.
        Parameters:
        fold - The fold to remove.
        folds - The list of top-level folds.