Class MarkdownSanitizer

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int BLOCK
      Codeblock region such as "```Hello```"
      static int BOLD
      Bold region such as "**Hello**"
      static int ITALICS_A
      Italics region for asterisks such as "*Hello*"
      static int ITALICS_U
      Italics region for underline such as "_Hello_"
      static int MONO
      Monospace region such as "`Hello`"
      static int MONO_TWO
      Monospace region such as "``Hello``"
      static int NORMAL
      Normal characters that are not special for markdown, ignoring this has no effect
      static int QUOTE
      Quote region such as "> text here"
      static int QUOTE_BLOCK
      Quote block region such as ">>> text here"
      static int SPOILER
      Spoiler region such as "||Hello||"
      static int STRIKE
      Strikethrough region such as "~~Hello~~"
      static int UNDERLINE
      Underline region such as "__Hello__"
    • Field Detail

      • NORMAL

        public static final int NORMAL
        Normal characters that are not special for markdown, ignoring this has no effect
        See Also:
        Constant Field Values
      • ITALICS_U

        public static final int ITALICS_U
        Italics region for underline such as "_Hello_"
        See Also:
        Constant Field Values
      • ITALICS_A

        public static final int ITALICS_A
        Italics region for asterisks such as "*Hello*"
        See Also:
        Constant Field Values
      • MONO_TWO

        public static final int MONO_TWO
        Monospace region such as "``Hello``"
        See Also:
        Constant Field Values
      • BLOCK

        public static final int BLOCK
        Codeblock region such as "```Hello```"
        See Also:
        Constant Field Values
      • SPOILER

        public static final int SPOILER
        Spoiler region such as "||Hello||"
        See Also:
        Constant Field Values
      • UNDERLINE

        public static final int UNDERLINE
        Underline region such as "__Hello__"
        See Also:
        Constant Field Values
      • STRIKE

        public static final int STRIKE
        Strikethrough region such as "~~Hello~~"
        See Also:
        Constant Field Values
      • QUOTE

        public static final int QUOTE
        Quote region such as "> text here"
        See Also:
        Constant Field Values
      • QUOTE_BLOCK

        public static final int QUOTE_BLOCK
        Quote block region such as ">>> text here"
        See Also:
        Constant Field Values
    • Method Detail

      • sanitize

        @Nonnull
        public static java.lang.String sanitize​(@Nonnull
                                                java.lang.String sequence)
        Sanitize string with default settings.
        Same as sanitize(sequence, SanitizationStrategy.REMOVE)
        Parameters:
        sequence - The string to sanitize
        Returns:
        The sanitized string
      • escape

        @Nonnull
        public static java.lang.String escape​(@Nonnull
                                              java.lang.String sequence)
        Escapes every markdown formatting found in the provided string.
        Parameters:
        sequence - The string to sanitize
        Returns:
        The string with escaped markdown
        Throws:
        java.lang.IllegalArgumentException - If provided with null
        See Also:
        escape(String, int)
      • escape

        @Nonnull
        public static java.lang.String escape​(@Nonnull
                                              java.lang.String sequence,
                                              int ignored)
        Escapes every markdown formatting found in the provided string.
        Example: escape("**Hello** ~~World~~!", MarkdownSanitizer.BOLD | MarkdownSanitizer.STRIKE)
        Parameters:
        sequence - The string to sanitize
        ignored - Formats to ignore
        Returns:
        The string with escaped markdown
        Throws:
        java.lang.IllegalArgumentException - If provided with null
      • escape

        @Nonnull
        public static java.lang.String escape​(@Nonnull
                                              java.lang.String sequence,
                                              boolean single)
        Escapes every single markdown formatting token found in the provided string.
        Example: escape("**Hello _World_", true)
        Parameters:
        sequence - The string to sanitize
        single - Whether it should scape single tokens or not.
        Returns:
        The string with escaped markdown
        Throws:
        java.lang.IllegalArgumentException - If provided with null sequence
      • withIgnored

        @Nonnull
        public MarkdownSanitizer withIgnored​(int ignored)
        Specific regions to ignore.
        Example: new MarkdownSanitizer().withIgnored(MarkdownSanitizer.BOLD | MarkdownSanitizer.UNDERLINE).compute("Hello __world__!")
        Parameters:
        ignored - The regions to ignore
        Returns:
        The current sanitizer instance with the new ignored regions
      • compute

        @Nonnull
        public java.lang.String compute​(@Nonnull
                                        java.lang.String sequence)
        Computes the provided input.
        Uses the specified MarkdownSanitizer.SanitizationStrategy and ignores any regions specified with withIgnored(int).
        Parameters:
        sequence - The string to compute
        Returns:
        The resulting string after applying the computation
        Throws:
        java.lang.IllegalArgumentException - If the provided string is null