Skip to content

Commit

Permalink
fix: allow varying indentation inside of blockquotes
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMarCode committed Jul 10, 2023
1 parent c6ec9b9 commit a7375e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/indent-alignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,23 @@ module.exports = {

// Ensure blocks are aligned
traverse(params.parsers.micromark.tokens, [ 'blockQuote', 'listOrdered', 'listUnordered' ], (token) => {
const iterateOverChildTokens = [ 'blockQuote', 'codeFenced', 'content', 'listItemPrefix', 'listOrdered', 'listUnordered' ],
firstToken = findFirstTokenOfType(token.children, [ 'content' ]);
let iterateOverChildTokens = [ 'codeFenced', 'content', 'listItemPrefix', 'blockQuote', 'listOrdered', 'listUnordered' ];

const firstToken = findFirstTokenOfType(token.children, [ 'content' ]);

if (!firstToken) {
return;
}

// This rule does not enforce a specific initial indentation of list items
// since that behavior is handled by rules like MD007. Therefore, ignore any
// list tokens that are the direct children of blockQuote tokens.
// We also ignore nested blockQuotes because the checks below are not written
// to handle that edge case.
if (token.type === 'blockQuote') {
iterateOverChildTokens = [ 'codeFenced', 'content', 'listItemPrefix' ];
}

let expectedIndent = firstToken.startColumn - 1; // -1 to make zero indexed

iterate(token.children, iterateOverChildTokens, (child, skipTo) => {
Expand Down
15 changes: 15 additions & 0 deletions tests/indent-alignment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,21 @@ describe('Indent Alignment', () => {
]);
});

it('reports no errors for indented lists inside double blockquotes', async () => {
await testValidExample([
'>> hello',
'>>',
'>> * test',
'>> * test',
'>>',
'>> test',
'>>',
'>> 1. test',
'>> 2. test',
'>> 3. test',
]);
});

it('reports no errors for left-aligned paragraphs', async () => {
await testValidExample([
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
Expand Down

0 comments on commit a7375e2

Please sign in to comment.