spotless icon indicating copy to clipboard operation
spotless copied to clipboard

Format http code in markdown

Open EricGao888 opened this issue 3 years ago • 1 comments

Sometimes we may have some http code in markdown, e.g. image link like:

<p align="center">
   <img src="xxxx" width="60%" />
 </p>

Currently, markdown.FlexmarkStep in spotless could not fix http code formatting in markdown. It would be pretty handy if spotless could support this feature in the future.

BTW, I'd like to help with it but currently I haven't found a good way to implement this. Any help will be appreciated! Thx

EricGao888 avatar Aug 10 '22 06:08 EricGao888

With the Gradle plugin, you can apply different formatters on different blocks (formatter inception).

But this only works if you have a regex that demarcates the nested HTML from the rest of the markdown. If all of the cases you care about fit with '<p ', '</p>' then you could use this pattern to apply prettier or the Eclipse WTP formatter onto the embedded HTML. If that regex doens't capture all of the cases you care about, then you're probably better off improving the Flexmark project directly.

nedtwigg avatar Aug 10 '22 18:08 nedtwigg

@nedtwigg Thanks for the reply. May I ask whether there is something similar to the formatter inception in the Maven plugin?

EricGao888 avatar Aug 11 '22 02:08 EricGao888

There is not, but it might be possible. In the Gradle plugin, FormatExtension is the receiver for adding generic steps. It has this method for defining a block, and then defining the steps within that block.

https://github.com/diffplug/spotless/blob/ce98b688cb4724a95e0abb05f4bbaf398097c1b8/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java#L674-L682

In the Maven plugin, the equivalents would be AbstractSpotlessMojo and FormatterFactory, but I'm not sure how to do a nested DSL in the maven plugin (or if that's even possible).

nedtwigg avatar Aug 11 '22 19:08 nedtwigg

There is not, but it might be possible. In the Gradle plugin, FormatExtension is the receiver for adding generic steps. It has this method for defining a block, and then defining the steps within that block.

https://github.com/diffplug/spotless/blob/ce98b688cb4724a95e0abb05f4bbaf398097c1b8/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java#L674-L682

In the Maven plugin, the equivalents would be AbstractSpotlessMojo and FormatterFactory, but I'm not sure how to do a nested DSL in the maven plugin (or if that's even possible).

Got it, thanks!

EricGao888 avatar Aug 12 '22 02:08 EricGao888

Feel free to comment further if you need more help.

nedtwigg avatar Aug 17 '22 03:08 nedtwigg