Add asciidoc formatter for AsciiDoc files#2955
Conversation
|
@nedtwigg Could you review this pull request plz? |
…', stop requiring uppercase after '!'/'?' sentence splits, and replace IntStream allocations with plain loops in hot paths.
| void removeTrailingHeaderEqualsSign() { | ||
| for (int i = 0; i < lines.size(); i++) { | ||
| String line = lines.get(i); | ||
| Matcher symmetric = SYMMETRIC_HEADING.matcher(line); |
| lines.set(i, symmetric.group(1) + ' ' + symmetric.group(2)); | ||
| continue; | ||
| } | ||
| Matcher section = SECTION_HEADING.matcher(line); |
| continue; | ||
| } | ||
|
|
||
| if (SECTION_HEADING.matcher(line).matches()) { |
| } | ||
|
|
||
| private static String titleCaseLine(String line) { | ||
| Matcher matcher = AsciidocHeadingHandler.SECTION_HEADING.matcher(line); |
|
@dheid This formatter looks big enough to warrant its own project. Pros of that approach:
Cons: you'd have to setup your own mavenCentral publishing Spotless is more of a switchboard than a formatter itself. We have added a few directly into lib (specifically DBeaver's sql formatting), but they have been:
Those three bulletpoints were the reason we decided to accept the code straight into lib, rather than requiring that it be published on its own and then incorporated into Spotless using our standard glue-code approach. I think a lot of people will be eager to have AsciiDoc formatting, but the history in this PR makes me think this would be more appropriate at its own mavenCentral coordinate and integrated with glue code. |
|
I'm super sad by this and won't publish an own lib. Can't understand the decision and feel super rejected by this. Demotivates me very much to contribute to open source again. |
I think this is a great contribution and I want to merge it! But my preference is for you to publish the logic of the formatter in its own library, and then we merge the glue code into this. Maybe that was not clear? The logic (such as you put in lib) should be in Let me know if that was not clear, or if there is a hurdle why that is not possible. The big advantage of it is that it decouples the formatter implementation from the formatter harness. Almost every FormatterStep in Spotless works this way, your contribution was not singled out. I have given this exact feedback to other PRs in the past, #1649 comes to mind as an example of this, where someone wanted to add a new formatter, we asked them to put the impl into a separate jar, and then it got merged later on.
I hope you'll come back because I think it's good code. But I'm not responsible for motivating you. I apologize if my communication felt like a slammed door - you are always welcome to ask for further discussion or clarification. I am busy and I'm going to communicate simply and openly. TL;DR: I would like to merge your code if you still want to contribute it, but the core logic needs to live in a separate jar. |
Adds a pure-Java
AsciidocFormatterSteptolib(no external dependencies) and wires it into both the Gradle and Maven plugins as a first-classasciidocformat type.What it does
The formatter applies a configurable pipeline of structural normalizations to
.adocfiles. Every option is a boolean flag; all default values are chosen to be safe on real-world documents.normalizeSetextHeadingstrueTitle\n=====) to ATX style (= Title)removeTrailingHeaderEqualsSigntrue=signs (== Title ==→== Title) and normalize whitespace after the leading=signsensureHeadingBlankLinestruenormalizeBlockDelimiterstrue--------→----)collapseConsecutiveBlankLinestrueremoveTrailingWhitespacetrueoneSentencePerLinetruetitleCasefalsenormalizeListBulletsfalse- item→* item)normalizeOrderedListMarkersfalse1. item→. item)ensureSourceDelimitersfalse[source,…]/[listing]blocks that have no----delimiterAll transformations respect delimited block boundaries — content inside
----,====,****, etc. is never modified.Usage
Gradle:
Maven:
Tests
Notes
without reading the docs.