Skip to content

Add asciidoc formatter for AsciiDoc files#2955

Open
dheid wants to merge 10 commits into
diffplug:mainfrom
dheid:main
Open

Add asciidoc formatter for AsciiDoc files#2955
dheid wants to merge 10 commits into
diffplug:mainfrom
dheid:main

Conversation

@dheid
Copy link
Copy Markdown

@dheid dheid commented Jun 1, 2026

Adds a pure-Java AsciidocFormatterStep to lib (no external dependencies) and wires it into both the Gradle and Maven plugins as a first-class asciidoc format type.

What it does

The formatter applies a configurable pipeline of structural normalizations to .adoc files. Every option is a boolean flag; all default values are chosen to be safe on real-world documents.

Option Default Effect
normalizeSetextHeadings true Convert underline-style headings (Title\n=====) to ATX style (= Title)
removeTrailingHeaderEqualsSign true Remove symmetric trailing = signs (== Title ==== Title) and normalize whitespace after
the leading = signs
ensureHeadingBlankLines true Insert blank lines before and after every section heading
normalizeBlockDelimiters true Shorten over-long delimiters (------------)
collapseConsecutiveBlankLines true Collapse multiple consecutive blank lines into one
removeTrailingWhitespace true Strip trailing whitespace from every line
oneSentencePerLine true Reflow paragraph text so each sentence starts on its own line
titleCase false Apply Chicago-style title case to section headings and block titles
normalizeListBullets false Convert dash bullets to asterisk style (- item* item)
normalizeOrderedListMarkers false Convert explicit numbers to AsciiDoc dot style (1. item. item)
ensureSourceDelimiters false Wrap bare [source,…] / [listing] blocks that have no ---- delimiter

All transformations respect delimited block boundaries — content inside ----,
====, ****, etc. is never modified.

Usage

Gradle:

spotless {
  asciidoc {
    target '**/*.adoc'
    asciidoc()
      // override any defaults here, e.g.:
      .titleCase(true)
      .normalizeListBullets(true)
  }
}

Maven:

<asciidoc>
  <includes><include>**/*.adoc</include></includes>
  <asciidocFormatting>
    <titleCase>true</titleCase>
    <normalizeListBullets>true</normalizeListBullets>
  </asciidocFormatting>
</asciidoc>

Tests

  • 122 unit tests in lib (AsciidocFormatterFuncTest) covering every option individually, including idempotency, block-boundary protection, and several bug-regression cases (setext detection inside code blocks, page-break / block-macro handling, tab-separated list markers).
  • AsciidocFormatterStepTest in testlib using StepHarness.testResource for an end-to-end before/after fixture, and SerializableEqualityTester to verify that every config field contributes to step identity.

Notes

  • The Maven plugin defaults are more conservative than the lib defaults (only removeTrailingWhitespace, collapseConsecutiveBlankLines, and ensureHeadingBlankLines are on) to avoid surprising users who opt in
    without reading the docs.
  • The oneSentencePerLine feature handles common AsciiDoc-specific structural lines (page breaks <<<, block macros include::, toc::, description-list terms, horizontal rules ''') so they are never accumulated into paragraph text.
  • All new files carry the standard Apache 2.0 / Copyright 2026 DiffPlug header. spotlessApply and spotbugsMain both pass.

@dheid
Copy link
Copy Markdown
Author

dheid commented Jun 2, 2026

@nedtwigg Could you review this pull request plz?

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.

1 participant