Skip to content

Commit

Permalink
removed excessive spaces after line prefixes for unordered lists in m…
Browse files Browse the repository at this point in the history
…arkdown
  • Loading branch information
TomasLudvik committed Oct 20, 2023
1 parent 427a84d commit 1b94310
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 77 deletions.
27 changes: 27 additions & 0 deletions changelog_unreleased/markdown/15526.md
@@ -0,0 +1,27 @@
#### Removed excessive spaces after line prefixes for unordered lists in Markdown (#15526 by @TomasLudvik)

<!-- Optional description if it makes sense. -->

<!-- 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
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

0 comments on commit 1b94310

Please sign in to comment.