Skip to content

Conversation

@SougandhS
Copy link
Member

@SougandhS SougandhS commented Sep 22, 2025

This commits adds the support to recognize markdown headings, lists, comment fences & tables for formatter

fixes :
#4337

Lists

Lists.mp4

Headings

Headings.mp4

Snippets

SnippetMarkdown.mp4

What it does

How to test

Author checklist

@SougandhS
Copy link
Member Author

Hi @mateusz-matela, please check this once you are available

@mateusz-matela
Copy link
Member

I don't think a setting for this is necessary. It made more sense for html tags, as one can put spaces and newlines inside/around them in many different ways that make sense, so one may not want to use the formatter's standard. But for markdown elements there's pretty much only one sensible notation, wouldn't you agree?

Note that markdown also supports tables which require a similar approach: https://docs.oracle.com/en/java/javase/23/javadoc/using-markdown-documentation-comments.html#GUID-7269D6B1-BAA2-4260-A295-EBC3DDA3E69C

After a glance at the code I can say that the new code would better fit in a separate handleMarkdown() method that begins with if-return similar to handleHtml().

@SougandhS
Copy link
Member Author

But for markdown elements there's pretty much only one sensible notation, wouldn't you agree?

Then I guess I'll remove the UI and option changes 👍

@mateusz-matela
Copy link
Member

Then I guess I'll remove the UI and option changes 👍

maybe this point is actually even stronger - if the setting is turned off, the formatter would mangle the headers and lists into one line, resulting in completely different javadoc content? Nobody would want that!

As for tables - I guess they are much more complicated due to columns alignment - maybe that could be a separate issue (with an on/off setting this time?), but for now we'd need to at least detect them to make sure they are not touched.

@SougandhS
Copy link
Member Author

SougandhS commented Sep 22, 2025

Note that markdown also supports tables which require a similar approach: https://docs.oracle.com/en/java/javase/23/javadoc/using-markdown-documentation-comments.html#GUID-7269D6B1-BAA2-4260-A295-EBC3DDA3E69C

Yes, and different types of comments too https://docs.oracle.com/en/java/javase/23/javadoc/using-markdown-documentation-comments.html#GUID-7E6D6A81-1176-4CF2-85EE-97A86ACDA351

this I will do in another PR. I had hard time implementing this

@SougandhS
Copy link
Member Author

maybe this point is actually even stronger - if the setting is turned off, the formatter would mangle the headers and lists into one line, resulting in completely different javadoc content? Nobody would want that!

Agreed :D

As for tables - I guess they are much more complicated due to columns alignment - maybe that could be a separate issue (with an on/off setting this time?), but for now we'd need to at least detect them to make sure they are not touched.

Lists where complicated too due to indent style, but was manageable. For table pattern recognition do you have any suggestions ?

@SougandhS SougandhS force-pushed the MDTagPatternRecgLists branch from f92dfce to bf1e64b Compare September 29, 2025 01:49
@SougandhS SougandhS force-pushed the MDTagPatternRecgLists branch 9 times, most recently from ce5d986 to b628847 Compare October 1, 2025 07:28
@SougandhS SougandhS changed the title [Formatter] Recognise MarkDown headings & Lists in formatter [Formatter] Recognise MarkDown headings, Lists & Comment Snippets in formatter Oct 1, 2025
@SougandhS SougandhS force-pushed the MDTagPatternRecgLists branch from b628847 to eb48ce3 Compare October 1, 2025 14:34
@SougandhS SougandhS changed the title [Formatter] Recognise MarkDown headings, Lists & Comment Snippets in formatter [Formatter] Recognise MarkDown headings, Lists, Comment Snippets & Tables in formatter Oct 1, 2025
@SougandhS SougandhS force-pushed the MDTagPatternRecgLists branch 2 times, most recently from 84dda38 to 86b0e4f Compare October 2, 2025 01:43
@SougandhS
Copy link
Member Author

SougandhS commented Oct 2, 2025

Hi @mateusz-matela
I have added support for formatting markdown Snippets comments & Tables

Snippets

SnippetMarkdown.mp4

Tables

for tables currently the formatter recognise the pattern, however it still have some issues in processing column arrangement but it wont break the table structure now.

TableMarkdown.mp4

Could you please check the new changes ?

@SougandhS
Copy link
Member Author

Unrelated test failure org.eclipse.jdt.core.tests.model.ClasspathTests.testInvalidClasspath1

Copy link
Member

@mateusz-matela mateusz-matela left a comment

Choose a reason for hiding this comment

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

for tables currently the formatter recognise the pattern, however it still have some issues in processing column arrangement but it wont break the table structure now.

I think full support would mean parsing the whole table, reformatting contents of each cell and determining width of each column as max width of column's cells in order to align everything. This would require a setting as someone my want to keep their unconventional alignment for some reason. I'm not sure it makes sense to implement a partial solution for now, it would be enough to leave tables untouched (as if the new setting is off)

