Skip to content

Commit d518fd3

Browse files
authored
add flexmark gradle support (#1801)
2 parents fed839a + 9ac3edc commit d518fd3

File tree

9 files changed

+143
-12
lines changed

9 files changed

+143
-12
lines changed

Diff for: CHANGES.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1111

1212
## [Unreleased]
1313
### Added
14-
* Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)).
15-
1614
* Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/).
1715
The configuration is still the same, but you should switch to the new `biome` tag / function and adjust
1816
the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)).
19-
2017
### Fixed
2118
* Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
19+
### Changes
20+
* Bump default `flexmark` version to latest `0.64.0` -> `0.64.8`. ([#1801](https://github.com/diffplug/spotless/pull/1801))
21+
* Bump default `ktlint` version to latest `0.50.0` -> `1.0.0`. ([#1808](https://github.com/diffplug/spotless/pull/1808))
2222

2323
## [2.41.0] - 2023-08-29
2424
### Added

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ lib('kotlin.KtLintStep') +'{{yes}} | {{yes}}
9494
lib('kotlin.KtfmtStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
9595
lib('kotlin.DiktatStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
9696
lib('markdown.FreshMarkStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
97-
lib('markdown.FlexmarkStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
97+
lib('markdown.FlexmarkStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
9898
lib('npm.EslintFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
9999
lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
100100
lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
@@ -146,7 +146,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}}
146146
| [`kotlin.KtfmtStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
147147
| [`kotlin.DiktatStep`](lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
148148
| [`markdown.FreshMarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
149-
| [`markdown.FlexmarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: |
149+
| [`markdown.FlexmarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
150150
| [`npm.EslintFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
151151
| [`npm.PrettierFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
152152
| [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |

Diff for: lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class FlexmarkStep {
2929
// prevent direct instantiation
3030
private FlexmarkStep() {}
3131

32-
private static final String DEFAULT_VERSION = "0.64.0";
32+
private static final String DEFAULT_VERSION = "0.64.8";
3333
private static final String NAME = "flexmark-java";
3434
private static final String MAVEN_COORDINATE = "com.vladsch.flexmark:flexmark-all:";
3535

Diff for: plugin-gradle/CHANGES.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
44

55
## [Unreleased]
66
### Added
7-
* Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)).
8-
7+
* Support `flexmark` in gradle. Previously only Maven was supported. ([#1801](https://github.com/diffplug/spotless/pull/1801))
98
* Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/).
109
The configuration is still the same, but you should switch to the new `biome(...)` function and adjust
1110
the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)).
12-
1311
### Fixed
1412
* Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
13+
### Changes
14+
* Bump default `ktlint` version to latest `0.50.0` -> `1.0.0`. ([#1808](https://github.com/diffplug/spotless/pull/1808))
1515

1616
## [6.21.0] - 2023-08-29
1717
### Added

Diff for: plugin-gradle/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui
6262
- [Protobuf](#protobuf) ([buf](#buf), [clang-format](#clang-format))
6363
- [Python](#python) ([black](#black))
6464
- [FreshMark](#freshmark) aka markdown
65+
- [Flexmark](#flexmark) aka markdown
6566
- [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter))
6667
- [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier))
6768
- [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Biome](#biome))
@@ -577,6 +578,25 @@ spotless {
577578
}
578579
```
579580
581+
## Flexmark
582+
583+
`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java)
584+
585+
[homepage](https://github.com/vsch/flexmark-java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options).
586+
587+
Currently, none of the available options can be configured yet. It uses only the default options together with `COMMONMARK` as `FORMATTER_EMULATION_PROFILE`.
588+
589+
To apply flexmark to all of the `.md` files in your project, use this snippet:
590+
591+
```gradle
592+
spotless {
593+
flexmark {
594+
target '**/*.md' // you have to set the target manually
595+
flexmark() // or flexmark('0.64.8') // version is optional
596+
}
597+
}
598+
```
599+
580600
## Antlr4
581601
582602
`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2023 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.gradle.spotless;
17+
18+
import java.util.Objects;
19+
20+
import javax.inject.Inject;
21+
22+
import com.diffplug.spotless.FormatterStep;
23+
import com.diffplug.spotless.markdown.FlexmarkStep;
24+
25+
public class FlexmarkExtension extends FormatExtension {
26+
static final String NAME = "flexmark";
27+
28+
@Inject
29+
public FlexmarkExtension(SpotlessExtension spotless) {
30+
super(spotless);
31+
}
32+
33+
public FlexmarkFormatterConfig flexmark() {
34+
return flexmark(FlexmarkStep.defaultVersion());
35+
}
36+
37+
public FlexmarkFormatterConfig flexmark(String version) {
38+
return new FlexmarkFormatterConfig(version);
39+
}
40+
41+
@Override
42+
protected void setupTask(SpotlessTask task) {
43+
// defaults to all markdown files
44+
if (target == null) {
45+
throw noDefaultTargetException();
46+
}
47+
super.setupTask(task);
48+
}
49+
50+
public class FlexmarkFormatterConfig {
51+
52+
private final String version;
53+
54+
FlexmarkFormatterConfig(String version) {
55+
this.version = Objects.requireNonNull(version);
56+
addStep(createStep());
57+
}
58+
59+
private FormatterStep createStep() {
60+
return FlexmarkStep.create(this.version, provisioner());
61+
}
62+
}
63+
64+
}

Diff for: plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java

+6
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ public void freshmark(Action<FreshMarkExtension> closure) {
147147
format(FreshMarkExtension.NAME, FreshMarkExtension.class, closure);
148148
}
149149

150+
/** Configures the special flexmark-specific extension. */
151+
public void flexmark(Action<FlexmarkExtension> closure) {
152+
requireNonNull(closure);
153+
format(FlexmarkExtension.NAME, FlexmarkExtension.class, closure);
154+
}
155+
150156
/** Configures the special groovy-specific extension. */
151157
public void groovy(Action<GroovyExtension> closure) {
152158
format(GroovyExtension.NAME, GroovyExtension.class, closure);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2023 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.gradle.spotless;
17+
18+
import java.io.IOException;
19+
20+
import org.junit.jupiter.api.Test;
21+
22+
class FlexmarkExtensionTest extends GradleIntegrationHarness {
23+
@Test
24+
void integration() throws IOException {
25+
setFile("build.gradle").toLines(
26+
"plugins {",
27+
" id 'java'",
28+
" id 'com.diffplug.spotless'",
29+
"}",
30+
"repositories { mavenCentral() }",
31+
"spotless {",
32+
" flexmark {",
33+
" target '*.md'",
34+
" flexmark()",
35+
" }",
36+
"}");
37+
setFile("markdown_test.md").toResource("markdown/flexmark/FlexmarkUnformatted.md");
38+
gradleRunner().withArguments("spotlessApply").build();
39+
assertFile("markdown_test.md").sameAsResource("markdown/flexmark/FlexmarkFormatted.md");
40+
}
41+
}

Diff for: plugin-maven/CHANGES.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
44

55
## [Unreleased]
66
### Added
7-
* Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)).
8-
97
* Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/).
108
The configuration is still the same, but you should switch to the new `<biome>` tag and adjust
119
the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)).
12-
1310
### Fixed
1411
* Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
12+
### Changes
13+
* Bump default `flexmark` version to latest `0.64.0` -> `0.64.8`. ([#1801](https://github.com/diffplug/spotless/pull/1801))
14+
* Bump default `ktlint` version to latest `0.50.0` -> `1.0.0`. ([#1808](https://github.com/diffplug/spotless/pull/1808))
1515

1616
## [2.39.0] - 2023-08-29
1717
### Added

0 commit comments

Comments
 (0)