Skip to content

Commit

Permalink
#603
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhang-gh committed Jan 27, 2020
1 parent f0bf512 commit 4f27e33
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/test/suite/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function testCommand(command: string, configs, lines: string[], sel
return commands.executeCommand(command).then(() => {
let actual = window.activeTextEditor.document.getText();
actual = actual.replace(/\r\n/g, '\n').replace(/\t/g, ' '); /* !!! */
assert.deepEqual(actual, expLines.join('\n'));
assert.deepEqual(actual, expLines.join('\n').replace(/\t/g, ' '));
assert.deepEqual(window.activeTextEditor.selection, expSelection);
});
});
Expand Down
29 changes: 29 additions & 0 deletions src/test/suite/toc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,35 @@ suite("TOC.", () => {
new Selection(9, 25, 9, 25)).then(done, done);
});

test("Ignore code blocks 2 (GitHub #603)", done => {
testCommand('markdown.extension.toc.create', {},
[
'# Section 1',
'',
'\t```',
'\t## Section 1.1',
'\t```',
'',
'# Section 2',
'',
''
],
new Selection(8, 0, 8, 0),
[
'# Section 1',
'',
'\t```',
'\t## Section 1.1',
'\t```',
'',
'# Section 2',
'',
'- [Section 1](#section-1)',
'- [Section 2](#section-2)'
],
new Selection(9, 25, 9, 25)).then(done, done);
});

test("Markdown syntax in headings", done => {
testCommand('markdown.extension.toc.create', {},
[
Expand Down
9 changes: 5 additions & 4 deletions src/toc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,11 @@ export function buildToc(doc: TextDocument) {
&& !lineText.includes('< omit in toc >');
}).map(lineText => {
lineText = lineText.replace(/^ +/, '');
let entry = {};
let matches = /^(#+) (.*)/.exec(lineText);
entry['level'] = matches[1].length;
entry['text'] = matches[2].replace(/#+$/, '').trim();
const matches = /^(#+) (.*)/.exec(lineText);
const entry = {
level: matches[1].length,
text: matches[2].replace(/#+$/, '').trim()
};
return entry;
});

Expand Down

0 comments on commit 4f27e33

Please sign in to comment.