Skip to content
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

Removed excessive spaces after line prefixes for unordered lists in Markdown #15526

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions changelog_unreleased/markdown/15526.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#### Removed excessive spaces after line prefixes for unordered lists in Markdown (#15526 by @TomasLudvik)

<!-- prettier-ignore -->
```md
<!-- Input -->
- first line
- second line indented
- third line
- fourth line
- fifth line

<!-- Prettier stable -->
- first line
- second line indented
- third line
- fourth line
- fifth line

<!-- Prettier main -->
- first line
- second line indented
- third line
- fourth line
- fifth line
```
12 changes: 8 additions & 4 deletions src/language-markdown/printer-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ function genericPrint(path, options, print) {

return node.isAligned ||
/* workaround for https://github.com/remarkjs/remark/issues/315 */ node.hasIndentedCodeblock
? alignListPrefix(rawPrefix, options)
? alignListPrefix(rawPrefix, options, node.ordered)
: rawPrefix;
}
},
Expand Down Expand Up @@ -461,16 +461,20 @@ function printListItem(path, options, print, listPrefix) {
];
}

function alignListPrefix(prefix, options) {
const additionalSpaces = getAdditionalSpaces();
function alignListPrefix(prefix, options, isOrdered) {
const additionalSpaces = getAdditionalSpaces(isOrdered);
return (
prefix +
" ".repeat(
additionalSpaces >= 4 ? 0 : additionalSpaces, // 4+ will cause indented code block
)
);

function getAdditionalSpaces() {
function getAdditionalSpaces(isOrdered) {
if (!isOrdered) {
return 0;
}

const restSpaces = prefix.length % options.tabWidth;
return restSpaces === 0 ? 0 : options.tabWidth - restSpaces;
}
Expand Down
Loading
Loading