Allow folding of html blocks in markdown files

Fixes #57505
This commit is contained in:
Matt Bierner
2018-09-07 13:35:26 -07:00
parent 321077674d
commit a118676a3b
2 changed files with 24 additions and 2 deletions

View File

@@ -70,8 +70,19 @@ export default class MarkdownFoldingProvider implements vscode.FoldingRangeProvi
private async getBlockFoldingRanges(document: vscode.TextDocument): Promise<vscode.FoldingRange[]> {
const isFoldableToken = (token: Token) =>
['fence', 'list_item_open'].indexOf(token.type) >= 0 && token.map[1] > token.map[0];
const isFoldableToken = (token: Token) => {
switch (token.type) {
case 'fence':
case 'list_item_open':
return token.map[1] > token.map[0];
case 'html_block':
return token.map[1] > token.map[0] + 1;
default:
return false;
}
};
const tokens = await this.engine.parse(document.uri, document.getText());
const multiLineListItems = tokens.filter(isFoldableToken);

View File

@@ -152,6 +152,17 @@ a`);
assert.strictEqual(firstFold.start, 4);
assert.strictEqual(firstFold.end, 6);
});
test('Should fold html blocks', async () => {
const folds = await getFoldsForDocument(`x
<div>
fa
</div>`);
assert.strictEqual(folds.length, 1);
const firstFold = folds[0];
assert.strictEqual(firstFold.start, 1);
assert.strictEqual(firstFold.end, 3);
});
});