@SougandhS SougandhS force-pushed the MDTagPatternRecgLists branch 2 times, most recently from 085f2f3 to 76a755f Compare October 12, 2025 06:09
@SougandhS SougandhS force-pushed the MDTagPatternRecgLists branch from a7f4eff to b277e18 Compare December 2, 2025 08:21
@mateusz-matela
Copy link
Member

I see 3 failures with this patch, Could you please check that too ?

Oh right, good new tests ;) Fixed with mateusz-matela@e1815a5

@SougandhS SougandhS force-pushed the MDTagPatternRecgLists branch from b277e18 to 195c200 Compare December 4, 2025 07:54
@SougandhS
Copy link
Member Author

I see 3 failures with this patch, Could you please check that too ?

Oh right, good new tests ;) Fixed with mateusz-matela@e1815a5

I tried out the new changes but yet its failing with 195c200 :(

@mateusz-matela
Copy link
Member

mateusz-matela commented Dec 4, 2025

I tried out the new changes but yet its failing with 195c200 :(

Hmm, I just cherry picked my last two commits on top of yours and all tests pass :)
See https://github.com/mateusz-matela/eclipse.jdt.core-dev/commits/MarkdownLists/

@SougandhS SougandhS force-pushed the MDTagPatternRecgLists branch from 195c200 to 7616659 Compare December 6, 2025 06:07
@SougandhS SougandhS force-pushed the MDTagPatternRecgLists branch from 7616659 to b7b2e0c Compare December 8, 2025 04:33
@SougandhS
Copy link
Member Author

@mateusz-matela I have added both of the commits now 👍

@SougandhS SougandhS added this to the 4.39 M1 milestone Dec 8, 2025
int endPos = -1;
int tokenIndexLast = -1;
Token closingToken = null;
boolean shouldDisable = false;
Copy link
Member

Choose a reason for hiding this comment

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

found in CommonMark spec:

If the end of the containing block (or document) is reached and no closing code fence has been found, the code block contains all of the lines after the opening code fence until the end

So maybe it was good to init with shouldDisable = true but also closing Token should init as the last token in the comment

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me check this.. it looks like a very tricky edge case

Copy link
Member Author

Choose a reason for hiding this comment

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

Handled this case now 👍

String fenceCharsEnd = matcher.group(1); // the fence itself
int fenceLengthEnd = fenceCharsStart.length();
// Check if fences match
if (!fenceCharsStart.equals(fenceCharsEnd))
Copy link
Member

Choose a reason for hiding this comment

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

could also check if there's no equivalent of info string after the closing fence, turns out it is not allowed

Copy link
Member

Choose a reason for hiding this comment

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

huh, it's also not allowed to have more than 3 spaces in front of a fence, not counting any indentation coming from lists. So code blocks analysis would need to be part of handleMarkdownList... So maybe that's for later :P

Copy link
Member Author

Choose a reason for hiding this comment

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

Will check this later then..

@SougandhS
Copy link
Member Author

@mateusz-matela If there are no more major issues shall we proceed with current state ?

@iloveeclipse
Copy link
Member

@SougandhS : not sure why this was assigned to me, I've undit that. I have no insights into the "formatter" domain area.

@mateusz-matela
Copy link
Member

The fenced blocks implementation become quite complex, so I thought I'd have a try at the target solution and integrate it with the lists implementation: mateusz-matela@e344bd9
This fixed a few problems, as reflected it tests changes (you thought that 2 ticks made a valid code block fence)?
I think with these changes the PR will be ready to merge at last.

@SougandhS SougandhS force-pushed the MDTagPatternRecgLists branch 3 times, most recently from 8afb6e8 to 3a0e8b0 Compare January 1, 2026 03:40
@SougandhS
Copy link
Member Author

The fenced blocks implementation become quite complex, so I thought I'd have a try at the target solution and integrate it with the lists implementation: mateusz-matela@e344bd9 This fixed a few problems, as reflected it tests changes (you thought that 2 ticks made a valid code block fence)? I think with these changes the PR will be ready to merge at last.

Thanks, I have added the changes

This commits adds the support to recognize markdown Headings, Lists,
Fences & Tables for formatter

Fixes : eclipse-jdt#4337
@SougandhS SougandhS force-pushed the MDTagPatternRecgLists branch from 3a0e8b0 to 582da6b Compare January 2, 2026 01:07
@SougandhS
Copy link
Member Author

Thanks a lot for the thorough review @mateusz-matela !
Merging this now 👍

@SougandhS SougandhS merged commit df7f21e into eclipse-jdt:master Jan 2, 2026
13 checks passed
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.

[regression] formatting document breaks fenced codeblocks in markdown-style comments [Formatter] Support Markdown tag recognition in comments

5 participants