fix(markdown): list prefix alignment: count spaces from correct place (#4041)

* test: add tests

* fix(markdown): list prefix alignment: count spaces from correct place

* docs: codeblock -> code block
master
Ika 2018-02-26 08:53:09 +08:00 committed by GitHub
parent ca81bef73e
commit b6c27893cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 175 additions and 3 deletions

View File

@ -357,7 +357,7 @@ function printListItem(path, options, print, listPrefix) {
} }
const alignment = " ".repeat( const alignment = " ".repeat(
clamp(options.tabWidth - listPrefix.length, 0, 3) // 4 will cause indented codeblock clamp(options.tabWidth - listPrefix.length, 0, 3) // 4+ will cause indented code block
); );
return concat([alignment, align(alignment, childPath.call(print))]); return concat([alignment, align(alignment, childPath.call(print))]);
} }
@ -366,12 +366,11 @@ function printListItem(path, options, print, listPrefix) {
} }
function alignListPrefix(prefix, options) { function alignListPrefix(prefix, options) {
const prefixTrailingSpaces = prefix.match(/ *$/)[0].length;
const additionalSpaces = getAdditionalSpaces(); const additionalSpaces = getAdditionalSpaces();
return ( return (
prefix + prefix +
" ".repeat( " ".repeat(
prefixTrailingSpaces + additionalSpaces >= 4 ? 0 : additionalSpaces // 4+ will cause indented code block additionalSpaces >= 4 ? 0 : additionalSpaces // 4+ will cause indented code block
) )
); );

View File

@ -1,5 +1,161 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`align.md 1`] = `
1. 123
---
11. 123
---
111. 123
---
1111. 123
---
11111. 123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. 123
---
11. 123
---
111. 123
---
1111. 123
---
11111. 123
`;
exports[`align.md 2`] = `
1. 123
---
11. 123
---
111. 123
---
1111. 123
---
11111. 123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. 123
---
11. 123
---
111. 123
---
1111. 123
---
11111. 123
`;
exports[`align.md 3`] = `
1. 123
---
11. 123
---
111. 123
---
1111. 123
---
11111. 123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. 123
---
11. 123
---
111. 123
---
1111. 123
---
11111. 123
`;
exports[`align.md 4`] = `
1. 123
---
11. 123
---
111. 123
---
1111. 123
---
11111. 123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. 123
---
11. 123
---
111. 123
---
1111. 123
---
11111. 123
`;
exports[`checkbox.md 1`] = ` exports[`checkbox.md 1`] = `
- [ ] this is a long long long long long long long long long long long long long long paragraph. - [ ] this is a long long long long long long long long long long long long long long paragraph.
- [x] this is a long long long long long long long long long long long long long long paragraph. - [x] this is a long long long long long long long long long long long long long long paragraph.

View File

@ -0,0 +1,17 @@
1. 123
---
11. 123
---
111. 123
---
1111. 123
---
11111. 123