Class AlertsExtension.Builder

java.lang.Object
org.commonmark.ext.gfm.alerts.AlertsExtension.Builder
Enclosing class:
AlertsExtension

public static class AlertsExtension.Builder extends Object
Builder for configuring the alerts extension.
  • Field Details

    • allowedTypes

      private Map<String,String> allowedTypes
    • customTitlesAllowed

      private boolean customTitlesAllowed
    • nestedAlertsAllowed

      private boolean nestedAlertsAllowed
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • setAllowedTypes

      public AlertsExtension.Builder setAllowedTypes(Map<String,String> allowedTypes)
      Sets which alert types will be recognized and parsed into Alert blocks, completely overwriting any previous configuration.

      By default, AlertsExtension.STANDARD_TYPES are used.

      Parameters:
      allowedTypes - A map of alert type to the default title for that type. Must not be null/empty or contain any null/empty keys or values. Additionally, all alert types must be uppercase.
      Returns:
      this
      See Also:
    • addCustomType

      public AlertsExtension.Builder addCustomType(String type, String title)
      Adds a custom alert type with a default title.

      This can also be used to override the default title of standard GFM types (e.g., for localization).

      Parameters:
      type - the alert type (must be uppercase)
      title - the default title for this alert type
      Returns:
      this
      See Also:
    • allowCustomTitles

      public AlertsExtension.Builder allowCustomTitles(boolean allow)
      Allows or disallows custom titles on alerts. Inline formatting is supported within these titles.
      Parameters:
      allow - Whether to allow or disallow custom titles on alerts.
      Returns:
      this
      See Also:
    • allowNestedAlerts

      public AlertsExtension.Builder allowNestedAlerts(boolean allow)
      Allows or disallows parsing alerts within non-root blocks (Document).

      When disallowed, if an alert appears within another block, it will be parsed as a regular BlockQuote.

      Note that even when this is allowed, Parser.Builder.maxOpenBlockParsers(int) will be respected.

      Parameters:
      allow - Whether to allow or disallow parsing alerts within non-root blocks.
      Returns:
      this
    • build

      public Extension build()
      Returns:
      a configured Extension
    • validateTypeAndTitle

      private void validateTypeAndTitle(String type, String title)
      Checks whether an alert type and default title are valid.
      Parameters:
      type - The type to validate. Must be uppercase.
      title - The default title to validate. Must not be null or empty.