Package org.commonmark.ext.gfm.alerts
Class AlertsExtension.Builder
java.lang.Object
org.commonmark.ext.gfm.alerts.AlertsExtension.Builder
- Enclosing class:
- AlertsExtension
Builder for configuring the alerts extension.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddCustomType(String type, String title) Adds a custom alert type with a default title.allowCustomTitles(boolean allow) Allows or disallows custom titles on alerts.allowNestedAlerts(boolean allow) Allows or disallows parsing alerts within non-root blocks (Document).build()setAllowedTypes(Map<String, String> allowedTypes) Sets which alert types will be recognized and parsed intoAlertblocks, completely overwriting any previous configuration.private voidvalidateTypeAndTitle(String type, String title) Checks whether an alert type and default title are valid.
-
Field Details
-
allowedTypes
-
customTitlesAllowed
private boolean customTitlesAllowed -
nestedAlertsAllowed
private boolean nestedAlertsAllowed
-
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
setAllowedTypes
Sets which alert types will be recognized and parsed intoAlertblocks, completely overwriting any previous configuration.By default,
AlertsExtension.STANDARD_TYPESare 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
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
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
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
- Returns:
- a configured
Extension
-
validateTypeAndTitle
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.
-