Skip to content

Flexmark arbitrary formatter options in maven/gradle config#2968

Merged
nedtwigg merged 7 commits into
diffplug:mainfrom
bentatham:feature/flexmark-arbitrary-options
Jun 9, 2026
Merged

Flexmark arbitrary formatter options in maven/gradle config#2968
nedtwigg merged 7 commits into
diffplug:mainfrom
bentatham:feature/flexmark-arbitrary-options

Conversation

@bentatham

Copy link
Copy Markdown
Contributor

Add support for arbitrary formatterOptions in the flexmark step for Maven and Gradle plugins.

The Flexmark Markdown formatter step previously exposed only a small set of formatting options (emulationProfile, pegdownExtensions, extensions). This PR adds a formatterOptions map that lets users pass any option supported by the flexmark-java Markdown Formatter without requiring Spotless to add per-option DSL methods.

Options are specified as SCREAMING_SNAKE_CASE keys matching the static DataKey fields on com.vladsch.flexmark.formatter.Formatter (e.g. RIGHT_MARGIN). The value is always a String and is coerced to the correct type (Integer, Boolean, or String) based on the key's default value. An unrecognised key or unsupported type fails the build with a descriptive error.

Gradle:

flexmark()
    .formatterOptions(['RIGHT_MARGIN': '120'])

Maven:

<flexmark>
  <formatterOptions>
    <rightMargin>120</rightMargin>                                                                                                                                                        
  </formatterOptions>                                                                                                                                                                     
</flexmark>

bentatham and others added 5 commits June 9, 2026 13:18
…ns map

Adds a flexmarkOptions map to FlexmarkConfig and the Maven plugin's
Flexmark class. Each camelCase key (e.g. rightMargin) is converted to
SCREAMING_SNAKE_CASE and resolved to a static DataKey field on the
flexmark Formatter class via reflection. Integer, Boolean, and String
option types are supported; an unknown key or unsupported type fails
the build with a clear error message.

Example Maven configuration:
  <flexmark>
    <flexmarkOptions>
      <rightMargin>100</rightMargin>
    </flexmarkOptions>
  </flexmark>

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds unit tests in FlexmarkStepTest verifying:
- rightMargin option wraps long paragraphs at the configured column
- an unknown option key fails with a clear IllegalArgumentException

Adds a Maven integration test in FlexmarkMavenTest verifying the
flexmarkOptions XML map configuration round-trips correctly through
the plugin.

Adds the corresponding test resource fixtures
FlexmarkOptionsUnformatted.md / FlexmarkOptionsFormatted.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…camelCase conversion to Maven plugin

- FlexmarkConfig stores SCREAMING_SNAKE_CASE keys directly; camelCase→SCREAMING_SNAKE_CASE conversion now lives in the Maven plugin (Flexmark.java) where XML element name convention originates
- Renamed flexmarkOptions→formatterOptions throughout (config field, getter/setter, @parameter, Gradle DSL method, README, tests)
- Added formatterOptions(Map) to Gradle FlexmarkExtension with a corresponding integration test
- Added emulationProfile javadoc noting it can also be set via formatterOptions as FORMATTER_EMULATION_PROFILE
- Updated plugin-maven/README.md with formatterOptions documentation and example

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@nedtwigg nedtwigg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming CI passes this LGTM, though I've got one nit:

private String emulationProfile = "COMMONMARK";
private List<String> pegdownExtensions = List.of("ALL");
private List<String> extensions = new ArrayList<>();
private Map<String, String> formatterOptions = new LinkedHashMap<>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the serialized value of these options is used for up-to-date checks, so if there's any order instability we'll get lots of unnecessary rebuilds. How about swapping for TreeMap

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea!

@bentatham

Copy link
Copy Markdown
Contributor Author

@nedtwigg I pushed fixed that should fix CI, but it looks like you need to approve the workflow for CI to re-run.

@nedtwigg nedtwigg enabled auto-merge June 9, 2026 21:15
@nedtwigg nedtwigg merged commit 10c95c9 into diffplug:main Jun 9, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants