Skip to content

feat: make unindent in code blocks configurable - #175

Merged
dsherret merged 6 commits into
dprint:mainfrom
bjones1:fix-code-block-unindent
Aug 22, 2026
Merged

feat: make unindent in code blocks configurable#175
dsherret merged 6 commits into
dprint:mainfrom
bjones1:fix-code-block-unindent

Conversation

@bjones1

@bjones1 bjones1 commented Jan 31, 2026

Copy link
Copy Markdown
Contributor

In Markdown,

    test

renders differently than

test

, but the current code strips the indent.

@bjones1
bjones1 marked this pull request as ready for review January 31, 2026 12:36
@dsherret dsherret changed the title Fix: remove unindent from code blocks. fix: remove unindent from code blocks Feb 3, 2026
@dsherret

dsherret commented Feb 3, 2026

Copy link
Copy Markdown
Member

I think maybe the current behaviour might be desirable and someone could use an ignore comment for codeblocks that really need this?

@bjones1

bjones1 commented Feb 4, 2026

Copy link
Copy Markdown
Contributor Author

I see dprint as a formatter, something that makes the formatting of a file consistent without changing the underlying meaning. In Markdown, that means that the HTML produced before and after running dprint won't change, but the way the Markdown is presented improves (word wrapped, consistent headings, etc.). Removing leading spaces is certainly a content change (since the resulting HTML produced differs). While I can see that some might view this as useful cleanup, I hesitate to have dpring make any true content changes to the underlying Markdown. I'm open to your thoughts, though. Perhaps we could make the remove indent in code blocks a non-default option with a warning in the docs "NOTE: changes resulting HTML, but might be your desired outcome"?

@dsherret

Copy link
Copy Markdown
Member

I think this should just be a new config setting and have the current behaviour as the default. If you update the pr to add a config option I'll merge it in.

@bjones1

bjones1 commented May 22, 2026

Copy link
Copy Markdown
Contributor Author

Sounds good! I'll modify the PR and ping you when it's ready. Thanks for the feedback and for the tool!

@bjones1

bjones1 commented May 23, 2026

Copy link
Copy Markdown
Contributor Author

I've updated this PR to add the unindent_code_block option, which defaults to true. Would you review?

Also, if you have time, would you review #171? It should be an easy merge IMHO.

@dsherret dsherret left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Sorry for my delay.

@dsherret dsherret changed the title fix: remove unindent from code blocks feat: make unindent in code blocks configurable Aug 22, 2026
@dsherret
dsherret merged commit 2ce5e05 into dprint:main Aug 22, 2026
2 checks passed
@bjones1

bjones1 commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

My pleasure. If/when you have more time, I have several more PRs that I'll send your way.

Thanks again for this crate -- I use it in my app and really appreciate it!

@bjones1
bjones1 deleted the fix-code-block-unindent branch August 22, 2026 15:29
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.

2 participants