Skip to content

feat(#2183): flexmark configuration support #2280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

l3r8yJ
Copy link

@l3r8yJ l3r8yJ commented Sep 27, 2024

WIP PR,

closes #2183

@@ -89,6 +89,7 @@ dependencies {
compatDiktat2Dot0Dot0CompileOnly "com.saveourtool.diktat:diktat-runner:2.0.0"
// flexmark
flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.64.8'
implementation 'com.vladsch.flexmark:flexmark-util-data:0.64.8'
Copy link
Member

Choose a reason for hiding this comment

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

Has to be flexmarkCompileOnly, not implementation. Spotless has way too many dependencies to deal with all the transitive conflicts. You can only use flexmark classes inside of FlexmarkFormatterFunc, which gets called with a special classloader after Gradle/Maven has done the dependency resolution.

Copy link
Author

Choose a reason for hiding this comment

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

@nedtwigg okay, got it

Copy link
Author

Choose a reason for hiding this comment

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

@nedtwigg I'm a bit confused. If we 're using only flexmarkCompileOnly it means that I can't get access to flexmark-util-data API inside of FlexmarkStep, which makes it impossible to run with custom configuration or am I wrong?

Copy link

@qwertycxz qwertycxz Jul 20, 2025

Choose a reason for hiding this comment

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

Hey, @l3r8yJ. It's been almost a year and I don't know if you still have the interest to finish this PR.

Anyway, you can find an example of the usage of classloader in JsonSimpleStep. You need to use com.diffplug.spotless.JarState and load the class at runtime.

Comment on lines +21 to +22
implementation 'com.vladsch.flexmark:flexmark-all:0.64.8'
implementation 'com.vladsch.flexmark:flexmark-util-data:0.64.8'
Copy link
Member

Choose a reason for hiding this comment

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

These can't be here either.

Copy link

@qwertycxz qwertycxz left a comment

Choose a reason for hiding this comment

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

If you don't want to finish this PR. I could take it over as long as you want to. :)

@@ -40,7 +40,7 @@ public class FlexmarkFormatterFunc implements FormatterFunc {
private final Parser parser;
private final Formatter formatter;

public FlexmarkFormatterFunc() {
public FlexmarkFormatterFunc(final MutableDataHolder customFormatterOptions) {
Copy link

@qwertycxz qwertycxz Jul 20, 2025

Choose a reason for hiding this comment

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

As you mentioned, MutableDataHolder is not Serializable. So we can't use it as a parameter like Gson.

We need to pass Lists of String, like cleanthat, or anything with zero dependencies.

Choose a reason for hiding this comment

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

This would be hard, since Flexmark reinvent the wheels...

import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.util.Objects;

import com.vladsch.flexmark.util.data.MutableDataHolder;
import com.vladsch.flexmark.util.data.MutableDataSet;

Choose a reason for hiding this comment

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

We need to load the classes at runtime.

@@ -19,29 +19,38 @@

import javax.inject.Inject;

import com.vladsch.flexmark.util.data.MutableDataSet;

Choose a reason for hiding this comment

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

No dependencies.

@l3r8yJ
Copy link
Author

l3r8yJ commented Jul 21, 2025

@qwertycxz so, If u're had an idea, go ahead please!

@l3r8yJ
Copy link
Author

l3r8yJ commented Jul 21, 2025

@qwertycxz or I can finish it in couple of days...

@qwertycxz
Copy link

I have two ideas for this:

Plan A: Let user create a MutableDataSet in gradle DSL and pass it as an Object. Really easy but dirty, and dropped the support of Maven.

Plan B: We take a parser option Map and a formatter option Map, parse the two Maps and convert them to Flexmark options. I like it, but it'll take a LOT of work.

@l3r8yJ
Copy link
Author

l3r8yJ commented Jul 21, 2025

@qwertycxz I'll take a look at this a bit later and give an answer for you tomorrow or later today

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.

Ability to configure flexmark with different options
3 participants